From b165e025d964ca71df4a8764ed8132673bc0c510 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 21 Nov 2016 16:48:10 +1100 Subject: [PATCH] Filter: added new constructor for 1p filter allow both sample rate and cutoff to be specified in constructor --- libraries/Filter/LowPassFilter.cpp | 18 ++++++++++++------ libraries/Filter/LowPassFilter.h | 1 + 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/libraries/Filter/LowPassFilter.cpp b/libraries/Filter/LowPassFilter.cpp index be14b7148b..282ca5a3bf 100644 --- a/libraries/Filter/LowPassFilter.cpp +++ b/libraries/Filter/LowPassFilter.cpp @@ -61,14 +61,20 @@ void DigitalLPF::reset(T value) { //////////////////////////////////////////////////////////////////////////////////////////// // LowPassFilter //////////////////////////////////////////////////////////////////////////////////////////// + +// constructors template -LowPassFilter::LowPassFilter() : _cutoff_freq(0.0f) { - -} -// constructor +LowPassFilter::LowPassFilter() : + _cutoff_freq(0.0f) {} + template -LowPassFilter::LowPassFilter(float cutoff_freq) : _cutoff_freq(cutoff_freq) { - +LowPassFilter::LowPassFilter(float cutoff_freq) : + _cutoff_freq(cutoff_freq) {} + +template +LowPassFilter::LowPassFilter(float sample_freq, float cutoff_freq) +{ + set_cutoff_frequency(sample_freq, cutoff_freq); } // change parameters diff --git a/libraries/Filter/LowPassFilter.h b/libraries/Filter/LowPassFilter.h index 6781e28b67..1ff19a3875 100644 --- a/libraries/Filter/LowPassFilter.h +++ b/libraries/Filter/LowPassFilter.h @@ -73,6 +73,7 @@ class LowPassFilter { public: LowPassFilter(); LowPassFilter(float cutoff_freq); + LowPassFilter(float sample_freq, float cutoff_freq); // change parameters void set_cutoff_frequency(float cutoff_freq);