Skip to content

File syn_filter.h

FileList > dsp > syn_filter.h

Go to the source code of this file

Integer-only digital filters for sensor signal conditioning. More...

  • #include "../util/syn_qmath.h"
  • #include <stdbool.h>
  • #include <stddef.h>
  • #include <stdint.h>

Classes

Type Name
struct SYN_FilterEMA
Exponential moving average filter state.
struct SYN_FilterFIR
FIR filter state (Q16 fixed-point).
struct SYN_FilterMA
Moving average filter state.
struct SYN_FilterMedian
Median filter state.

Public Functions

Type Name
void syn_filter_ema_init (SYN_FilterEMA * f, uint8_t alpha)
Initialize an EMA filter.
void syn_filter_ema_reset (SYN_FilterEMA * f)
Reset the filter to its initial state.
int16_t syn_filter_ema_update (SYN_FilterEMA * f, int16_t sample)
Feed a new sample and get the filtered output.
void syn_filter_fir_init (SYN_FilterFIR * f, const q16_t * taps, q16_t * history, uint16_t num_taps)
Initialize an FIR filter.
void syn_filter_fir_reset (SYN_FilterFIR * f)
Reset FIR filter sample history to 0.
q16_t syn_filter_fir_update (SYN_FilterFIR * f, q16_t sample)
Feed a new Q16 sample and get the FIR filtered output.
void syn_filter_ma_init (SYN_FilterMA * f, uint8_t window)
Initialize a moving average filter.
void syn_filter_ma_reset (SYN_FilterMA * f)
Reset the filter to its initial state.
int16_t syn_filter_ma_update (SYN_FilterMA * f, int16_t sample)
Feed a new sample and get the filtered output.
void syn_filter_median_init (SYN_FilterMedian * f, uint8_t window)
Initialize a median filter.
void syn_filter_median_reset (SYN_FilterMedian * f)
Reset the filter to its initial state.
int16_t syn_filter_median_update (SYN_FilterMedian * f, int16_t sample)
Feed a new sample and get the filtered output.

Macros

Type Name
define SYN_FILTER_MAX_WINDOW 32

Detailed Description

All filters operate on int16_t values and use no floating-point math. Window backing buffers are caller-provided (no malloc).

** **

  • Moving Average (MA): Smooth noise, configurable window
  • Exponential Moving Average (EMA): Low-pass, single coefficient
  • Median: Impulse noise rejection, small windows only

Public Functions Documentation

function syn_filter_ema_init

Initialize an EMA filter.

void syn_filter_ema_init (
    SYN_FilterEMA * f,
    uint8_t alpha
) 

Parameters:

  • f Filter instance.
  • alpha Smoothing factor (0–255). Higher = more responsive. Equivalent to alpha = value/256. Example: 64 ≈ 0.25 (slow), 192 ≈ 0.75 (fast).

function syn_filter_ema_reset

Reset the filter to its initial state.

void syn_filter_ema_reset (
    SYN_FilterEMA * f
) 

Parameters:

  • f Filter instance.

function syn_filter_ema_update

Feed a new sample and get the filtered output.

int16_t syn_filter_ema_update (
    SYN_FilterEMA * f,
    int16_t sample
) 

Parameters:

  • f Filter instance.
  • sample New raw sample.

Returns:

Filtered value.


function syn_filter_fir_init

Initialize an FIR filter.

void syn_filter_fir_init (
    SYN_FilterFIR * f,
    const q16_t * taps,
    q16_t * history,
    uint16_t num_taps
) 

Parameters:

  • f Filter instance.
  • taps Array of Q16 filter coefficients.
  • history Caller-provided Q16 history buffer of size num_taps.
  • num_taps Number of filter taps.

function syn_filter_fir_reset

Reset FIR filter sample history to 0.

void syn_filter_fir_reset (
    SYN_FilterFIR * f
) 

Parameters:

  • f Filter instance.

function syn_filter_fir_update

Feed a new Q16 sample and get the FIR filtered output.

q16_t syn_filter_fir_update (
    SYN_FilterFIR * f,
    q16_t sample
) 

Parameters:

  • f Filter instance.
  • sample New Q16 sample.

Returns:

Filtered output in Q16.


function syn_filter_ma_init

Initialize a moving average filter.

void syn_filter_ma_init (
    SYN_FilterMA * f,
    uint8_t window
) 

Parameters:

  • f Filter instance.
  • window Window size (must be <= SYN_FILTER_MAX_WINDOW).

function syn_filter_ma_reset

Reset the filter to its initial state.

void syn_filter_ma_reset (
    SYN_FilterMA * f
) 

Parameters:

  • f Filter instance.

function syn_filter_ma_update

Feed a new sample and get the filtered output.

int16_t syn_filter_ma_update (
    SYN_FilterMA * f,
    int16_t sample
) 

Parameters:

  • f Filter instance.
  • sample New raw sample.

Returns:

Filtered value (average of the last window samples).


function syn_filter_median_init

Initialize a median filter.

void syn_filter_median_init (
    SYN_FilterMedian * f,
    uint8_t window
) 

Parameters:

  • f Filter instance.
  • window Window size (should be odd for a true median; must be <= SYN_FILTER_MAX_WINDOW).

function syn_filter_median_reset

Reset the filter to its initial state.

void syn_filter_median_reset (
    SYN_FilterMedian * f
) 

Parameters:

  • f Filter instance.

function syn_filter_median_update

Feed a new sample and get the filtered output.

int16_t syn_filter_median_update (
    SYN_FilterMedian * f,
    int16_t sample
) 

Parameters:

  • f Filter instance.
  • sample New raw sample.

Returns:

Median of the last window samples.


Macro Definition Documentation

define SYN_FILTER_MAX_WINDOW

#define SYN_FILTER_MAX_WINDOW `32`

Maximum window size for moving average and median filters.



The documentation for this class was generated from the following file src/syntropic/dsp/syn_filter.h