Data Acquisition Toolbox™ software provides you with a way to linearly scale data as it is being queued in the engine. You can associate this scaling with specific engineering units such as volts or Newtons that you might want to apply to your data.
The properties associated with engineering units and linearly scaling output data are as follows:
Specify the range of the analog output hardware subsystem.
Specify the engineering units label.
Specify the range of data as engineering units.
For many devices, the output range is expressed in terms of the gain and polarity.
Note You can set the engineering units properties on a per-channel basis. Therefore, you can configure different engineering unit conversions for each hardware channel.
Linearly scaled output data is given by the formula:
scaled value = (original value)(output range)/(units range)
The units range is given by the
while the output range is given by the
the scaling of data when it is queued in the engine with the
the gain and polarity of your D/A subsystem. You should choose an
output range that encompasses the output signal, and that utilizes
the maximum dynamic range of your hardware.
For sound cards, you might have to adjust the volume control to obtain the full-scale output range of the device. See Sound Cards to learn how to access the volume control for your sound card.
For example, suppose
If a queued value is 2.5, then the scaled value is (2.5)(20/10) or
5, in the appropriate units.
Note The data acquisition engine always clips out-of-range values. Clipping means that an out-of-range value is fixed to either the minimum or maximum value that is representable by the hardware. Clipping is equivalent to saturation.
This example illustrates how to configure the engineering units properties for an analog output object connected to a National Instruments® PCI-6024E board.
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.
The queued data consists of a 4 volt peak-to-peak sine wave.
UnitsRange property is configured
so that queued data is scaled to the
value, which is fixed at ±10 volts. This scaling utilizes the
maximum dynamic range of the analog output hardware.
You can run this example by typing
the MATLAB Command Window.
Create a device object —
Create the analog output object
AO for a National Instruments board.
The installed adaptors and hardware IDs are found with
AO = analogoutput('nidaq','Dev1');
Add channels —
Add one hardware channel to
chan = addchannel(AO,0);
Configure property values — Create the data to be queued.
freq = 500; w = 2*pi*freq; t = linspace(0,2,20000); data = 2*sin(w*t)';
the sampling rate to 5 kHz, configure the trigger to repeat two times,
and scale the data to cover the full output range of the D/A converter.
Because the peak-to-peak amplitude of the queued data is 4,
[-2 2], which scales the output data to
20 volts peak-to-peak.
AO.'SampleRate = 5000 AO.RepeatOutput = 2 chan.UnitsRange = [-2 2]
Queue the data with one call to
Calculate the time to wait for data generation to complete. The wait time is based on:
the amount of data queued.
the number of times the generation repeats.
extra time to allow for the time it takes to configure and start the device.
timeToWait = (length(data)/AO.SampleRate)*(AO.RepeatOutput + 1)*1.1;
Output data —
AO and wait until all the data is output.
Clean up —
When you no longer need
AO, you should remove it
from memory and from the MATLAB workspace.
delete(AO) clear AO