XTOS / OPEN SOURCE REAL-TIME SYSTEMOPEN SOURCE · VERSION 0.9.0 · BUILD FROM SOURCE
libxtos-signalxtos_signal_p300_feature

xtos_signal_p300_feature

Computes a centered positive peak, z score, energy, and relative latency from a prestimulus baseline and millisecond window.

On this page

Declaration

c
#include <xtos/signal.h>

int xtos_signal_p300_feature(const double *input,
                             size_t n,
                             uint32_t sample_rate_hz,
                             size_t baseline_samples,
                             uint32_t window_start_ms,
                             uint32_t window_end_ms,
                             double detection_z_threshold,
                             struct xtos_p300_feature *result);

Parameters

ParameterTypeDescription
inputconst double *Non-NULL array with at least n entries; the function does not modify it.
nsize_tSample count; it need not be a power of two.
sample_rate_hzuint32_tSampling rate in Hz, greater than zero.
baseline_samplessize_tPrestimulus baseline length, with 2≤baseline_samples<n.
window_start_msuint32_tWindow start after stimulus onset in milliseconds, less than the end value.
window_end_msuint32_tWindow end after stimulus onset in milliseconds; the end point is exclusive.
detection_z_thresholddoubleFinite positive detection threshold.
resultstruct xtos_p300_feature *Non-NULL caller-provided output structure.

Output fields

FieldTypeMeaning
baseline_meandoubleMean of baseline samples, in the same unit as input.
baseline_stddevdoublePopulation standard deviation of the baseline, in the same unit as input.
peak_amplitudedoubleMaximum positive baseline-centered amplitude in the window, in the same unit as input.
peak_latency_msdoublePeak latency relative to stimulus onset, in milliseconds.
peak_z_scoredoubleZ score peak_amplitude / baseline_stddev.
window_energydoubleSum of squared centered samples in the window, in squared input units.
peak_indexsize_tAbsolute input index of the peak sample.
detectedintWhether peak_z_score reaches detection_z_threshold; 1 when reached, otherwise 0.

Return value

Returns 0 and writes result on success; returns -1 on failure. detected only means peak_z_score reached the threshold.

Errors

errnoCondition
EINVALParameters or rounded window are invalid, or a checked baseline/window sample is NaN/Inf.
EDOMThe baseline standard deviation is zero or non-finite.

Notes

  • Milliseconds convert with (ms×fs+500)/1000; the peak is the greatest positive centered value in the window, keeping the earliest tie.
  • The implementation checks finite values in the baseline and window; samples outside those ranges are not checked.
  • The caller owns result and no heap is allocated; this is a research feature, not a diagnostic or calibration conclusion.

Example

Source

This reference describes headers and implementation at OpenXTOS commit dd313955ad57542bcd2af8827157d1bbd0cf5e83.