APM:Libraries
NotchFilter.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 /*
18  notch filter with settable sample rate, center frequency, bandwidth and attenuation
19 
20  Design by Leonard Hall
21  */
22 
23 #include <AP_Math/AP_Math.h>
24 #include <cmath>
25 #include <inttypes.h>
26 #include <AP_Param/AP_Param.h>
27 
28 
29 template <class T>
30 class NotchFilter {
31 public:
32  // set parameters
33  void init(float sample_freq_hz, float center_freq_hz, float bandwidth_hz, float attenuation_dB);
34  T apply(const T &sample);
35 
36 private:
38  float b0, b1, b2, a1, a2, a0_inv;
40 };
41 
42 /*
43  a notch filter with enable and filter parameters
44  */
46 public:
48  void init(float sample_freq_hz);
49  Vector3f apply(const Vector3f &sample);
50 
51  static const struct AP_Param::GroupInfo var_info[];
52 
53 private:
54  AP_Int8 enable;
55  AP_Float center_freq_hz;
56  AP_Float bandwidth_hz;
57  AP_Float attenuation_dB;
58 
60 
64 
66 };
67 
70 
void init(float sample_freq_hz, float center_freq_hz, float bandwidth_hz, float attenuation_dB)
Definition: NotchFilter.cpp:22
T apply(const T &sample)
Definition: NotchFilter.cpp:42
bool initialised
Definition: NotchFilter.h:37
A system for managing and storing variables that are of general interest to the system.
NotchFilter< float > NotchFilterFloat
Definition: NotchFilter.h:68
float a0_inv
Definition: NotchFilter.h:38
NotchFilter< Vector3f > NotchFilterVector3f
Definition: NotchFilter.h:69
NotchFilter< Vector3f > filter
Definition: NotchFilter.h:65