Data Acquisition Toolbox    

Repeating Triggers

You can configure triggers to occur once (one-shot acquisition) or multiple times. You control trigger repeats with the TriggerRepeat property. If TriggerRepeat is set to its default value of 0, then the trigger occurs once. If TriggerRepeat is set to a positive integer value, then the trigger is repeated the specified number of times. If TriggerRepeat is set to inf, then the trigger repeats continuously and you can stop the device object only by issuing the stop function.

Example: Voice Activation and Repeating Triggers

This example modifies daqdoc5_3 such that two triggers are issued. The specified amount of data is acquired for each trigger and stored in separate variables. The Timeout value is set to five seconds. Therefore, if getdata does not return the specified number of samples in the time given by the TimeOut property plus the time required to acquire the data, the acquisition will be aborted.

You can run this example by typing daqdoc5_5 at the MATLAB command line.

  1. Create a device object -- Create the analog input object AIVoice for a sound card. The installed adaptors and hardware IDs are found with daqhwinfo.
  2. Add channels -- Add one hardware channel to AIVoice.
  3. Configure property values -- Define a 1-second total acquisition time and configure a software trigger. The source of the trigger is chan, and the trigger executes when a rising voltage level has a value of at least 0.2 volt. Additionally, the trigger is repeated once when the trigger condition is met.
  4. Acquire data -- Start AIVoice, acquire the specified number of samples, extract all the data from the first trigger as sample-time pairs, and extract all the data from the second trigger as sample-time pairs. Note that you can extract the data acquired from both triggers with the command getdata(AIVoice,44100).
  1. Plot the data for both triggers.

    Make sure AIVoice has stopped running before cleaning up the workspace.

  1. Clean up -- When you no longer need AIVoice, you should remove it from memory and from the MATLAB workspace.

The data acquired for both triggers is shown below.

As described in Extracting Data from the Engine, if you do not specify the amount of data to extract from the engine with getdata, then the amount of data returned is given by the SamplesPerTrigger property. You can return data from multiple triggers with one call to getdata by specifying the appropriate number of samples. When you return data that spans multiple triggers, a NaN is inserted in the data stream between trigger events. Therefore, an extra "sample" (the NaN) is stored in the engine and returned by getdata. Identifying these NaNs allows you to locate where and when each trigger was issued in the data stream.

The figure below illustrates the data stored by the engine during a multiple-trigger acquisition. The data acquired for each trigger is given by the SamplesPerTrigger property value. The relative trigger times are shown on the Time axis where the first trigger time corresponds to t1 (0 seconds by definition), the second trigger time corresponds to t2, and so on.

The following code modifies daqdoc5_5 so that multiple-trigger data is extracted from the engine with one call to getdata.

Plot the data.

The multiple-trigger data is shown below.

You can find the relative trigger times by searching for NaNs in the returned data. You can find the index location of the NaN in d or t using the isnan function.

With this information, you can find the relative time for the second trigger.


  Trigger Delays How Many Triggers Occurred?