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

xtos_signal_ssvep_feature

Sums rounded-bin harmonic power and neighboring noise, then computes SNR and dB.

On this page

Declaration

c
#include <xtos/signal.h>

int xtos_signal_ssvep_feature(const double *input,
                              size_t n,
                              uint32_t sample_rate_hz,
                              double target_frequency_hz,
                              size_t harmonic_count,
                              size_t neighbor_bins,
                              struct xtos_ssvep_feature *result);

Parameters

ParameterTypeDescription
inputconst double *Non-NULL input with at least n doubles; it is not modified, but NaN/Inf are not checked.
nsize_tA nonzero power of two used as the internal DFT length.
sample_rate_hzuint32_tSampling rate in Hz, greater than zero.
target_frequency_hzdoubleTarget frequency in Hz, in (0, fs/2); finite is not explicitly checked.
harmonic_countsize_tNumber of target harmonics, greater than zero, with the highest harmonic bin in range.
neighbor_binssize_tNeighbor bins on each side, greater than zero.
resultstruct xtos_ssvep_feature *Non-NULL caller-provided output structure.

Output fields

FieldTypeMeaning
signal_powerdoubleSum of squared-magnitude power at target harmonic bins, without automatic normalization.
noise_powerdoubleAverage power of valid neighboring bins.
snrdoubleLinear signal-to-noise ratio, signal_power / noise_power.
snr_dbdoubleSignal-to-noise ratio 10×log10(snr), in dB.
target_binsize_tRounded target-frequency bin index.
harmonics_usedsize_tNumber of target harmonics included in the accumulation.

Return value

Returns 0 and writes result on success; returns -1 on failure. signal_power sums target bins and noise_power averages valid neighbors.

Errors

errnoCondition
EINVALA pointer is NULL, n is not a power of two, frequency range is invalid, target bin is zero, or a harmonic bin is out of range.
ENOMEMAllocation of the internal power or FFT temporary arrays failed.
EDOMThere are no valid neighbors or noise power is not positive.

Notes

  • The implementation allocates heap memory for power and the FFT; it does not check input or target_frequency_hz NaN/Inf, so callers must validate first.
  • Overlapping neighborhoods may count a noise bin more than once; this is not CCA, stimulus identification, or artifact rejection.

Example

Source

This reference describes headers and implementation at OpenXTOS commit dd313955ad57542bcd2af8827157d1bbd0cf5e83.