Newsletters - MATLAB News & Notes
Data Acquisition Toolbox for MATLAB
New toolbox for communicating with hardware devices
by Jane Price
If you work with measured data, the new Data Acquisition Toolbox can streamline your work and accelerate your acquisition tasks. Just released for use with MATLAB, this new toolbox makes it easier to integrate all your test, analysis, and visualization applications within the MATLAB environment. The Data Acquisition Toolbox provides a full set of functions for controlling and communicating with a variety of off-the-shelf, PC-compatible data acquisition hardware, including:
- Multimedia sound card devices
- National Instruments E-Series and 1200-Series Boards
- Hewlett-Packard VXI E1432-Series Boards
- Additional third-party devices such as DSP Technology's SigLab
The inherent features of each manufacturer's hardware devices are exposed through the MATLAB interface. Whether you are using one or several hardware devices, the toolbox provides a single, unified interface across all devices. A consistent set of familiar MATLAB commands gives you full access to and control of the individual board features.
The Data Acquisition Toolbox is completely integrated with MATLAB, so you can perform analysis on your data while you are collecting it, save it for post-processing, or make iterative updates to your test setup based on your analysis. You can also take advantage of MathWorks application-specific toolboxes and Simulink to provide additional analysis and modeling capabilities.
Virtually any aspect of your acquisition can be controlled using the functions provided in the toolbox. For example, you can get event information, evaluate the acquisition status, define triggers and callbacks, preview data while the device is running, and perform analysis "on-the-fly." All hardware properties can be displayed and customized to meet your specifications.
Features
- Live data access directly from MATLAB
- Analog input, analog output, and digital I/O
- Direct interface to board features
- Seamless integration with MATLAB and MATLAB Toolboxes
- Multichannel support
- High-speed acquisition
- Triggering-software, hardware, and manual
- Data buffering for background acquisition (double buffering)
- Simultaneous A/D and D/A conversion
- Error handling
- Engineering units
- Callbacks on acquisition events-e.g., buffer full
- Data logging
Simplifying the Process
In the past, MATLAB users who work with data acquisition hardware have found it difficult to bring their data into MATLAB for analysis and visualization. To do this used to require you to write your own code to interface with your plug-in data acquisition board and transfer the data. Or you had to acquire data using a standalone software package and then convert the data to bring it into MATLAB.

Now, with the Data Acquisition Toolbox, you can communicate with, and control, your plug-in data acquisition hardware devices using familiar MATLAB commands. You no longer need to build a custom interface to your hardware or purchase and learn additional software products-you can do it all in MATLAB. A typical data acquisition session consists of these steps:
- Initialization: Create a device object.
- Configuration: Add channels and control acquisition behavior with properties.
- Execution: Start the device object and acquire or send data.
- Termination: Delete the device object.
This process is illustrated in the following example.
Acquiring Data with a Sound Card
For this example, we will verify that the fundamental (lowest) frequency of a tuning fork is 440 Hz. To do this, we will use a microphone and a sound card to collect audio data. Next, we will perform an FFT on the acquired data to find the frequency components of the tuning fork. The setup for this task is as follows:
We begin by acquiring one second of audio data on one sound card channel. Since the tuning fork vibrates at a nominal frequency of 440 Hz, the sound card sampling rate can be set to its lowest standard sampling rate of 8000 Hz. Even at this lowest rate, we are guaranteed not to experience any aliasing effects, because 8000 Hz is well above the expected Nyquist frequency.
After we have set the tuning fork vibrating and placed it near the microphone, we will trigger the acquisition one time using an immediate trigger. The complete data acquisition session for the sound card is shown below.

Initialization: The first step is to create the analog input object (AI) for the sound card.
AI = analoginput('winsound');
Configuration: Next, we add a single channel to AI and set the sample rate to 8000 Hz with an acquisition duration of 2 seconds:
addchannel(AI, 1);
Fs = 8000; % Sample Rate is 8000 Hz
AI.SampleRate = Fs;
duration = 2; % Two-second acquisition
AI.SamplesPerTrigger = duration*Fs;
Execution: Now, we are ready to start the acquisition. The default trigger behavior is to start collecting data as soon as the start command is issued. Before doing so, you should begin inputting data from the tuning fork into the microphone.
start(AI);
To retrieve all the data:
data = getdata(AI);
Termination: To end the acquisition session, we can delete the AI object from the workspace:
delete(AI)
Now let's determine the frequency components of the tuning fork and plot the results. We begin by calculating the absolute value of the FFT of the data.
xfft = abs(fft(data));
Convert the absolute value into dB magnitude and extract the real frequency components:
mag = 20*log10(xfft);
mag = mag(1:end/2);
The results are plotted below.

This plot shows the fundamental frequency around 440 Hz and the first overtone around 880 Hz. A simple way to find actual fundamental frequency is as follows:
[ymax, maxindex] = max(mag);
The answer is 441 Hz.
This example could be repeated using different hardware by simply changing two lines of code. For example, if we were to use a National Instruments multifunction card, then we could create the analog input object using
AI=analoginput('nidaq',1); % Board 1
addchannel(AI,0) % NI uses zero based indexing
Likewise, if we were to use an HP-E1432A to acquire the data, the code would read:
AI=analoginput('hpe1432',8); % Module in slot 8
addchannel(AI,1) % HP uses one- based indexing
The Data Acquisition Toolbox can simplify your test, measurement, and analysis process. By issuing a few familiar MATLAB commands, you can quickly and easily bring your data directly into MATLAB without having to write additional code or use multiple software products.
| The Data Acquisition Toolbox is a PC-only product and works with MATLAB version 5.3 or later.
To learn more about the Data Acquisition Toolbox, visit our Web site at www.mathworks.com/products/daq and try out the interactive demos. To receive your free technical kit, click here. |