From 438b0abc7a4378e28d69b9a4867c705b4d0e70b1 Mon Sep 17 00:00:00 2001 From: Daniel Agar Date: Mon, 31 May 2021 10:34:45 -0400 Subject: [PATCH] mathlib: Biquad filters use internal fields for parameter update --- src/lib/mathlib/math/filter/LowPassFilter2p.hpp | 2 +- src/lib/mathlib/math/filter/NotchFilter.hpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/mathlib/math/filter/LowPassFilter2p.hpp b/src/lib/mathlib/math/filter/LowPassFilter2p.hpp index 2ecc17f652..fd3a531e03 100644 --- a/src/lib/mathlib/math/filter/LowPassFilter2p.hpp +++ b/src/lib/mathlib/math/filter/LowPassFilter2p.hpp @@ -72,7 +72,7 @@ public: _cutoff_freq = math::constrain(cutoff_freq, 5.f, sample_freq / 2); // TODO: min based on actual numerical limit _sample_freq = sample_freq; - const float fr = sample_freq / _cutoff_freq; + const float fr = _sample_freq / _cutoff_freq; const float ohm = tanf(M_PI_F / fr); const float c = 1.f + 2.f * cosf(M_PI_F / 4.f) * ohm + ohm * ohm; diff --git a/src/lib/mathlib/math/filter/NotchFilter.hpp b/src/lib/mathlib/math/filter/NotchFilter.hpp index 0049022a72..5bf99a7119 100644 --- a/src/lib/mathlib/math/filter/NotchFilter.hpp +++ b/src/lib/mathlib/math/filter/NotchFilter.hpp @@ -201,8 +201,8 @@ void NotchFilter::setParameters(float sample_freq, float notch_freq, float ba _bandwidth = math::constrain(bandwidth, 5.f, sample_freq / 2); _sample_freq = sample_freq; - const float alpha = tanf(M_PI_F * bandwidth / sample_freq); - const float beta = -cosf(2.f * M_PI_F * notch_freq / sample_freq); + const float alpha = tanf(M_PI_F * _bandwidth / _sample_freq); + const float beta = -cosf(2.f * M_PI_F * _notch_freq / _sample_freq); const float a0_inv = 1.f / (alpha + 1.f); _b0 = a0_inv;