Filters 1.0
LPF, HPF, BPF, BSF, SRL
Loading...
Searching...
No Matches
hpf_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
21 tau = 1.0 / (6.28318530717958647692528676655900576 * fc);
22 alpha = tau / (dt + tau);
23}
24
25template <typename T>
27{
28 T y_k = 0.0;
29
30 if (start == false)
31 {
32 start = true;
33 y_k = x_k;
34 }
35 else
36 {
37 y_k = alpha * (y_k_1 + x_k - x_k_1);
38 }
39 x_k_1 = x_k;
40 y_k_1 = y_k;
41
42 return y_k;
43}
44
45template <typename T>
47{
48 x_k_1 = 0.0;
49 y_k_1 = 0.0;
50 start = false;
51}
52
53template <typename T>
55{
56 set_param(fc_, dt);
57}
58
59template <typename T>
61{
62 tau = tau_;
63 fc = 1.0 / (6.28318530717958647692528676655900576 * tau);
64 alpha = tau / (dt + tau);
65}
66
67template <typename T>
69{
70 set_param(fc, dt_);
71}
72
73template <typename T>
75{
76 alpha = alpha_;
77 tau = (alpha / (1.0 - alpha)) * dt;
78 fc = 1.0 / (6.28318530717958647692528676655900576 * tau);
79}
80
81template <typename T>
83{
84 return fc;
85}
86
87template <typename T>
89{
90 return tau;
91}
92
93template <typename T>
95{
96 return dt;
97}
98
99template <typename T>
101{
102 return alpha;
103}
104
105template <typename T>
107{
108 return 1.0 / dt;
109}
T get_fs()
Gets the sampling frequency.
Definition hpf_1.h:107
T update(T x_k)
Processes a new input sample.
Definition hpf_1.h:27
void set_tau(T tau_)
Sets the filter time constant.
Definition hpf_1.h:61
void set_param(T fc_, T dt_)
Sets the filter parameters.
Definition hpf_1.h:17
HPF_1()
Constructs a first-order high-pass filter.
Definition hpf_1.h:5
void set_fc(T fc_)
Sets the cutoff frequency.
Definition hpf_1.h:55
T get_fc()
Gets the cutoff frequency.
Definition hpf_1.h:83
void config(T fc_, T dt_)
Configures the high-pass filter.
Definition hpf_1.h:11
void set_dt(T dt_)
Sets the sampling time.
Definition hpf_1.h:69
T get_alpha()
Gets the filter coefficient.
Definition hpf_1.h:101
void set_alpha(T alpha_)
Sets the filter coefficient.
Definition hpf_1.h:75
T get_tau()
Gets the filter time constant.
Definition hpf_1.h:89
T get_dt()
Gets the sampling time.
Definition hpf_1.h:95
void reset()
Resets the filter state.
Definition hpf_1.h:47
First-order high-pass filter.