13#error "This header is C++-only."
37 static_assert(std::is_integral<Scalar>::value,
38 "Filter is designed only for integral values. Use the other one for floats.");
51 : state(val), alpha(alpha_.withNonNegativeDenominator())
53 if (!alpha.isBetweenZeroAndOne()) {
54 throw std::invalid_argument(
"Alpha must be between zero and one.");
62 reset(Value
const &val)
noexcept
88 Value scaledStateNumerator = oneMinusWeightedAlpha.numerator * state;
89 Value scaledSampleNumerator = weightedAlpha.numerator * sample;
92 state = (scaledStateNumerator + scaledSampleNumerator) / weightedAlpha.denominator;
97 bool initialized{
false};
120 assert(alpha.isBetweenZeroAndOne());
162 return impl_.initialized;
A very simple integer low-pass filter, using a "one-pole infinite impulse response" design (one-pole ...
Definition: m_lowpass_integer.hpp:108
Scalar getState() const noexcept
Get the filtered value.
Definition: m_lowpass_integer.hpp:150
void reset() noexcept
Reset the filter to newly-created state.
Definition: m_lowpass_integer.hpp:127
IntegerLowPassIIRFilter(math::Rational< Scalar > alpha) noexcept
Constructor.
Definition: m_lowpass_integer.hpp:118
void addSample(Scalar sample, math::Rational< Scalar > weight=math::Rational< Scalar >::simplestUnity())
Filter a sample, with an optional weight.
Definition: m_lowpass_integer.hpp:141
bool isInitialized() const noexcept
Get whether we have initialized state.
Definition: m_lowpass_integer.hpp:160
Wrapper header for <math.h> to ensure pi-related math constants are defined.
A very simple rational number type.
C++-only functionality in the Math helper library.
Definition: m_documentation.hpp:15
A rational (fractional) number type.
Definition: m_rational.hpp:26
constexpr Rational complement() const noexcept
Get the complementary fraction.
Definition: m_rational.hpp:118
The shared implementation (between vector and scalar versions) of an integer IIR/exponential low-pass...
Definition: m_lowpass_integer.hpp:34
void addSample(Value const &sample, math::Rational< Scalar > weight=math::Rational< Scalar >::simplestUnity())
Filter a sample, with an optional weight.
Definition: m_lowpass_integer.hpp:77
IntegerLowPassIIR(math::Rational< Scalar > alpha_, Value const &val)
Constructor.
Definition: m_lowpass_integer.hpp:50
void reset(Value const &val) noexcept
Reset the filter to newly-created state.
Definition: m_lowpass_integer.hpp:62
Time-keeping: a clock that is steady, convertible to system time, and ideally high-resolution.