APM:Libraries
LowPassFilter2p.h
Go to the documentation of this file.
1 /*
2  This program is free software: you can redistribute it and/or modify
3  it under the terms of the GNU General Public License as published by
4  the Free Software Foundation, either version 3 of the License, or
5  (at your option) any later version.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program. If not, see <http://www.gnu.org/licenses/>.
14  */
15 #pragma once
16 
17 #include <AP_Math/AP_Math.h>
18 #include <cmath>
19 #include <inttypes.h>
20 
21 
25 template <class T>
27 public:
28  struct biquad_params {
29  float cutoff_freq;
30  float sample_freq;
31  float a1;
32  float a2;
33  float b0;
34  float b1;
35  float b2;
36  };
37 
39 
40  T apply(const T &sample, const struct biquad_params &params);
41  void reset();
42  static void compute_params(float sample_freq, float cutoff_freq, biquad_params &ret);
43 
44 private:
47 };
48 
49 template <class T>
51 public:
53  // constructor
55  // change parameters
56  void set_cutoff_frequency(float sample_freq, float cutoff_freq);
57  // return the cutoff frequency
58  float get_cutoff_freq(void) const;
59  float get_sample_freq(void) const;
60  T apply(const T &sample);
61  void reset(void);
62 
63 protected:
64  struct DigitalBiquadFilter<T>::biquad_params _params;
65 
66 private:
67  DigitalBiquadFilter<T> _filter;
68 };
69 
70 // Uncomment this, if you decide to remove the instantiations in the implementation file
71 /*
72 template <class T>
73 LowPassFilter2p<T>::LowPassFilter2p() {
74  memset(&_params, 0, sizeof(_params) );
75 }
76 
77 // constructor
78 template <class T>
79 LowPassFilter2p<T>::LowPassFilter2p(float sample_freq, float cutoff_freq) {
80  // set initial parameters
81  set_cutoff_frequency(sample_freq, cutoff_freq);
82 }
83 */
84 
T apply(const T &sample, const struct biquad_params &params)
static void compute_params(float sample_freq, float cutoff_freq, biquad_params &ret)