ncrar_audio.triggers module#

extract_triggers(x, threshold=None, group_window=10, fs=None)#

Extract and group triggers generated by the trigger interface of subclasses of SoundDevice that support including triggers (e.g., Babyface).

Parameters:
  • x (array) – The waveform of the trigger channel (e.g., Erg2 in the Biosemi BDF file).

  • threshold ({None, float}) – Threshold used to detect triggers. The trigger times will be the point at which the leading edge of the trigger crosses threshold. If None, will automatically be set to 20% of the maximum value in the signal.

  • group_window (float) – Group triggers occuring within window of the previous trigger. The timestamp for the set of triggers is the timestamp of the first trigger in the train. If fs is not None, group_window should be in seconds. If fs is None, group_window should be in units of samples.

  • fs ({None, float}) – Sampling rate of x.

Returns:

trigger_times – Grouped trigger times. Dictionary keys are the number of triggers in each group and values are a list of times where that trigger group was detected. The reported times are the time of the first trigger in the group. Trigger times will be in units of seconds when fs is provided, samples otherwise.

Return type:

dict

group_triggers(x, window=10)#

Group triggers if they fall within window of the previous trigger.

Parameters:
  • x (array) – Array of timestamps (e.g., in units of sample number or seconds).

  • window (float) – Group triggers occuring within window of the previous trigger. The timestamp for the set of triggers is the timestamp of the first trigger in the train.

Returns:

trigger_times – Grouped trigger times. Dictionary keys are the number of triggers in each group and values are a list of times where that trigger group was detected. The reported times are the time of the first trigger in the group.

Return type:

dict

Note

The units of window and trigger_times are the same units of x (e.g., if x is specified as trigger timestamps in seconds, then window would be seconds; if x is specified as trigger timestamps in samples, then window would be number of samples).

make_trigger(fs, n, shape='square', shape_settings=None)#