xtos_ signal_ ssvep_ feature
Sums rounded-bin harmonic power and neighboring noise, then computes SNR and dB.
On this page
Declaration
#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
| Parameter | Type | Description |
|---|---|---|
| input | const double * | Non-NULL input with at least n doubles; it is not modified, but NaN/Inf are not checked. |
| n | size_t | A nonzero power of two used as the internal DFT length. |
| sample_rate_hz | uint32_t | Sampling rate in Hz, greater than zero. |
| target_frequency_hz | double | Target frequency in Hz, in (0, fs/2); finite is not explicitly checked. |
| harmonic_count | size_t | Number of target harmonics, greater than zero, with the highest harmonic bin in range. |
| neighbor_bins | size_t | Neighbor bins on each side, greater than zero. |
| result | struct xtos_ssvep_feature * | Non-NULL caller-provided output structure. |
Output fields
| Field | Type | Meaning |
|---|---|---|
| signal_power | double | Sum of squared-magnitude power at target harmonic bins, without automatic normalization. |
| noise_power | double | Average power of valid neighboring bins. |
| snr | double | Linear signal-to-noise ratio, signal_power / noise_power. |
| snr_db | double | Signal-to-noise ratio 10×log10(snr), in dB. |
| target_bin | size_t | Rounded target-frequency bin index. |
| harmonics_used | size_t | Number 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
| errno | Condition |
|---|---|
| EINVAL | A 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. |
| ENOMEM | Allocation of the internal power or FFT temporary arrays failed. |
| EDOM | There 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.