clear all;close all;instrreset
clc
tic
obj1 = gpib('NI', 0, 6);
obj1.Timeout=300;
obj1.InputBufferSize=5000;
obj1.OutputBufferSize=5000;
fopen(obj1);
% fprintf(obj1,'*IDN?')
fprintf(obj1,':TIMEBASE:RANGE?')
t=str2num(fscanf(obj1));
dist=2e5*t/2;
% fprintf(obj1,'*RST')
fprintf(obj1,':CHANNEL1:RANGE 1')
fprintf(obj1,':CHANNEL2:RANGE 16')
fprintf(obj1,':ACQUIRE:TYPE AVERAGE')
fprintf(obj1,':WAVEFORM:SOURCE CHANNEL1');
fprintf(obj1,':ACQUIRE:COUNT 256')
fprintf(obj1,':DIGITIZE CHANNEL1')
fprintf(obj1,':WAVEFORM:DATA?');
[data1,points1]=fscanf(obj1,'%s');
fprintf(obj1,':WAVEFORM:SOURCE CHANNEL2');
% fprintf(obj1,':ACQUIRE:COUNT 256')
fprintf(obj1,':DIGITIZE CHANNEL2')
fprintf(obj1,':WAVEFORM:DATA?');
[data2,points2]=fscanf(obj1,'%s');
dummy1=sprintf('%e',data1);
dummy2=sprintf('%e',data2);
a1=[];
a2=[];
kk=1;
for ii=1:length(dummy1)/13
    a1=[a1;dummy1(kk:kk+12)];
    a2=[a2;dummy2(kk:kk+12)];
    kk=kk+13;
end
d1=str2num(a1);
d2=str2num(a2);
x=linspace(0,dist,length(d1));
plot(x,d1'/max(d1'),x,d2'/max(d2'));
fclose(obj1);
delete(obj1);
toc