Newsletters - MATLAB News & Notes
Live Communication with Instruments from MATLAB
by Melissa Pike
There is now an easy way to control and communicate with instruments directly from MATLAB. Just released for use with MATLAB 6, the Instrument Control Toolbox lets you configure instruments, query instrument settings, and access measurement data. Once the data has been read into MATLAB, you can use all of MATLAB's computational tools for analyzing and visualizing your data. Based on the results of your analysis, you can write new data to your instrument or you can tweak your instrument settings.
The Instrument Control Toolbox is completely integrated with MATLAB, so you can:
- Perform analysis on your data while you are collecting it
- Save instrument configuration steps and settings along with
measurement data to a text file for later debugging, analysis or reuse - Make iterative updates to your test setup based on your analysis
- Stream measurement data from your instrument into an Excel spreadsheet
- Take advantage of MathWorks application-specific toolboxes to provide additional analysis
By staying within the MATLAB environment, you will spend less time and effort configuring your instrument and accessing the measurement data. This will leave more time for analyzing and visualizing your data using MATLAB. You can either use a graphical or textual approach to communicate with your instrument. The graphical user interfaces (GUIs) provided with the toolbox let you define the settings of your instrument and let you transfer ASCII data to and from your instrument. Using the textual approach, you have the full flexibility of the MATLAB language and you can begin communicating with your instrument in as little as five MATLAB commands.
Storing a Snapshot of an Oscilloscope Display
![]() |
| The Instrument Control Toolbox allows you to communicate with instruments directly from MATLAB. Here, a waveform is read from an oscilloscope into MATLAB and plotted. |
Let's take a look at an example of bringing data from an instrument into MATLAB.
Suppose you have an oscilloscope that is displaying your test results and you would like to record the results of your test. Using MATLAB and the Instrument Control Toolbox, you can capture and store the oscilloscope display thereby providing a permanent record of your work and an easy way to document important signal and scope parameters.
This example uses a National Instruments' GPIB controller with board index 0, and a Tektronix TDS 210 oscilloscope configured with a primary address of 2. The first step is to create an instrument object. Create the GPIB object (g) associated with the GPIB controller and oscilloscope.
g = gpib('ni', 0, 2);
Next, we configure the input buffer to 50,000 bytes in order to hold the entire snapshot of the oscilloscope display. We also configure the timeout to one minute to provide adequate time to transfer the data.
set(g, 'InputBufferSize', 50000);
set(g, 'Timeout', 60);
Next we connect to the instrument. Once the connection is established, we can transfer data between MATLAB and the instrument.
fopen(g)
To write and read the data, we instruct the oscilloscope to transfer the screen display as a bitmap.
fprintf(g, 'HARDCOPY:PORT GPIB');
fprintf(g, 'HARDCOPY:FORMAT BMP');
fprintf(g, 'HARDCOPY START');
Now, we can read the data into MATLAB.
data = fread(g, 38462, 'uint8');
Once the data has been read into MATLAB, we no longer need access to the instrument and we can disconnect the object from the instrument and remove it from memory.
fclose(g)
delete(g)
Our final step is to visualize the data in MATLAB. Now that the
measurement data has been read into MATLAB, we can use MATLAB functions to save the data to disk and to view the data.
![]() |
| Here, the test results from an oscilloscope are read into MATLAB and displayed. |
fid = fopen('screen.bmp', 'w');
fwrite(fid, data, 'uint8');
fclose(fid)
bmp_data = imread('screen.bmp', 'bmp');
imagesc(bmp_data);
colormap(gray(2));
axis('off')
The resulting graph is shown:
![]()
Instrument Control Toolbox Features:
|
| At Moss Landing Marine Laboratories in California, Professor Bill Broenkow is using MATLAB and the Instrument Control Toolbox to teach marine science, with a focus on physical and satellite oceanography, and instrumentation. He uses MATLAB and the Instrument Control Toolbox to teach students to work with instruments and to create procedures for gathering oceanographic data. "Using MATLAB with our Ocean Optics radiometer will give the students the opportunity to learn radiometer calibration and data reduction procedures," said Broenkow, "It's a big eye-opener for [students] to see that experimental data can be acquired directly into MATLAB." |
| Dr. Kobi Cohen, research engineer at I.M.I. Rocket Systems Division, is responsible for developing test and analysis systems. In a stimulus-response test set-up he developed, he used the Instrument Control Toolbox to communicate with instruments and vary parameters of the test, and the Data Acquisition Toolbox to simultaneously collect eight channels of data. This data was then analyzed and plotted in MATLAB. "My test is working perfectly. I'm able to control eight instruments at the same time using serial and GPIB. I can then instantly analyze the results in MATLAB," Cohen said. |
To learn more about the Instrument Control Toolbox, visit:
www.mathworks.com/products/instrument ![]()
Store

