APM:Libraries
Butter.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <AP_HAL/AP_HAL.h>
4 
5 template <typename Coefficients>
6 class Butter2
7 {
8 public:
9  float filter(float input)
10  {
11  float newhist = input + Coefficients::A1*hist[1] + Coefficients::A2*hist[0];
12  float ret = (newhist + 2*hist[1] + hist[0])/Coefficients::GAIN;
13  hist[0] = hist[1]; hist[1] = newhist;
14  return ret;
15  }
16 private:
17  float hist[2];
18 };
19 
21 {
22  static constexpr float A1 = 1.9777864838f;
23  static constexpr float A2 = -0.9780305085f;
24  static constexpr float GAIN = 1.639178228e+04f;
25 };
26 typedef Butter2<butter100_025_coeffs> butter100hz0_25; //100hz sample, 0.25hz fcut
27 typedef Butter2<butter100_025_coeffs> butter50hz0_125; //50hz sample, 0.125hz fcut
28 typedef Butter2<butter100_025_coeffs> butter10hz0_025; //10hz sample, 0.025hz fcut
29 
31 {
32  static constexpr float A1 = 1.9555782403f;
33  static constexpr float A2 = -0.9565436765f;
34  static constexpr float GAIN = 4.143204922e+03f;
35 };
36 typedef Butter2<butter100_05_coeffs> butter100hz0_5; //100hz sample, 0.5hz fcut
37 typedef Butter2<butter100_05_coeffs> butter50hz0_25; //50hz sample, 0.25hz fcut
38 typedef Butter2<butter100_05_coeffs> butter10hz0_05; //10hz sample, 0.05hz fcut
39 
41 {
42  static constexpr float A1 = 1.9111970674f;
43  static constexpr float A2 = -0.9149758348f;
44  static constexpr float GAIN = 1.058546241e+03f;
45 };
46 typedef Butter2<butter100_1_coeffs> butter100hz1_0; //100hz sample, 1hz fcut
47 typedef Butter2<butter100_1_coeffs> butter50hz0_5; //50hz sample, 0.5hz fcut
48 typedef Butter2<butter100_1_coeffs> butter10hz0_1; //10hz sample, 0.1hz fcut
49 
51 {
52  static constexpr float A1 = 1.8668922797f;
53  static constexpr float A2 = -0.8752145483f;
54  static constexpr float GAIN = 4.806381793e+02f;
55 };
56 typedef Butter2<butter100_1_5_coeffs> butter100hz1_5; //100hz sample, 1.5hz fcut
57 typedef Butter2<butter100_1_5_coeffs> butter50hz0_75; //50hz sample, 0.75hz fcut
58 typedef Butter2<butter100_1_5_coeffs> butter10hz0_15; //10hz sample, 0.15hz fcut
59 
61 {
62  static constexpr float A1 = 1.8226949252f;
63  static constexpr float A2 = -0.8371816513f;
64  static constexpr float GAIN = 2.761148367e+02f;
65 };
66 typedef Butter2<butter100_2_coeffs> butter100hz2_0; //100hz sample, 2hz fcut
67 typedef Butter2<butter100_2_coeffs> butter50hz1_0; //50hz sample, 1hz fcut
68 typedef Butter2<butter100_2_coeffs> butter10hz0_2; //10hz sample, 0.2hz fcut
69 
71 {
72  static constexpr float A1 = 1.7347257688f;
73  static constexpr float A2 = -0.7660066009f;
74  static constexpr float GAIN = 1.278738361e+02f;
75 };
76 typedef Butter2<butter100_3_coeffs> butter100hz3_0; //100hz sample, 3hz fcut
77 typedef Butter2<butter100_3_coeffs> butter50hz1_5; //50hz sample, 1.5hz fcut
78 typedef Butter2<butter100_3_coeffs> butter10hz0_3; //10hz sample, 0.3hz fcut
79 
81 {
82  static constexpr float A1 = 1.6474599811f;
83  static constexpr float A2 = -0.7008967812f;
84  static constexpr float GAIN = 7.485478157e+01f;
85 };
86 typedef Butter2<butter100_4_coeffs> butter100hz4_0; //100hz sample, 4hz fcut
87 typedef Butter2<butter100_4_coeffs> butter50hz2_0; //50hz sample, 2hz fcut
88 typedef Butter2<butter100_4_coeffs> butter10hz0_4; //10hz sample, .4hz fcut
89 
91 {
92  static constexpr float A1 = 1.3072850288f;
93  static constexpr float A2 = -0.4918122372f;
94  static constexpr float GAIN = 2.167702007e+01f;
95 };
96 typedef Butter2<butter100_8_coeffs> butter100hz8_0; //100hz sample, 8hz fcut
97 typedef Butter2<butter100_8_coeffs> butter50hz4_0; //50hz sample, 4hz fcut
98 typedef Butter2<butter100_8_coeffs> butter10hz0_8; //10hz sample, .8hz fcut
99 
101 {
102  static constexpr float A1 = 0.6710290908f;
103  static constexpr float A2 = -0.2523246263f;
104  static constexpr float GAIN = 6.881181354e+00f;
105 };
106 typedef Butter2<butter50_8_coeffs> butter50hz8_0; //50hz sample, 8hz fcut
107 typedef Butter2<butter50_8_coeffs> butter10hz1_6; //10hz sample, 1.6hz fcut
Butter2< butter100_8_coeffs > butter50hz4_0
Definition: Butter.h:97
Butter2< butter100_025_coeffs > butter50hz0_125
Definition: Butter.h:27
Butter2< butter100_1_coeffs > butter50hz0_5
Definition: Butter.h:47
Butter2< butter100_2_coeffs > butter50hz1_0
Definition: Butter.h:67
Butter2< butter100_8_coeffs > butter10hz0_8
Definition: Butter.h:98
Butter2< butter100_3_coeffs > butter10hz0_3
Definition: Butter.h:78
Butter2< butter50_8_coeffs > butter50hz8_0
Definition: Butter.h:106
Butter2< butter100_3_coeffs > butter100hz3_0
Definition: Butter.h:76
Butter2< butter100_1_5_coeffs > butter100hz1_5
Definition: Butter.h:56
Butter2< butter100_1_coeffs > butter10hz0_1
Definition: Butter.h:48
Butter2< butter100_1_5_coeffs > butter50hz0_75
Definition: Butter.h:57
Butter2< butter100_8_coeffs > butter100hz8_0
Definition: Butter.h:96
#define constexpr
Definition: AP_HAL_Macros.h:16
Butter2< butter100_4_coeffs > butter100hz4_0
Definition: Butter.h:86
#define f(i)
Definition: Butter.h:6
Butter2< butter100_3_coeffs > butter50hz1_5
Definition: Butter.h:77
Butter2< butter100_2_coeffs > butter100hz2_0
Definition: Butter.h:66
Butter2< butter100_05_coeffs > butter100hz0_5
Definition: Butter.h:36
Butter2< butter100_4_coeffs > butter50hz2_0
Definition: Butter.h:87
Butter2< butter100_025_coeffs > butter100hz0_25
Definition: Butter.h:26
float hist[2]
Definition: Butter.h:17
Butter2< butter100_2_coeffs > butter10hz0_2
Definition: Butter.h:68
Butter2< butter100_1_5_coeffs > butter10hz0_15
Definition: Butter.h:58
Butter2< butter100_05_coeffs > butter50hz0_25
Definition: Butter.h:37
Butter2< butter100_1_coeffs > butter100hz1_0
Definition: Butter.h:46
Butter2< butter100_05_coeffs > butter10hz0_05
Definition: Butter.h:38
float filter(float input)
Definition: Butter.h:9
Butter2< butter100_025_coeffs > butter10hz0_025
Definition: Butter.h:28
Butter2< butter50_8_coeffs > butter10hz1_6
Definition: Butter.h:107
Butter2< butter100_4_coeffs > butter10hz0_4
Definition: Butter.h:88