Perform Live Acquisition, Signal Processing, and Generation
This example shows how to use the Analog Input block to acquire live analog data from a data acquisition device into Simulink. The acquired data is processed in Simulink and uses the Analog Output block to output data to a data acquisition device. It shows how a Simulink model can communicate with different subsystems in the same model. In this case, the data acquisition device used is from National Instruments®.
Note: This example requires MATLAB®, Data Acquisition Toolbox, and Simulink to open and run the model.
Live Data Input
The input signal is acquired from a National Instruments data acquisition device (USB-6211). Signal is acquired from channel ai0 at the rate of 8000 samples/second. The Analog Input block is configured to do synchronous acquisition, which does blocking read from the device and at each timestep it acquires a chunk of 1600 samples from the hardware.
Note: Each column in the output of Analog Input block corresponds to data from an analog input channel. To correctly interpret the data, in the downstream processing/visualization blocks, you need to use 'Columns as Channels (frame-based)' as Input Processing method.
The acquired data is processed using a discrete filter. The discrete filter uses pre-computed coefficients to implement a bandpass filter with a bandwidth of 50Hz around 100Hz and an attenuation of 60dB elsewhere, for input signals sampled at 8kHz. To design digital filters, to select specific implementation structures, use blocks from the "Filtering" library in DSP System Toolbox. The capture data has three major frequency components: sine waves at 100Hz, 500Hz and 1000Hz. After the discrete filter, you would see a clear 100Hz sine wave in the output. A plot of the input and the filtered signals are shown below.
Live Data Output
The processed data is output to a single channel of a National Instruments device (PCI-6211) at a rate of 8000 samples/second.
Even though a National Instruments device was used for this example, this model can be easily updated to connect to other supported data acquisition devices. This provides you the flexibility to reuse the same Simulink model with different data acquisition hardware.