% MDA: Agilent Infiniium Oscilloscope model number 54845A, s/n US40020193 % MDA: Oscilloscope IP address: 148.88.156.198 Subnet mask: 255.255.0.0 % MDA: Host PC IP address: 10.48.240.61 Subnet mask: 255.255.255.255 % MDA: Preferred DNS server: 148.88.65.52 Alternative DNS server: 148.88.65.53 % Clear all variables, functions & MEX-files, and close all figures if exist('t') fclose(t); end clear all close all % File and acquisition setup title = 'Oscilloscope: File & acquisition set up'; prompt = {'File directory', 'File name', ... 'Number of events', 'Sample rate (Sa/s)', 'Acquisition points'}; defAns = {'C:\', 'Diamond_Saed', '10', '8E9', '400'}; % MDA: At 8 GSa/s and 400 samples we have an acquisition window of 50 ns FileData = inputdlg(prompt, title, 1, defAns); DestDir = char(FileData(1)); DestFile = char(FileData(2)); EventCount = str2double(FileData(3)); SampFreq = char(FileData(4)); AcqPoints = char(FileData(5)); Frequency = str2double(FileData(4)); Points = str2double(FileData(5)); TimeBase = num2str((1/str2double(SampFreq))*str2double(AcqPoints)); % MDA: This calculates the hortizontal fullscale range based on sample rate and number of acquisiton points strBuffer = ['%', num2str(length(num2str(Points*2))+2), 's']; % Trigger setup title = 'Channel 3: Trigger set up'; % MDA: Channel 1 on the Agilent Infiniium oscilliscope s/n US40040193 is faulty, we're therefore using channel 3 prompt = {'Trigger level (V)', 'Time trigger offset (s)'}; defAns = {'19.0E-3', '10E-09'}; TrigData = inputdlg(prompt, title, 1, defAns); TrigLevel = char(TrigData(1)); TrigOffset = char(TrigData(2)); % Channel 3 voltage axis setup title = 'Channel 3: Voltage axis set up'; prompt = {'Voltage full scale range (V)', 'Voltage offset (V)'}; % MDA: for the voltage offset, +ve moves signal down, -ve moves signal up defAns = {'80.0E-03', '20.0E-3'}; VoltData = inputdlg(prompt, title, 1, defAns); % Connect to the oscilloscope t = visa('agilent', 'TCPIP0::148.88.156.198::INSTR'); set(t, 'InputBufferSize', 2602144,'Timeout', 350); fopen(t); fwrite(t, '*CLS'); % Configure the oscilloscope fwrite(t, [':CHANNEL3:RANGE ', char(VoltData(1))]); fwrite(t, [':CHANNEL3:OFFSET ', char(VoltData(2))]); fwrite(t, ':CHANnel3:INPut DC50'); fwrite(t, ':ACQUIRE:CONFIG SINGLE'); fwrite(t, [':ACQUIRE:SRATE ', SampFreq]); fwrite(t, [':ACQUIRE:POINTS ', AcqPoints]); fwrite(t, ':ACQUIRE:MODE RTIME;AVERAGE OFF'); fwrite(t, ':TIMebase:REFerence CENTer'); fwrite(t, [':TIMEBASE:POS ', TrigOffset]); fwrite(t, [':TIMEBASE:RANGE ', TimeBase]); fwrite(t, ':TRIGGER:EDGE:COUPLING DC'); fwrite(t, ':TRIGGER:EDGE:SOURCE CHAN3'); fwrite(t, [':TRIGGER:LEVEL CHAN3,', TrigLevel]); fwrite(t, ':TRIGGER:MODE EDGE'); fwrite(t, ':TRIGGER:EDGE:SLOPE POSITIVE'); fwrite(t, ':TRIGGER:SWEEP TRIGGERED'); fwrite(t, '*CLS'); counts = 0; start_time = clock; start_time = (start_time(1, 4) * 60 * 60) + (start_time(1, 5) * 60) + (start_time(1, 6)); % MDA: Query scope settings fwrite(t, ':CHANNEL3:SCALE?'); vertical_scale = fscanf(t, '%f'); % MDA: This returns volts/div fwrite(t, ':CHANNEL3:OFFS?'); vertical_offset = fscanf(t, '%f'); % MDA: This returns vertical offset % MDA: Define ADC constants adc_resolution = 256; % MDA: 8-bit ADC adc_offset = 128; % MDA: Midpoint for an 8-bit ADC num_vertical_divisions = 8; % MDA: Number of vertical divisions on the screen while (counts < EventCount) fwrite(t, ':VIEW CHANNEL3'); fwrite(t, ':DIGITIZE'); fwrite(t, ':WAVEFORM:SOURCE CHANNEL3'); fwrite(t, ':WAVEFORM:FORMAT ASCII'); fwrite(t, ':WAVEFORM:BYTEORDER LSBFIRST'); fwrite(t, ':WAVEFORM:DATA?'); ch1=fscanf(t, '%s', AcqPoints); ch1_array = str2double(strsplit(ch1, ',')'); ch1=fread(t,400,'float'); a = fscanf(t, '%c', (length(num2str(Points * 2)) + 2)); if isempty(a) a = ['#', num2str(length(num2str(Points * 2))), num2str(Points * 2)]; end RecordBytes = str2double(a(2)); bufLen = str2double(a(3:RecordBytes+2)) / 2; ch1 = fread(t, bufLen, 'int16'); % UNDERSTAND WHAT IS GOING ON HERE FOR RECORD AMPLITUDE CONVERSION TO VOLTS %ch1_bc = ch1 * voltage_per_digital_unit % - (voltage_per_digital_unit * Resolution / 2);% scale and adjust for offset % ch1_bc = (ch1 +1000) * voltage_per_digital_unit * 20000; % scale the waveform counts = counts + 1; Channel_1(:, counts) = ch1; fwrite(t, '*CLS'); end % Calculate voltage per digital unit %voltage_full_scale = str2double(VoltData(1)); %Resolution = 65536; % Assuming 16-bit resolution %voltage_per_digital_unit = (VoltsDiv * voltage_full_scale) / (Resolution); finish_time = clock; finish_time = (finish_time(1, 4) * 60 * 60) + (finish_time(1, 5) * 60) + (finish_time(1, 6)); laps = finish_time - start_time; count_rate = counts / laps; fclose(t); % peak_amp = max(Channel_1); % % largest_peak_amp = max(peak_amp); % % x=0:largest_peak_amp/1023:largest_peak_amp; %0 : roundup(largest_peak_amp)/(number_bins -1): roundup(largest_peak_amp) % % [occur,xout]=hist(peak_amp,x); % % plot(occur); % plot against channel number % plot(xout,occur); % plot against volts