xtos_ signal_ p300_ quality_ gate
Validates P300 trial fields and summarizes detection rate, mean z, latency deviation, and passed.
On this page
Declaration
#include <xtos/signal.h>
int xtos_signal_p300_quality_gate(const struct xtos_p300_feature *trials,
size_t trial_count,
size_t min_valid_trials,
double min_detection_rate,
double min_mean_z_score,
double max_latency_stddev_ms,
struct xtos_p300_quality *result);Parameters
| Parameter | Type | Description |
|---|---|---|
| trials | const struct xtos_p300_feature * | Non-NULL trial array with at least trial_count entries. |
| trial_count | size_t | Number of trials, greater than zero. |
| min_valid_trials | size_t | Minimum valid trials required to pass, greater than zero. |
| min_detection_rate | double | Finite threshold in [0,1]. |
| min_mean_z_score | double | Finite lower bound for mean z score; negative values are allowed. |
| max_latency_stddev_ms | double | Finite nonnegative latency standard-deviation limit in milliseconds. |
| result | struct xtos_p300_quality * | Non-NULL caller-provided output structure. |
Output fields
| Field | Type | Meaning |
|---|---|---|
| trials_total | size_t | Total number of input trials. |
| trials_valid | size_t | Number of trials that pass field-consistency checks. |
| trials_detected | size_t | Number of valid trials whose detected flag is 1. |
| trials_rejected | size_t | Number of trials rejected by validity checks. |
| detection_rate | double | trials_detected / trials_valid; 0 when there are no valid trials. |
| mean_peak_z_score | double | Mean peak_z_score across valid trials. |
| mean_peak_latency_ms | double | Mean peak latency across valid trials, in milliseconds. |
| peak_latency_stddev_ms | double | Population standard deviation of valid-trial latency, in milliseconds. |
| passed | int | Whether all gate conditions pass; 1 when passed, otherwise 0. |
Return value
Returns 0 when arguments are valid and statistics complete, even when passed=0; returns -1 for invalid arguments.
Errors
| errno | Condition |
|---|---|
| EINVAL | trials or result is NULL, a count is zero, min_detection_rate is outside [0,1], any threshold is non-finite, or max_latency_stddev_ms is negative. |
Notes
- Each trial is checked for finite fields, stddev, z consistency with amplitude/stddev, energy lower bound, and detected=0/1; any rejected trial makes passed=0.
- Statistics use population latency standard deviation among valid trials; with no valid trial the function still returns 0 with passed=0.
- The function allocates no memory and does not modify trials; the caller owns result.
Example
Source
This reference describes headers and implementation at OpenXTOS commit dd313955ad57542bcd2af8827157d1bbd0cf5e83.