How do I get a waveform using the Instrument Control Toolbox in Matlab?

Question:

How do I get a waveform using the Instrument Control Toolbox in Matlab?

Answer:

Here is a simple program to get a waveform and plot it in Matlab. Note this is connecting using GPIB but this could also use serial or ethernet connections:

function ICT_example
%clear all variables
delete(instrfind)
clear all
g = visa('tek','GPIB0::1::INSTR');
fopen(g);
fprintf(g,' DATA :SOURCE CH1')
recordLength=query(g,'HORIZONTAL:RECORDLENGTH?','%s\n','%d');
fclose(g);
g.InputBufferSize = recordLength;
fopen(g);
fprintf(g,' DATA :START 1');
fprintf(g,[' DATA :STOP ' num2str(recordLength)]);
fprintf(g,' DATA :WIDTH 1');
fprintf(g,' DATA : ENC RPB');
fprintf(g,'CURVE?');
data = binblockread(g,'uint8');
ymult = str2num(query(g,'WFMP:YMULT?'));
yoff = str2num(query(g,'WFMP:YOFF?'));
xmult = str2num(query(g,'WFMP:XINCR?'));
xoff = str2num(query(g,'WFMP:PT_OFF?'));
xzero = str2num(query(g,'WFMP:XZERO?'));
ydata = ymult*(data - yoff);
xdata = xmult*((0:length(data)-1)-xoff)+xzero;
%Plot the scaled data.
plot(xdata,ydata)
title('Scaled Waveform Data'); ylabel('Amplitude (V)');
xlabel('Time (s)')

FAQ ID : 53991

View all FAQs »
다운로드
다운로드

매뉴얼, 데이터 시트, 소프트웨어 등을 다운로드할 수 있습니다.

Go to top