Build Models to Acquire Data

Data Acquisition Toolbox Block Library

This section provides an example that builds a simple model using the block in conjunction with a block from another block library. It illustrates how to bring live analog data into Simulink® from a data acquisition device, in this case a sound card.

Bring Analog Data into a Model

Step 1: Open the Data Acquisition Toolbox Block Library

To use the Analog Input block, you must open the Data Acquisition Toolbox™ block library. To open the library, start the Simulink Library Browser and select Data Acquisition Toolbox software entry from the list displayed in the browser.

To start the Simulink Library Browser, enter

simulink

at the MATLAB Command window. In the Simulink Library Browser, the left pane lists the available block libraries. To open the Data Acquisition Toolbox block library, click its icon.

Step 2: Create a New Model

To use a block, you must add it to an existing model or create a new model.

Create a new model by clicking the Create a new model button in the Simulink Library Browser.

Step 3: Add the Analog Input Block to the Model

To use the Analog Input block in a model, click the block in the library and, holding the left mouse button down, drag it into the Simulink editor. Note how the name on the block changes to reflect the first available analog device connected to your system.

Step 4: Add a Scope to the Model

To illustrate using the block, this example creates a simple model that acquires analog data from a microphone, via a sound card (the analog device), and then outputs the data to a scope, where you can see the intensity of the sound waves. To create this model, this example uses a Scope block from the basic Simulink block library.

Expand the Simulink block library by clicking Simulink at the top of the library list, if it is not already open. In the library window, open the Sinks group. From this group, click the Scope block in the library and, holding the left mouse button down, drag the block into the Simulink editor.

Step 5: Specify Block Parameters

To specify Analog Input block parameter settings, double-click the block's icon in the Simulink editor. This opens the Source Block Parameters dialog box for the Analog Input block, shown in the following figure. Use the various fields to determine the current values of the Analog Input block parameters or to change the values.

In this example, keep the default settings for everything except Block size. Change the block size setting to 5, which means five samples will be acquired from each channel at every time step. As you can see in the dialog box, the acquisition will be asynchronous, and the left and right channels will both use the same port, since the 1 for all hardware channels option is selected for Number of ports.

After changing the block size to 5, click OK to close the dialog box. For more information on the options and the Analog Input block, see the Analog Input block reference page.

Step 6: Connect the Blocks

Connect the output from the Analog Input block to the Scope. Use the cursor in the model to drag a connection from the port of the Analog Input block to the scope.

Step 7: Run the Simulation

Before running the simulation, change the run time to 20 seconds by editing the default of 10 seconds in the Simulink editortoolbar.

Open the scope by double-clicking the Scope block in the model. You will see live sound waves in the scope when the model is running.

Run the simulation by clicking the Run toolbar button. During the 20 seconds that the simulation is running, speak into the microphone.

While the simulation is running, the status bar at the bottom of the Simulink editor indicates the progress of the simulation. If you are speaking into the microphone, you will also see the live sound data plotted in the scope.

Step 8: Look at the Data in the Scope

When the 20 seconds elapses, the model stops running and you will have 20 seconds of sound data displayed by the scope. Click the Autoscale toolbar button (binoculars icon) in the scope to see the portion of the collected data that has the most contrast or significance. It will look something like this:

Note in the above example that words were spoken into the microphone between the 7th and 8th second, and only ambient sound is picked up between the 9th and 10th second.

In the following example, you can see that the volume of the sound peaked around the 18th second, when shouting was picked up by the microphone.

Was this topic helpful?