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
#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
| Parameter | Type | Description |
|---|---|---|
| input | const double * | Non-NULL array with at least n entries; the function does not modify it. |
| n | size_t | Sample count; it need not be a power of two. |
| sample_rate_hz | uint32_t | Sampling rate in Hz, greater than zero. |
| baseline_samples | size_t | Prestimulus baseline length, with 2≤baseline_samples<n. |
| window_start_ms | uint32_t | Window start after stimulus onset in milliseconds, less than the end value. |
| window_end_ms | uint32_t | Window end after stimulus onset in milliseconds; the end point is exclusive. |
| detection_z_threshold | double | Finite positive detection threshold. |
| result | struct xtos_p300_feature * | Non-NULL caller-provided output structure. |
Output fields
| Field | Type | Meaning |
|---|---|---|
| baseline_mean | double | Mean of baseline samples, in the same unit as input. |
| baseline_stddev | double | Population standard deviation of the baseline, in the same unit as input. |
| peak_amplitude | double | Maximum positive baseline-centered amplitude in the window, in the same unit as input. |
| peak_latency_ms | double | Peak latency relative to stimulus onset, in milliseconds. |
| peak_z_score | double | Z score peak_amplitude / baseline_stddev. |
| window_energy | double | Sum of squared centered samples in the window, in squared input units. |
| peak_index | size_t | Absolute input index of the peak sample. |
| detected | int | Whether 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
| errno | Condition |
|---|---|
| EINVAL | Parameters or rounded window are invalid, or a checked baseline/window sample is NaN/Inf. |
| EDOM | The 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.