diff options
author | Andrew Tridgell <tridge@samba.org> | 2013-12-11 14:14:03 +1100 |
---|---|---|
committer | Lorenz Meier <lm@inf.ethz.ch> | 2013-12-13 11:19:08 +0100 |
commit | e808e015dd84c234f9689daf90aedf0162d7d2f2 (patch) | |
tree | 4357f9d76178303750e30aa7d7ef9247c1c86758 /src/lib/mathlib/math | |
parent | 17502cbde43cf96c55af1811723ce84ca2a1fc27 (diff) | |
download | px4-firmware-e808e015dd84c234f9689daf90aedf0162d7d2f2.tar.gz px4-firmware-e808e015dd84c234f9689daf90aedf0162d7d2f2.tar.bz2 px4-firmware-e808e015dd84c234f9689daf90aedf0162d7d2f2.zip |
LowPassFilter: allow for filtering to be disabled
using bandwidth of 0 gives no filtering
Diffstat (limited to 'src/lib/mathlib/math')
-rw-r--r-- | src/lib/mathlib/math/filter/LowPassFilter2p.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/lib/mathlib/math/filter/LowPassFilter2p.cpp b/src/lib/mathlib/math/filter/LowPassFilter2p.cpp index efb17225d..3699d9bce 100644 --- a/src/lib/mathlib/math/filter/LowPassFilter2p.cpp +++ b/src/lib/mathlib/math/filter/LowPassFilter2p.cpp @@ -46,6 +46,10 @@ namespace math void LowPassFilter2p::set_cutoff_frequency(float sample_freq, float cutoff_freq) { _cutoff_freq = cutoff_freq; + if (_cutoff_freq <= 0.0f) { + // no filtering + return; + } float fr = sample_freq/_cutoff_freq; float ohm = tanf(M_PI_F/fr); float c = 1.0f+2.0f*cosf(M_PI_F/4.0f)*ohm + ohm*ohm; @@ -58,6 +62,10 @@ void LowPassFilter2p::set_cutoff_frequency(float sample_freq, float cutoff_freq) float LowPassFilter2p::apply(float sample) { + if (_cutoff_freq <= 0.0f) { + // no filtering + return sample; + } // do the filtering float delay_element_0 = sample - _delay_element_1 * _a1 - _delay_element_2 * _a2; if (isnan(delay_element_0) || isinf(delay_element_0)) { |