MovingAverageThreshold Filter

template<typename T, size_t N, T Threshold>
struct MovingAverageThreshold

Filter using moving average threshold.

This stateful filter maintains a moving average over a sliding window and propagates changes only when the average exceeds the specified threshold.

Since

v0.1.0

// Example: Moving average with window of 5, threshold of 50
Signal<float, 10, MovingAverageThreshold<float, 5, 50>> sensor(0.0);

Note

Stateful filter. Moving average over sliding window.

Warning

  • Only accepts arithmetic types (integral and floating-point).

  • Window size N must be greater than 0.

Template Parameters:
typename T

Arithmetic type.

size_t N

Window size for moving average.

T Threshold

Threshold value for acceptance.

Public Functions

inline bool operator()(const T &old_value, const T &new_value) const

Public Members

mutable T buffer[N] = {}
mutable size_t index = 0
mutable size_t count = 0
mutable T sum = 0

See Also