Configure Analog Input Properties

Analog Input: Basic Properties

After hardware channels are added to the analog input object, you should configure property values. As described in Configure and Return Properties, Data Acquisition Toolbox™ software supports two basic types of properties for analog input objects: common properties and channel properties. Common properties apply to all channels contained by the device object while channel properties apply to individual channels.

The properties you configure depend on your particular analog input application. For many common applications, there is a small group of properties related to the basic setup that you will typically use. These basic setup properties control the sampling rate, define the trigger type, and define the samples to be acquired per trigger. Analog input properties related to the basic setup are given below.

Analog Input Basic Setup Properties

Property Name

Description

SampleRate

Specify the per-channel rate at which analog data is converted to digital data.

SamplesPerTrigger

Specify the number of samples to acquire for each channel group member for each trigger that occurs.

TriggerType

Specify the type of trigger to execute.

Sampling Rate

You control the rate at which an analog input subsystem converts analog data to digital data with the SampleRate property. Specify SampleRate as samples per second. For example, to set the sampling rate for each channel of your National Instruments® board to 100,000 samples per second (100 kHz)

ai = analoginput('nidaq','Dev1');
addchannel(ai,0:1);
ai.SampleRate = 100000

Data acquisition boards typically have predefined sampling rates that you can set. If you specify a sampling rate that does not match one of these predefined values, there are two possibilities:

  • If the rate is within the range of valid values, then the engine automatically selects a valid sampling rate.

  • If the rate is outside the range of valid values, then an error is returned.

After setting a value for SampleRate, find out the actual rate set by the engine.

ActualRate = ai.SampleRate;

Alternatively, you can use the setverify function, which sets a property value and returns the actual value set.

ActualRate = setverify(ai,'SampleRate',100000);

You can find the range of valid sampling rates for your hardware with the propinfo function.

ValidRates = ai.SampleRate;
ValidRates.ConstraintValue
ans =
  1.0e+005 *
    0.0000    2.0000

The maximum rate at which channels are sampled depends on the type of hardware you are using. The maximum board rate determines the maximum sampling rate for each channel if you are using simultaneous sample and hold (SS/H) hardware such as a sound card. For example, suppose you create the analog input object ai for a sound card and configure it for stereo operation. If the device has a maximum rate of 48.0 kHz, then the maximum sampling rate per channel is 48.0 kHz.

ai = analoginput('winsound');
addchannel(ai,1:2);
ai.SampleRate = 48000

If you are using scanning hardware such as a National Instruments board, then the maximum sampling rate your hardware is rated at typically applies for one channel. You can apply the following formula to calculate the maximum sampling rate per channel:

For example, suppose you create the analog input object ai for a National Instruments board and add ten channels to it. If the device has a maximum rate of 100 kHz, then the maximum sampling rate per channel is 10 kHz.

ai = analoginput('nidaq','Dev1');
ai.InputType = SingleEnded
addchannel(ai,0:9);
ai.SampleRate = 10000

Typically, you can achieve this maximum rate only under ideal conditions. In practice, the sampling rate depends on several characteristics of the analog input subsystem including the settling time, the gain, and the channel skew. See Channel Skew for more information

The hardware clock governs the list of valid sample rates on the device. Most devices offer a fixed speed hardware clock, used to drive the timing of an acquisition. In order to achieve a required sample rate, there is a programmable divider set from 1 to 65536. This limits the device to 65535 possible sample rates. For instance with a 100,000Hz clock, if you request 1,200 samples per second, you can set the divider to either 83 or 84. This setting results in a sample rate of either 1,204.82 (100,000/83) or 1,190.48 (100,000/84).

    Notes   For some sound cards, you can set the sampling rate to any value between the minimum and maximum values defined by the hardware. You can enable this feature with the StandardSampleRates property. Refer to for more information.

    When you change the SampleRate value, and the BufferingMode property is Auto the engine recalculates the BufferingConfig property value. BufferingConfig indicates the memory used by the engine.

Trigger Types

For analog input objects, a trigger is defined as an event that initiates data logging to memory or to a disk file. Defining an analog input trigger involves specifying the trigger type with the TriggerType property. The TriggerType values that are supported for all hardware are given below.

Analog Input TriggerType Property Values

TriggerType Value

Description

{Immediate}

The trigger occurs just after the start function is issued.

Manual

The trigger occurs just after you manually issue the trigger function.

Software

The trigger occurs when the associated trigger condition is satisfied. Trigger conditions are given by the TriggerCondition property.

Many devices have additional hardware trigger types, which are available to you through the TriggerType property.

This information tells you that the National Instruments board also supports a hardware digital trigger. For a description of device-specific trigger types, refer to Device-Specific Hardware Triggers, or the TriggerType reference pages in the properties.

    Note   Triggering can be a complicated issue and it has many associated properties. For detailed information about triggering, refer to Configure Analog Input Triggers.

Samples to Acquire per Trigger

When a trigger executes, a predefined number of samples is acquired for each channel group member and logged to the engine or a disk file. You specify the number of samples to acquire per trigger with the SamplesPerTrigger property.

The default value of SamplesPerTrigger is calculated by the engine such that 1 second of data is collected, and is based on the default value of SampleRate. In general, to calculate the acquisition time for each trigger, you apply the formula

acquisition time (seconds) = samples per trigger/sampling rate (in Hz)

For example, to acquire 5 seconds of data per trigger for each channel contained by ai:

ai.SamplesPerTrigger = 500000

To continually acquire data, you set SamplesPerTrigger to inf.

ai.SamplesPerTrigger = inf

A continuous acquisition stops only if you issue the stop function, or an error occurs.

Was this topic helpful?