Complementary Filter 1.0
Complementary Filter for Real-Time Application
Loading...
Searching...
No Matches
cf.tpp
Go to the documentation of this file.
1#include "cf.h"
2
3template <typename T>
5{
6}
7
8template <typename T>
10{
11}
12
13template <typename T>
14void estimators::cf::CF<T>::init(T fc_, T dt_)
15{
16 set_param(fc_, dt_);
17}
18
19template <typename T>
20void estimators::cf::CF<T>::set_param(T fc_, T dt_)
21{
22 fc = fc_;
23 dt = dt_;
24 tau = 1.0 / (6.28318530717958647692528676655900576 * fc);
25 alpha = dt / (dt + tau);
26}
27
28template <typename T>
29T estimators::cf::CF<T>::update(T x1_i, T x2_i)
30{
31 return alpha * x1_i + (1.0 - alpha) * x2_i;
32}
33
34template <typename T>
36{
37}
38
39template <typename T>
41{
42 set_param(fc_, dt);
43}
44
45template <typename T>
47{
48 tau = tau_;
49 fc = 1.0 / (6.28318530717958647692528676655900576 * tau);
50 alpha = dt / (dt + tau);
51}
52
53template <typename T>
55{
56 set_param(fc, dt_);
57}
58
59template <typename T>
61{
62 alpha = alpha_;
63 tau = ((1.0 - alpha) * dt) / alpha;
64 fc = 1.0 / (6.28318530717958647692528676655900576 * tau);
65}
66
67template <typename T>
69{
70 return fc;
71}
72
73template <typename T>
75{
76 return tau;
77}
78
79template <typename T>
81{
82 return dt;
83}
84
85template <typename T>
87{
88 return alpha;
89}
Declaration of the complementary filter class.
T update(T x1_i, T x2_i)
Updates the complementary filter with new measurements.
Definition cf.h:30
void init(T fc_, T dt_)
Initializes the complementary filter.
Definition cf.h:15
void set_fc(T fc_)
Sets the cutoff frequency.
Definition cf.h:41
void set_param(T fc_, T dt_)
Sets the filter parameters.
Definition cf.h:21
~CF()
Destroys the complementary filter.
Definition cf.h:10
void set_alpha(T alpha_)
Sets the complementary filter coefficient.
Definition cf.h:61
void reset()
Resets the filter state.
Definition cf.h:36
void set_dt(T dt_)
Sets the sampling time.
Definition cf.h:55
CF()
Constructs a complementary filter.
Definition cf.h:5
T get_tau()
Gets the filter time constant.
Definition cf.h:75
T get_dt()
Gets the sampling time.
Definition cf.h:81
T get_alpha()
Gets the complementary filter coefficient.
Definition cf.h:87
void set_tau(T tau_)
Sets the filter time constant.
Definition cf.h:47
T get_fc()
Gets the cutoff frequency.
Definition cf.h:69