Documentation Center

  • Trial Software
  • Product Updates

Scale Data Linearly

Engineering Units

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:

Property Name

Description

OutputRange

Specify the range of the analog output hardware subsystem.

Units

Specify the engineering units label.

UnitsRange

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 UnitsRange property, while the output range is given by the OutputRange property. UnitsRange controls the scaling of data when it is queued in the engine with the putdata function. OutputRange specifies 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 OutputRange is [-10 10], and UnitsRange is [-5 5]. 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.

Perform a Linear Conversion

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 Session-Based Interface to acquire and generate data.

The queued data consists of a 4 volt peak-to-peak sine wave. The UnitsRange property is configured so that queued data is scaled to the OutputRange property 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 daqdoc6_6 at the MATLAB Command Window.

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

    AO = analogoutput('nidaq','Dev1');
    
  2. Add channels — Add one hardware channel to AO.

    chan = addchannel(AO,0);
  3. 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)';

    Configure 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, UnitsRange is set to [-2 2], which scales the output data to 20 volts peak-to-peak.

    set(AO,'SampleRate',5000)
    set(AO,'RepeatOutput',2)
    set(chan,'UnitsRange',[-2 2])

    Queue the data with one call to putdata.

    putdata(AO,data)
  4. 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;
  5. Output data — Start AO and wait until all the data is output.

    start(AO)
    wait(AO,timeToWait)
  6. Clean up — When you no longer need AO, you should remove it from memory and from the MATLAB workspace.

    delete(AO)
    clear AO
Was this topic helpful?