4#include <AH/STL/type_traits>
26template <u
int8_t NB, u
int8_t NA,
class T>
48 for (uint8_t i = 0; i < 2 * NB - 1; ++i)
50 for (uint8_t i = 0; i < 2 *
MA - 1; ++i)
75 for (uint8_t i = 0; i < NB; i++)
76 acc +=
x[i] * b_coeff_shift[i];
79 for (uint8_t i = 0; i <
MA; i++)
80 acc -=
y[i] * a_coeff_shift[i];
99 constexpr static uint8_t
MA = NA - 1;
101 AH::Array<T, NB>
x = {};
102 AH::Array<T, MA>
y = {};
126template <u
int8_t NB, u
int8_t NA,
class T>
148 for (uint8_t i = 0; i < 2 * NB - 1; ++i)
149 this->b_coefficients[i] =
151 for (uint8_t i = 0; i < 2 *
MA - 1; ++i)
152 this->a_coefficients[i] =
177 for (uint8_t i = 0; i < NB; i++)
178 acc +=
x[i] * b_coeff_shift[i];
181 for (uint8_t i = 0; i <
MA; i++)
182 acc -=
y[i] * a_coeff_shift[i];
200 constexpr static uint8_t
MA = NA - 1;
202 AH::Array<T, NB>
x = {};
203 AH::Array<T, MA>
y = {};
212template <u
int8_t NB, u
int8_t NA,
class T>
214 typename std::conditional<std::is_floating_point<T>::value,
235template <u
int8_t NB, u
int8_t NA = NB,
class T =
float>
255 const AH::Array<T, NA> &a_coefficients)
275template <
size_t NB,
size_t NA,
class T =
float>
281template <
size_t NB,
size_t NA,
class T =
float>
283 const AH::Array<T, NA> &a_coefficients) {
284 return {b_coefficients, a_coefficients};
typename std::conditional< std::is_floating_point< T >::value, NormalizingIIRFilter< NB, NA, T >, NonNormalizingIIRFilter< NB, NA, T > >::type IIRImplementation
Select the NormalizingIIRFilter implementation if T is a floating point type, NonNormalizingIIRFilter...
Generic Infinite Impulse Response filter class.
T operator()(T input)
Update the internal state with the new input and return the new output .
IIRFilter(const AH::Array< T, NB > &b_coefficients, const AH::Array< T, NA > &a_coefficients)
Construct a new IIR Filter object.
IIRFilter(const TransferFunction< NB, NA, T > &tf)
Infinite Impulse Response filter implementation that does not normalize the coefficients upon initial...
AH::Array< T, 2 *NB - 1 > b_coefficients
Numerator coefficients.
AH::Array< T, NB > x
Previous inputs.
T operator()(T input)
Update the internal state with the new input and return the new output .
NonNormalizingIIRFilter(const TransferFunction< NB, NA, T > &tf)
AH::Array< T, MA > y
Previous outputs.
static constexpr uint8_t MA
NonNormalizingIIRFilter(const AH::Array< T, NB > &b_coefficients, const AH::Array< T, NA > &a_coefficients)
Construct a new Non-Normalizing IIR Filter object.
AH::Array< T, 2 *MA - 1 > a_coefficients
Denominator coefficients.
Infinite Impulse Response filter implementation that normalizes the coefficients upon initialization.
NormalizingIIRFilter(const AH::Array< T, NB > &b_coefficients, const AH::Array< T, NA > &a_coefficients)
Construct a new Normalizing IIR Filter object.
AH::Array< T, 2 *NB - 1 > b_coefficients
T operator()(T input)
Update the internal state with the new input and return the new output .
static constexpr uint8_t MA
NormalizingIIRFilter(const TransferFunction< NB, NA, T > &tf)
AH::Array< T, 2 *MA - 1 > a_coefficients
IIRFilter< NB, NA, T > makeIIRFilter(const TransferFunction< NB, NA, T > &tf)
Create an IIRFilter from the given transfer function.
Class for transfer function coefficients.