Data Acquisition Toolbox

Key Features

  • Support for a variety of industry-standard data acquisition boards and USB modules
  • Support for analog input, analog output, counters, timers, and digital I/O
  • Direct access to voltage, current, IEPE accelerometer, and thermocouple measurements
  • Live acquisition of measured data directly into MATLAB or Simulink
  • Hardware and software triggers for control of data acquisition
  • Device-independent software interface
Using Data Acquisition Toolbox to acquire an input signal from a data acquisition board directly into MATLAB

Using Data Acquisition Toolbox to acquire an input signal from a data acquisition board directly into MATLAB. The acquired data is displayed simultaneously as a time-domain signal, an instantaneous FFT, and a waterfall plot, making use of MATLAB signal processing and visualization capabilities.

Supported Hardware Devices and Vendors

Data Acquisition Toolbox supports PC-compatible data acquisition hardware from multiple vendors, including Advantech, Measurement Computing, and National Instruments. The toolbox also supports Microsoft® Windows® compatible sound cards. In addition, it is compatible with hardware from several data acquisition vendors via third-party adaptors. See more information on supported hardware.

If you work with a variety of hardware, the toolbox provides common base properties that apply to all supported hardware, such as sample rate, trigger settings, and channel properties. Using these properties promotes code reuse and reduces the need to change code when you change hardware. The toolbox also enables you to access device-specific features of your hardware from MATLAB.

To experiment with hardware and collect data interactively, you can execute toolbox functions from the MATLAB command line. You can also create MATLAB applications or work with live data in Simulink models.

Making Measurements with DAQ Hardware

Data Acquisition Toolbox lets you make a variety of measurements directly from MATLAB without the need to convert the data. Most data acquisition hardware provides the general capability to convert analog voltage data to a digital signal that a computer can process. Some data acquisition hardware has additional capabilities that allow for collecting and processing data directly from thermocouples, RTD devices, IEPE accelerometers and microphones, current-based sensors, or bridge-based sensors. To facilitate making measurements directly from MATLAB, Data Acquisition Toolbox supports the following measurement types:

Voltage — Data from general purpose A/D cards and sound card recording devices

Current — Data from current-based sensors, such as 4-20 mA sensors commonly used for process control

IEPE accelerometer — Data from IEPE accelerometers that need a constant excitation current source on the same wire on which you measure the acceleration

IEPE microphone — Data from IEPE microphones that need a constant excitation current source on the same wire on which you measure the sound pressure

Thermocouple and RTD — Data measured in degrees Celsius, Fahrenheit, or Kelvin

Bridge-based sensor — Data from resistive sensors, such as strain gauges in a variety of bridge configurations that require an excitation voltage

Accessing Subsystems of a DAQ Device

The toolbox provides functions to access four subsystems commonly found on DAQ hardware: analog input, analog output, digital I/O, and counter/timer. Depending on your application and hardware, you use either the legacy or session-based interface to communicate with the hardware.

Legacy and Session-Based Interfaces

 The legacy interface supports hardware from multiple vendors and all sound cards on 32-bit versions of MATLAB. (You can use this version of MATLAB on either 32-bit or 64-bit versions of Windows.) The legacy interface also supports voltage measurements of analog input, analog output, and digital I/O subsystems.

Setup for a data acquisition and analysis session using the legacy interface

Setup for a data acquisition and analysis session using the legacy interface. Data Acquisition Toolbox enables MATLAB or Simulink to interface with the data acquisition boards, such as sound cards.

The session-based interface supports analog input, analog output, digital I/O, and counter/timer subsystems on both 32-bit and 64-bit versions of MATLAB. This interface supports National Instruments hardware that can perform a wide variety of measurements such as voltage, current, temperature, IEPE accelerometer, and bridge measurements. The session-based interface also supports Windows sound cards and Digilent Analog Discovery hardware.

Sample code that uses the session-based interface.

Sample code that uses the session-based interface. Data Acquisition Toolbox enables MATLAB to discover and interface with data acquisition devices such as the NI 9205 CompactDAQ module.

In either interface, you create device or session objects to provide a gateway to the hardware's functionality and to control the behavior of your acquisition. For example, you can execute any supported analog input task via an analog input object created in MATLAB or Simulink.

By adding channels or lines to your device or session object, you can synchronize the collection of your data. The toolbox supports an unlimited number of channels or lines, enabling you to use as many as your hardware permits.

Analog Input

Analog input functions let you acquire signals from your hardware. You can create an analog input object, add channels to the object, acquire data to memory, read data into the workspace, and preview the most recently acquired data.

Analog Output

Analog output functions let you send signals out from your hardware. You can create an analog output object, add channels, queue data sets for output, and generate analog signals.

Digital I/O

Digital I/O functions enable you to generate or read digital signals using your hardware. You can create digital I/O objects, add lines, send data to the hardware, and read data into the workspace. The toolbox supports clocked digital I/O using the session-based interface. The legacy interface of the toolbox provides support for static acquisition and control.

Counter/Timer

Counter/timer functions let you access counters on data acquisition hardware. You can configure counters as input or output channels. Counters configured as inputs can count events and measure frequency, pulse width, and position; counters configured as outputs can generate pulse trains.

MATLAB code used to acquire data from a DAQ device with counter/timer channels

MATLAB code used to acquire data from a DAQ device with counter/timer channels.

Audio Input and Output

Audio input and audio output functions let you acquire and generate signals using built-in or external sound card. You can create an audio input object, add multiple audio channels to the object, acquire data to memory, read data into the workspace, and preview the most recently acquired audio data.

Controlling Your Acquisition

Data Acquisition Toolbox supports a wide range of functions for controlling your acquisition. For example, you can set event information, evaluate acquisition status, define triggers and callbacks, preview data while a device is running, and perform analysis on the fly. The toolbox also supports several hardware-specific properties that can be displayed and customized to your specifications.

Managing Data

The toolbox provides functions for previewing and extracting data for analysis. It streams data into MATLAB or Simulink in double-precision floating-point format, enabling you to work with the data just as you would with any other matrix in MATLAB or Simulink. You can also use a native hardware format to stream in data.

Logging Data

Data Acquisition Toolbox provides functions for logging data to disk, memory, or both, while an analog input object is running. You can log data, events, and errors. In addition, the toolbox provides functions for extracting data from log files it has generated.

Using the Oscilloscope Interface

You can interactively select and configure data acquisition sources in MATLAB. A familiar oscillosope-like interface enables you to acquire, view, and analyze data. Through a library of built-in measurement functions, you can verify hardware operation and perform live data analysis. You can extend the interface with your own analysis functions and export data to the MATLAB workspace. This oscilloscope UI is available on the 32-bit version of MATLAB only.

Two channels of live audio data displayed and analyzed using the SoftScope graphical interface.

Two channels of live audio data displayed and analyzed. A few lines of code let you acquire two seconds of data from a data acquisition board, calculate the frequency components of the data, and plot the results in MATLAB.

Basic Features of the Oscilloscope Interface 2:18
Acquire and display data from data acquisition cards without writing code using the oscilloscope interface.

Advanced Features of the Oscilloscope Interface 4:08
Make custom measurements on acquired data and export results to the MATLAB® workspace using advanced features of the oscilloscope interface.

Simultaneous Collection and Analysis of Data

Most data acquisition tasks are initiated by events. An event occurs at a specific time after a condition has been met. Event types supported by Data Acquisition Toolbox include:

  • Start and stop
  • Number of samples acquired
  • Errors
  • Triggers
  • Number of output samples

Events may result in one or more callbacks. In MATLAB, these event types execute a MATLAB function that you specify.

The session-based interface provides functions for both foreground and background data acquisition. Foreground data acquisition blocks the MATLAB command line; background acquisition does not. Background acquisition enables you to collect data continuously and plot or process the data while you are collecting it. A listener is available to flag session events. When an event occurs, the specified callback function is executed.

Handling Errors

Data Acquisition Toolbox provides a consistent set of error and warning messages. If a hardware error message is not handled by the toolbox in MATLAB or Simulink, an external error is reported with the vendor-specific hardware error message.

Evaluating Your Acquisition

Data Acquisition Toolbox lets you evaluate the status of an acquisition and the available data acquisition resources, including installed hardware, hardware drivers, and adapters. You can display the following types of information:

  • Device object and channel status
  • Session object status
  • Hardware information
  • Data acquisition engine information
Script illustrating the four steps of a typical MATLAB data acquisition session: creation, configuration, acquisition, and clean-up.

Script illustrating the four steps of a typical MATLAB data acquisition session: creation, configuration, acquisition, and clean-up. A few lines of code let you acquire two seconds of data from a data acquisition device, process the acquired data, and visualize the results.

Performing Data Acquisition in Simulink

Data Acquisition Toolbox provides Simulink blocks for acquiring live or measured data directly into your models, or for configuring hardware interfaced to data acquisition devices. These blocks are only available using the Legacy interface and the 32-bit version of MATLAB.

You can use the blocks to quickly evaluate the response of your Simulink models and algorithms with real-world data instead of designing systems against static data sets, such as those saved in files. You can also use the blocks to verify and validate models against live, measured data as part of the design verification process.

Data Acquisition Toolbox provides six Simulink blocks:

  • Analog Input: Acquire data from analog channels
  • Analog Input Single Sample: Acquire a single sample from each channel at each sample time
  • Analog Output: Output data to analog channels
  • Analog Output Single Sample: Send out a single sample from each channel at each sample time
  • Digital Input: Acquire the latest set of values from digital lines
  • Digital Output: Output data to digital lines

Input blocks let you acquire live data from hardware and then incorporate that data directly into your models. Output blocks let you configure hardware from your Simulink models, including instructing hardware to send data.

Each block enables you to configure parameters including device type, channels, and lines. The analog blocks also enable you to configure other relevant parameters such as asynchronous versus synchronous acquisition, sample rate, block size, and data type. You can connect the Simulink model to a broad range of data acquisition hardware, and later change devices with minimal changes to your model. By using Simulink with Data Acquisition Toolbox, you can verify designs with live data.

Analog Input block dialog box.

Analog Input block dialog box. Configure parameters such as acquisition mode, device type, and sample rate.

Acquiring live analog data directly into a Simulink model using the Analog Input block.

Acquiring live analog data directly into a Simulink model using the Analog Input block. By using live data, you can quickly try different data permutations and make adjustments in your Simulink model.

Try Data Acquisition Toolbox

Get trial software

Hands-on Learning with MATLAB and Analog Discovery

View webinar