%% clear all close all clc set(0, 'defaulttextfontname', 'times', 'defaulttextfontsize', 14); set(0, 'defaultaxesfontname', 'times', 'defaultaxesfontsize', 14); set(0, 'defaultaxeslinewidth', 1) instruments=instrfind; delete(instruments); % Select number of pulses EventCount =2000; Points=32768; %% Setup variables - convert from cell array to character strings t = visa('agilent','TCPIP0::192.168.0.1::INSTR'); t.timeout=10; set(t,'InputBufferSize',2602144) fopen(t) fwrite(t,'*CLS') % Flush the buffers % Set up scope fwrite(t,':ACQUIRE:SRATE 4E9') % Set sample rate fwrite(t,':ACQUIRE:POINTS 32768') % Set acquisition points/pulse % fwrite(t,':ACQUIRE:MODE RTIME;AVERAGE OFF') % Set up horizontal axis fwrite(t,':TIMebase:REFerence CENTer') % Set timebase reference centre fwrite(t,':TIMEBASE:POS 0') % Set timebase offset fwrite(t,':TIMEBASE:RANGE 10E-9') % Set timebase range % Set up trigger fwrite(t,':TRIGGER:EDGE:COUPLING DC') % Set to DC coupling fwrite(t,':TRIGGER:EDGE:SOURCE CHAN3') % Set Chan 1 as trigger source fwrite(t,':TRIGGER:LEVEL CHAN3 300E-3') % Set trigger level fwrite(t,':TRIGGER:MODE EDGE') % Set to edge trigger mode fwrite(t,':TRIGGER:EDGE:SLOPE POSITIVE') % Set to negative edge trigger fwrite(t,':TRIGGER:SWEEP TRIGGERED') % Set to sweep trigger % Set up vertical axis fwrite(t,':CHANNEL1:RANGE 1600E-3') % Set voltage range fwrite(t,':CHANNEL1:OFFSET 0e-3') % Set voltage offset fwrite(t,':CHANNEL1:INPUT 50') % Set input to DC coupling fwrite(t,':CHANNEL1:UNITS Volts') % Flush the buffers fwrite(t,'*CLS') counts = 0; tic while (counts < EventCount) fwrite(t,':VIEW CHANNEL1') fwrite(t,':DIGITIZE') % Set channels to digitize fwrite(t,':WAVEFORM:SOURCE CHANNEL1') fwrite(t,':WAVEFORM:FORMAT WORD') fwrite(t,':WAVEFORM:BYTEORDER LSBFIRST') fwrite(t,':WAVEFORM:DATA?') a = fscanf(t,'%c',(length(num2str(Points*2))+4)); RecordBytes = str2double(a(2)); bufLen = str2double(a(3:RecordBytes+2))/2; ch = fread(t,bufLen,'short'); % strBuffer = ['%',num2str(length(num2str(Points*2))+2),'s']; % == %7s counts = counts + 1; data(:,counts)=ch(260000:270000); fwrite(t,'*CLS') % Flush the buffers end % Disconnect the TCP/IP object from the host fclose(t) toc plot(data) setax % save data if 0 x=[0:0.25:0.25*9999]; data=data./8.1920; plot(x,data) setax xlabel('Time (ns)') ylabel('Voltage (mV)') end % save dat_raw data % 16-bit signed data -32768 to 32767 % 65536/8000mV range % 8.1902 mv per value % data/8.1920 % save('ej301_cf252','data','-ascii','-double','-tabs'); % plot(data); % setax % Clean up workspace % clear t a ch Channels Step EventCount Points strBuffer fName strTrigLevel % clear strAcqPoints strSampFreq strTimeBase strTimeBase strTimeOffset % clear bufLen RecordBytes strSource counts baseline strChanOffset strView % clear strChanInput strChanRange chanNum fOut ans PerformPGA Boundary % clear defAns lines prompt title % clear strChanRange1 strChanOffset1 strChanInput1 % clear strChanRange2 strChanOffset2 strChanInput2 % clear strChanRange3 strChanOffset3 strChanInput3 % clear strChanRange4 strChanOffset4 strChanInput4 % End of acqData_v4.m