classdef ChannelClass % CHANNELCLASS is the class for one channel of the oscilloscope. Multiple % settings for the different channels of the oscilloscope can be changed % via this class definition % See also: OSCILLOSCOPECLASS properties (Hidden, Access = private) scope % Contains the class of the scope that is parent of this channel. channelnumber % is the number of the channel on the scope. end properties (Dependent) state %is channel enabled or not coupling %DC or AC bandwidth %inputfilter bandwidth scale %Voltage scale in volt/div offset %DC offset probe %probesetting label %name for channel on scope type %set decimation mode probeunit %Define current or voltage probe end methods %Constructor of class function ch = ChannelClass(scope,channelnumber) ch.channelnumber = channelnumber; ch.scope = scope; end %% Get.function section %all get functions pull information from equipment to update %properties. function s = get.state(ch) s = ch.CHAN('state?'); end function out = get.coupling(ch) out = ch.CHAN('coup?'); end function out = get.bandwidth(ch) out = ch.CHAN('band?'); end function out = get.offset(ch) out = ch.CHAN('offs?'); end function out = get.scale(ch) out = ch.CHAN('scal?'); end function out = get.label(ch) out = ch.CHAN('lab?'); end function out = get.type(ch) out = ch.CHAN('type?'); end function out = get.probeunit(ch) out = ch.scope.query(['PROB',num2str(ch.channelnumber),':SET:ATT:UNIT?']); end function out = get.probe(ch) out = ch.scope.query(['PROB',num2str(ch.channelnumber),':SET:ATT:MAN?']); end %% Set.function section % This section contains all functions to change settings of a % channel function ch = set.state(ch,in) %STATE Set the channel on or off. %Options: ON | OFF ch.CHAN('state',in); end function ch = set.coupling(ch,in) %COUPLING Set coupling to one of the following settings: %Options: DCLimit | ACLimit | GND ch.CHAN('coup',in); end function ch = set.bandwidth(ch,in) %BANDWIDTH Set bandwidthlimit. Enable lowpass 20MHz filter %Options: FULL|B20 ch.CHAN('band',in); end function ch = set.offset(ch,in) %OFFSET Sets the DC offset for channel %Range: Depend on vertical scale and probe attenuation. %Increment: Depends on vertical scale and probe attenuation. %On reset: 0 %Default unit: V ch.CHAN('offs',in); end function ch = set.scale(ch,in) %SCALE Sets the scale for the channel % Scale value, given in Volts per division. % Range: 1e-3 to 10 (without probe attenuation) % *RST: 5e-3 % Default unit: V/div ch.CHAN('scal',in); end function ch = set.label(ch,in) %LABEL Sets label of the channel on the scope ch.CHAN('lab',in); end function ch = set.type(ch,in) %Sets the type of the channel ch.CHAN('type',in); end function ch = set.probeunit(ch,unit) ch.scope.write(['PROB',num2str(ch.channelnumber),':SET:ATT:UNIT ', unit]); end function ch = set.probe(ch,man) ch.scope.write(['PROB',num2str(ch.channelnumber),':SET:ATT:MAN ', man]); end %% not set or get function function enable(ch) %ENABLE channel ch.state('ON'); end function disable(ch) %DISABLE channel ch.state('OFF'); end function out = frequency(ch) %FREQUENCY gets the measured frequency of current signal. %Equal to one over the period. % See also PERIOD out = str2double(ch.MEAS('freq')); end function out = peak2peak(ch) %PEAK2PEAK gets the peak2peak value of current signal. %Equal to AMPLITUDE times two. out = str2double(ch.MEAS('peak')); end function out = period(ch) %PERIOD Gets the period of the current signal. %Equal to one over the frequency. out = str2double(ch.MEAS('per')); end function out = amplitude(ch) %AMPLITUDE Gets the amplitude of the current signal. %Equal to half the PEAK2PEAK value. %See also PEAK2PEAK out = str2double(ch.MEAS('ampl')); end function out = mean(ch) %MEAN Gets the mean value of the current signal. out = str2double(ch.MEAS('mean')); end function out = rms(ch) %RMS Gets the rms value of the current signal. out = str2double(ch.MEAS('rms')); end function out = phase(ch) %PHASE gets the phase shift between two signals. %Cannot be done on a single channel. out = str2double(ch.MEAS('phas')); end function data = waveform(ch,window) %WAVEFORM allows for the waveform to be downloaded to matlab % data = WAVEFORM(ch,window) gets the waveform from the scope and % returns a array of the waveform. % % WINDOW can be one of the following options: % %*DEFault* (Default option) % Waveform points that are visible on the screen. At maximum % waveform rate, the instrument stores more samples than visible % on the screen, and DEF returns less values than acquired. % %*MAXimum* % All waveform samples that are stored in the memory. Only available % if acquisition is stopped. % %*DMAXimum* % Display maximum: Waveform samples stored in the current % waveform record but only for the displayed time range. At maximum % waveform rate, the instrument stores more samples than % visible on the screen, and DMAX returns more values than DEF. % Only available if acquisition is stopped. % % See also OSCILLOSCOPECLASS.SETWAVEFORMSETTINGS ch.scope.single; if nargin < 2 window = 'DEF'; end ch.scope.setWaveformSettings(window,'REAL') data = ch.getWaveform; end end methods (Hidden, Access = private) function c = CHAN(ch,string,in) % CHAN checks if the string corresponds with a query or write % c = CHAN(ch, string, in) Where 'ch' is the channel-object, % 'string' is a part of the SCPI-command and 'in' is the actual % value is to be set. 'in' is optional. if nargin == 2 %If only ch and string are given it can be a query if strcmp(string(end),'?') %If the string ends with a '?' then it is a query. c = ch.scope.query(['CHAN',num2str(ch.channelnumber),':',string]); else %Without 'in' and no string it is a event. ch.scope.write(['CHAN',num2str(ch.channelnumber),':',string]); end else %If there is a third argument then the setting should be uploaded to the scope. ch.scope.write(['CHAN',num2str(ch.channelnumber),':',string,' ',in]); end end end methods (Hidden) function data = getWaveform(ch) %GETWAVEFORM Downloads and processes the waveform from scope. header = str2double(ch.CHAN('DATA:HEAD?')); %downloads the dataheader of the waveform that is stored on the scope. data.start = header(1); %First position in header is starttime in seconds data.stop = header(2); %Second position in header is stoptime in seconds data.length = header(3); %Thirth position in header is record length of the waveform in samples. data.sampletime = str2double(ch.CHAN('DATA:XINC?')); %Sample time is downloaded from scope. ch.scope.opc; %Wait for scope. ch.scope.write_unsafe(['CHAN',num2str(ch.channelnumber),':DATA?']); %Send command to download the data. %NOTE! Must be done with write_unsafe. Normal WRITE would also %check if there are errors but this will interfere with the %datastream. data.data = ch.scope.readWaveform(data.length); %Read data from buffer. end function c = MEAS(ch,string) %MEAS makes all the measurement-functions easier. %Most of the measurements queries start with %MEAS:RESult:ACT? Thus goes automatic right now. c = ch.scope.query(['MEAS',num2str(ch.channelnumber),':RES:ACT?',string]); end % function c = CHANsend(ch,string,in) % c = ['CHAN',num2str(ch.channelnumber),':',string,' ',in]; % end end end