Chapter 3 Programming Demos RIGOL
MSO1000Z/DS1000Z Programming Guide 3-7
Matlab Programming Demo
The program used in this demo: MATLAB R2009a
The function realized in this demo: make FFT operation on the waveform data and draw the
waveform.
1. Run the Matlab software and modify the current directory (namely modify the Current Directory at
the top of the software). In this demo, the current directory is modified to E:\MSO1000Z_Demo.
2. Click File ïƒ New ïƒ Blank M-File in the Matlab interface to create an empty M file.
3. Add the following codes in the M file:
% Create VISA object
MSO1000Z = visa('ni','USB0::0x1AB1::0x04CE::DS1ZA160801111::INSTR');
% Set the device property. In this demo, the length of the input buffer is set to 2048.
MSO1000Z.InputBufferSize = 2048;
% Open the VISA object created
fopen(MSO1000Z);
% Read the waveform data
fprintf(MSO1000Z, ':wav:data?' );
% Request the data
[data,len]= fread(MSO1000Z,2048);
% Close the VISA object
fclose(MSO1000Z);
delete(MSO1000Z);
clear MSO1000Z;
% Data processing. The waveform data read contains the TMC header. The length of the header is 11
bytes, wherein, the first 2 bytes are the TMC header denoter (#) and the width descriptor (9)
respectively, the 9 bytes following are the length of the data which is followed by the waveform data
and the last byte is the terminator (0x0A). Therefore, the effective waveform points read is from the
12nd to the next to last.
wave = data(12:len-1);
wave = wave';
subplot(211);
plot(wave);
fftSpec = fft(wave',2048);
fftRms = abs(fftSpec');
fftLg = 20*log(fftRms);
subplot(212);
plot(fftLg);
4. Save the M file under the current directory. In this demo, the M file is named as
MSO1000Z_Demo_MATLAB.m.