Data Acquisition Toolbox | ![]() ![]() |
The data acquisition session comprises all the steps you are likely to take when acquiring or outputting data. These steps are:
analoginput
, analogoutput
, or digitalio
creation function. Device objects are the basic toolbox elements you use to access your hardware device.
set
function or dot notation.
You can configure many of the properties at any time. However, some properties are configurable only when the device object is not running. Conversely, depending on your hardware settings and the requirements of your application, you may be able to accept the default property values and skip this step.
start
function. While the device object is running, it behaves according to the previously configured or default property values.
After data is acquired, you must extract it from the engine with the getdata
function. Before you can output data, you must queue it in the engine with
the putdata
function.
delete
function, and remove it from the MATLAB workspace using the clear
command.
The data acquisition session is used in many of the documentation examples included in this guide. Note that the fourth step is treated differently for digital I/O objects since they do not store data in the engine. Therefore, only analog input and analog output objects are discussed in this section.
Example: The Data Acquisition Session
This example illustrates the basic steps you take during a data acquisition session using an analog input object. You can run this example by typing daqdoc3_1
at the MATLAB command line.
1. Create a device object - Create the analog input object AI
for a sound card. The installed adaptors and hardware IDs are found with daqhwinfo
.
AI = analoginput('winsound');
%AI = analoginput('nidaq',1);
%AI = analoginput('cbi',1);
2. Add channels - Add two channels to AI
.
addchannel(AI,1:2); %addchannel(AI,0:1); % For NI and CBI
3. Configure property values - Configure the sampling rate to 11.025 kHz and define a 2 second acquisition.
set(AI,'SampleRate',11025) set(AI,'SamplesPerTrigger',22050)
4. Acquire data - Start AI
, wait until the requested samples are acquired, and extract all the data from the engine. Before start
is issued, you may want to begin inputting data from a microphone or a CD player.
start(AI) while strcmp(AI.Running,'On') end data = getdata(AI);
Plot the data and label the figure axes.
plot(data) xlabel('Samples') ylabel('Signal (Volts)')
5. Clean up - When you no longer need AI
, you should remove it from memory and from the MATLAB workspace.
delete(AI) clear AI
![]() | Using the Data Acquisition Toolbox | Creating a Device Object | ![]() |