Data Acquisition Toolbox | ![]() ![]() |
Trigger Delays
Trigger delays allow you to control exactly when data is logged after a trigger occurs. You can log data either before the trigger or after the trigger. Logging data before the trigger occurs is called pretriggering, while logging data after a trigger occurs is called posttriggering.
You configure trigger delays with the TriggerDelay
property. Pretriggers are specified by a negative TriggerDelay
value, while posttriggers are specified by a positive TriggerDelay
value. You can delay data logging in time or in samples using the TriggerDelayUnits
property. When TriggerDelayUnits
is set to Samples
, data logging is delayed by the specified number of samples. When the TriggerDelayUnits
property is set to Seconds
, data logging is delayed by the specified number of seconds.
Capturing Pretrigger Data
In some circumstances, you might want to capture data before the trigger occurs. Such data is called pretrigger data. When capturing pretrigger data, the SamplesPerTrigger
property value includes the data captured before and after the trigger occurs. Capturing pretrigger data is illustrated below.
You can capture pretrigger data for manual triggers and software triggers. If TriggerType
is Manual
, and the trigger
function is issued before the trigger delay passes, then a warning is returned and the trigger is ignored (the trigger event does not occur).
You cannot capture pretrigger data for immediate triggers or device-specific hardware triggers.
Note Pretrigger data has negative relative time values associated with it. This is because time = 0 corresponds to the time the trigger event occurs and data logging is initiated. |
Capturing Posttrigger Data
In some circumstances, you might want to capture data after the trigger occurs. Such data is called posttrigger data. When capturing posttrigger data, the SamplesPerTrigger
property value and the number of posttrigger samples are equal. Capturing posttrigger data is illustrated below.
You can capture posttrigger data using any supported trigger type.
Example: Voice Activation and Pretriggers
This example modifies daqdoc5_3
such that 500 pretrigger samples are acquired. You can run this example by typing daqdoc5_4
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, 500 pretrigger samples are collected.
duration = 2; % two second acquisition set(AIVoice,'SampleRate',44100) ActualRate = get(AIVoice,'SampleRate'); set(AIVoice,'SamplesPerTrigger',ActualRate*duration) set(AIVoice,'TriggerChannel',chan) set(AIVoice,'TriggerType','Software') set(AIVoice,'TriggerCondition','Rising') set(AIVoice,'TriggerConditionValue',0.2) set(AIVoice,'TriggerDelayUnits','Samples') set(AIVoice,'TriggerDelay',-500)
AIVoice
, acquire the specified number of samples, and extract the first 1000 samples from the engine as sample-time pairs.
Make sure AIVoice
has stopped running before cleaning up the workspace.
AIVoice
, you should remove it from memory and from the MATLAB workspace.
The output from this example is shown below. Note that the pretrigger data constitutes half of the 1000 samples extracted from the engine. Additionally, pretrigger data has negative time associated with it because time = 0 corresponds to the time the trigger event occurs and data logging is initiated.
![]() | Executing the Trigger | Repeating Triggers | ![]() |