Manage Output Data

Analog Output Subsystem

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

Property Name



Indicate the maximum number of samples that can be queued in the engine.


Specify the number of additional times queued data is output.


Specify an additional waiting time to queue data.

Data Queuing

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:

ao = analogoutput('winsound');
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.

Rules for Using putdata

Using 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 RepeatOutput property is greater than 0, then all queued data is automatically requeued until the RepeatOutput value is reached. You must configure RepeatOutput before start is issued.

  • While the analog output object is running, you can continue to queue data unless RepeatOutput is greater than 0.

  • You can queue data in the engine until the value specified by the MaxSamplesQueued property is reached, or the limitations of your hardware or computer are reached.

Rules for Queuing Data

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 NaN is 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 UnitsRange. Refer to Scale Data Linearly for more information about clipping.

Queue Data with putdata

This example illustrates how you can use putdata to queue 16000 samples, and then output the data a total of five times using the RepeatOutput property.

To run this example type daqdoc6_3 at the MATLAB Command Window.

  1. Create a device object — Create the analog output object AO for a sound card. The installed adaptors and hardware IDs are found with daqhwinfo.

    AO = analogoutput('winsound');
    %AO = analogoutput('nidaq','Dev1');
    %AO = analogoutput('mcc',1);
  2. Add channels — Add one channel to AO.

    chans = addchannel(AO,1);
    %chans = addchannel(AO,0); % For NI and MCC
  3. 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 putdata calls. Because the queued data is repeated four times and two putdata calls 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
  4. Output data — Start AO and wait for the device object to stop running.

  5. Clean up — When you no longer need AO, you should remove it from memory and from the MATLAB workspace.

    clear AO
Was this topic helpful?