Data Acquisition with the Data Acquisition Toolbox
These examples will show how to acquire data from a DAQ using the Data Acquisition Toolbox. Since this functionality is not supported for code generation, this functionality is best used when running MATLAB functions and Simulink models directly on a desktop computer.
There are many different DAQ units. The primary vendors are Analog Devices and NI. A sound card is also considered a DAQ and can be used for sampling. Use the following website to determine what data acquisition hardware is supported:
To acquire analog or audio data from a DAQ in MATLAB, use the following functions:
First, to create a data acquisition session:
- daq.createSession - Create data acquisition session for specific vendor hardware
Second, to add an input channel:
And third, to acquire data:
- startForeground - Start foreground data acquisition
To acquire analog or audio data from a DAQ in Simulink, use the following blocks:
- Code generation is not supported - Cannot generate a MATLAB Executable (.mex) or a generic executable (.exe) out of MATLAB or Simulink code which contains DAQ Toolbox functionality. Use the DSP System Toolbox's acquisition functionality instead if trying to generate code.
- Simulink blocks on 64-bit Windows are not supported - Cannot use the Analog Input blocks in Simulink if using 64-bit Windows OS. Use Simulink Desktop Real-Time's data acquisition functionality instead if using Simulink with a 64-bit Windows OS.
There are multiple examples in the documentation showing how to acquire data from a data acquisition board.
Foreground vs. Background
Analog vs. Audio