9#include <AH/STL/limits>
10#include <AH/STL/type_traits>
56 class input_t = uint_fast16_t,
57 class state_t =
typename std::make_unsigned<input_t>::type>
61 EMA(input_t initial = input_t(0))
62 :
state(
zero + (state_t(initial) << K) - initial) {}
70 void reset(input_t value = input_t(0)) {
71 state =
zero + (state_t(value) << K) - value;
82 state += state_t(input);
86 return input_t(output);
94 constexpr static state_t
98 half = K > 0 ? state_t(1) << (K - 1) : state_t(0);
100 static_assert(std::is_unsigned<state_t>::value,
101 "state type should be unsigned");
104 "state type cannot be narrower than input type");
122 using sstate_t =
typename std::make_signed<state_t>::type;
126 (std::is_unsigned<input_t>::value
#define AH_DIAGNOSTIC_POP()
#define AH_DIAGNOSTIC_WERROR()
A class for single-pole infinite impulse response filters or exponential moving average filters.
float operator()(float value)
Filter the input: Given , calculate .
float filter(float value)
Filter the input: Given , calculate .
EMA_f(float pole)
Create an exponential moving average filter with a pole at the given location.
Exponential moving average filter.
static constexpr state_t half
void reset(input_t value=input_t(0))
Reset the filter to the given value.
static constexpr bool supports_range(T min, T max)
Verify the input range to make sure it's compatible with the shift factor and the width of the state ...
input_t filter(input_t input)
Filter the input: Given , calculate .
EMA(input_t initial=input_t(0))
Constructor: initialize filter to zero or optional given value.
static constexpr state_t max_state
static constexpr state_t half_state
input_t operator()(input_t input)
Filter the input: Given , calculate .
static constexpr state_t zero
constexpr auto min(const T &a, const U &b) -> decltype(b< a ? b :a)
Return the smaller of two numbers/objects.
constexpr auto max(const T &a, const U &b) -> decltype(a< b ? b :a)
Return the larger of two numbers/objects.