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.
AIVoice
for a sound card. The installed adaptors and hardware IDs are found with daqhwinfo
.
AIVoice = analoginput('winsound'); %AIVoice = analoginput('nidaq',1); %AIVoice = analoginput('mcc',1);
AIVoice
.
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.
duration = 0.5; % One-half second acquisition for each trigger set(AIVoice,'SampleRate',44100) ActualRate = get(AIVoice,'SampleRate'); set(AIVoice,'Timeout',5) set(AIVoice,'SamplesPerTrigger',ActualRate*duration) set(AIVoice,'TriggerChannel',chan) set(AIVoice,'TriggerType','Software') set(AIVoice,'TriggerCondition','Rising') set(AIVoice,'TriggerConditionValue',0.2) set(AIVoice,'TriggerRepeat',1)
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)
.
subplot(211), plot(t1,d1), grid on, hold on
axis([t1(1)-0.05 t1(end)+0.05 -0.8 0.8]) xlabel('Time (sec.)'), ylabel('Signal level (Volts)'), title('Voice Activation First Trigger') subplot(212), plot(t2,d2), grid on
axis([t2(1)-0.05 t2(end)+0.05 -0.8 0.8]) xlabel('Time (sec.)'), ylabel('Signal level (Volts)') title('Voice Activation Second Trigger')
Make sure AIVoice
has stopped running before cleaning up the workspace.
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
.
returndata = ActualRate*duration*(AIVoice.TriggerRepeat + 1); start(AIVoice) [d,t] = getdata(AIVoice,returndata);
plot(t,d) xlabel('Time (sec.)') ylabel('Signal Level (Volts)') title('Voice Activation for Both Triggers') grid on
The multiple-trigger data is shown below.
You can find the relative trigger times by searching for NaN
s 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? | ![]() |