Skip to Main Content Skip to Search
Home |   Select Country  Choose Country  |  Contact Us  |  Cart Store 
Create Account | Log In
Products & Services Industries Academia Support User Community Company

 

Newsletters - MATLAB Digest

Data Streaming from the Instrument Control Toolbox to an Excel Spreadsheet

by Roberto Waissman

Send E-mail to: Roberto Waissman

This demo illustrates how to stream data collected from an oscilloscope to an Excel spreadsheet and then use MATLAB to do the intermediate analysis of the data. The Instrument Control Toolbox provides the framework for the data collection, while MATLAB's ActiveX client support provides the interface to Excel.

The data obtained for this demonstration was pre-recorded. Therefore, you do not need an instrument. The pre-recorded data is available in TDS210.txt. The commands used in this demo are available in stream2excel.m. These files are available from MATLAB Central. The stream2excel.m help explains how to call this function with pre-recorded data or with an instrument attached to your computer.

The instrument used was a Tektronix TDS210 oscilloscope connected through the GPIB host. Alternatively, you may to talk to the instrument through the serial port. To learn how to read and write data with the Instrument Control Toolbox, refer to the documentation.

The data collected is filtered to smooth out the quantization noise and other artifacts from the digitally sampled waveform (Refer to the Filter Design Toolbox documentation). The filter used is an IIR Chebyshev Type II filter designed with the Filter Design and Analysis (FDA) Tool provided with the Signal Processing Toolbox.

The following sections provide an explanation of the pertinent MATLAB commands used in stream2excel.m. You will acquire the data from the instrument, then analyze it and transfer it to Excel.

How to Collect Data with the Instrument Control Toolbox

The following commands describe how to use the Instrument Control Toolbox to collect data from an oscilloscope that is connected through a GPIB board on the computer. Specifically, a waveform from an oscilloscope is read into MATLAB. The scaling information of that data is also read from the instrument so that the data can be scaled in MATLAB.

The GPIB object is created in the MATLAB workspace and it contains the properties that are necessary to successfully link with the instrument.

obj = gpib('ni',0,1);

Alternatively you can use the serial port of the computer. The serial interface is part of core MATLAB.

obj = serial('COM1');

Set a convenient buffer size twice the length of the data.

set(obj,'InputBufferSize',5000);

Connect to the oscilloscope.

fopen(obj);

View the state of the object.

obj

GPIB Object Using NI Adaptor : GPIB0-1

Communication Address

  • BoardIndex: 0
  • PrimaryAddress: 1
  • SecondaryAddress: 0

Communication State

  • Status: closed
  • RecordStatus: off

Read/Write State

  • TransferStatus: idle
  • BytesAvailable: 0
  • ValuesReceived: 0
  • ValuesSent: 0

You will use the FPRINTF function to send commands to the oscilloscope using the above created GPIB object. The FREAD function will be used to capture data that becomes available through the GPIB interface.

To configure the oscilloscope to read 2500 points, you will use commands that are described in detail in the TDS 200-Series Programmer Manual.

fprintf(obj, 'Data:Source CH1');

fprintf(obj, 'Data:Encdg SRPbinary');

fprintf(obj, 'Data:Width 1');

fprintf(obj, 'Data:Start 1');

fprintf(obj, 'Data:Stop 2500');

fprintf(obj, 'Curve?');

Discard the first six bytes, as they only describe the data length.

trash = fread(obj, 6, 'int8');

Read in the waveform. You are using the unsigned integer 8-bit data type because you have configured the oscilloscope to send positive integer data bytes.

data = fread(obj, 2500, 'uint8');

Read in the terminator.

trash = fread(obj, 1, 'int8');

Scale the data.

fprintf(obj, 'WFMPre:YMult?')

ymult = fscanf(obj, '%%g');

fprintf(obj, 'WFMPre:YOff?')

yoff = fscanf(obj, '%%g');

fprintf(obj, 'WFMPre:YZEro?')

yzero = fscanf(obj, '%%g');

data = (data - yoff) * ymult + yzero;

Part 2

Contact sales
E-mail this page
Print this page
Subscribe to newsletters