Filters 1.0
LPF, HPF, BPF, BSF, SRL
Loading...
Searching...
No Matches
lpf_1.tpp
Go to the documentation of this file.
2
3template <typename T>
5{
6 reset();
7}
8
9template <typename T>
11{
12 set_param(fc_, dt_);
13}
14
15template <typename T>
17{
18 fc = fc_;
19 dt = dt_;
20 tau = 1.0 / (6.28318530717958647692528676655900576 * fc);
21 alpha = dt / (dt + tau);
22}
23
24template <typename T>
26{
27 T y_k = 0.0;
28
29 if (start == false)
30 {
31 start = true;
32 y_k = x_k;
33 }
34 else
35 {
36 y_k = alpha * x_k + (1.0 - alpha) * y_k_1;
37 }
38 y_k_1 = y_k;
39 return y_k;
40}
41
42template <typename T>
44{
45 y_k_1 = 0.0;
46 start = false;
47}
48
49template <typename T>
51{
52 set_param(fc_, dt);
53}
54
55template <typename T>
57{
58 tau = tau_;
59 fc = 1.0 / (6.28318530717958647692528676655900576 * tau);
60 alpha = dt / (dt + tau);
61}
62
63template <typename T>
65{
66 set_param(fc, dt_);
67}
68
69template <typename T>
71{
72 alpha = alpha_;
73 tau = ((1.0 - alpha) * dt) / alpha;
74 fc = 1.0 / (6.28318530717958647692528676655900576 * tau);
75}
76
77template <typename T>
79{
80 return fc;
81}
82
83template <typename T>
85{
86 return tau;
87}
88
89template <typename T>
91{
92 return dt;
93}
94
95template <typename T>
97{
98 return alpha;
99}
100
101template <typename T>
103{
104 return 1.0 / dt;
105}
T update(T x_k)
Processes a new input sample.
Definition lpf_1.h:26
void set_dt(T dt_)
Sets the sampling time.
Definition lpf_1.h:65
void set_param(T fc_, T dt_)
Sets the filter parameters.
Definition lpf_1.h:17
LPF_1()
Constructs a first-order low-pass filter.
Definition lpf_1.h:5
void reset()
Resets the filter state.
Definition lpf_1.h:44
T get_fc()
Gets the cutoff frequency.
Definition lpf_1.h:79
void set_tau(T tau_)
Sets the filter time constant.
Definition lpf_1.h:57
T get_dt()
Gets the sampling time.
Definition lpf_1.h:91
void config(T fc_, T dt_)
Configures the low-pass filter.
Definition lpf_1.h:11
T get_tau()
Gets the filter time constant.
Definition lpf_1.h:85
void set_fc(T fc_)
Sets the cutoff frequency.
Definition lpf_1.h:51
T get_alpha()
Gets the filter coefficient.
Definition lpf_1.h:97
void set_alpha(T alpha_)
Sets the filter coefficient.
Definition lpf_1.h:71
T get_fs()
Gets the sampling frequency.
Definition lpf_1.h:103
First-order low-pass filter.