At the core of any analog output application lies the data you want to send from a computer to an output device such as an actuator. The role of the analog output subsystem is to convert digitized data to analog data for subsequent output.
Before you can output data to the analog output subsystem, it
must be queued in the engine. Queuing data is managed with the
putdata function. In addition to this function,
there are several properties associated with managing output data.
These properties are given below.
Table 8-6. Analog Output Data Management Properties
Before data can be sent to the analog output hardware, you must
queue it in the engine. Queuing data is managed with the
putdata function. One column of data is
required for each channel contained by the analog output object. For
example, to queue one second of data for each channel contained by
the analog output object
ao = analogoutput('winsound'); addchannel(ao,1:2); data = sin(linspace(0,2*pi*500,8000))'; putdata(ao,[data data])
A data source consisting of m samples and n channels is illustrated below.
putdata to queue data
in the engine follows these rules:
You must queue data in the engine before starting the analog output object.
If the value of the
is greater than 0, then all queued data is automatically requeued
RepeatOutput value is reached. You must
While the analog output object is running, you can
continue to queue data unless
RepeatOutput is greater
You can queue data in the engine until the value specified
is reached, or the limitations of your hardware or computer are reached.
Data to be queued in the engine follows these rules:
Data is output as soon as a trigger occurs.
An error is returned if a
included in the data stream.
You can use the native data type of the hardware.
If the data is not within the range of the
UnitsRange property, then it is clipped
to the maximum or minimum value specified by
Refer to Scale Data Linearly for more information
Note: You cannot use the legacy interface on 64-bit MATLAB®. See About the Session-Based Interface to acquire and generate data on a 64-bit MATLAB.
To run this example type
daqdoc6_3 at the MATLAB Command
Create a device object —
Create the analog output object
AO for a sound
card. The installed adaptors and hardware IDs are found with
AO = analogoutput('winsound'); %AO = analogoutput('nidaq','Dev1'); %AO = analogoutput('mcc',1);
Add channels —
Add one channel to
chans = addchannel(AO,1); %chans = addchannel(AO,0); % For NI and MCC
Configure property values —
Define an output time of one second, assign values to the basic setup
properties, generate data to be queued, and issue two
Because the queued data is repeated four times and two
are issued, a total of 10 seconds of data is output.
% Set the SampleRate AO.SampleRate = 8000 % Obtain the actual rate set in case hardware limitations % prevent using the requested rate ActualRate = AO.SampleRate % Specify one second as the output time. % Use that to calculate the length of data duration = 1; len = ActualRate*duration; % Calculate the output signal based on the length of the data data = sin(linspace(0,2*pi*500,len))'; % All queued data is output once then repeated 4 times, % for a total of 5 times AO.RepeatOutput = 4 % Queue the output data twice putdata(AO,data) putdata(AO,data)
Output data —
AO and wait for the device object to stop
Clean up —
When you no longer need
AO, you should remove it
from memory and from the MATLAB workspace.
delete(AO) clear AO