Filters
1.0
LPF, HPF, BPF, BSF, SRL
Toggle main menu visibility
Loading...
Searching...
No Matches
hpf_1.tpp
Go to the documentation of this file.
1
#include "
../../include/high_pass/hpf_1.h
"
2
3
template
<
typename
T>
4
filter::high_pass::HPF_1<T>::HPF_1
()
5
{
6
reset();
7
}
8
9
template
<
typename
T>
10
void
filter::high_pass::HPF_1<T>::config
(T fc_, T dt_)
11
{
12
set_param(fc_, dt_);
13
}
14
15
template
<
typename
T>
16
void
filter::high_pass::HPF_1<T>::set_param
(T fc_, T dt_)
17
{
18
fc = fc_;
19
dt = dt_;
20
21
tau = 1.0 / (6.28318530717958647692528676655900576 * fc);
22
alpha = tau / (dt + tau);
23
}
24
25
template
<
typename
T>
26
T
filter::high_pass::HPF_1<T>::update
(T x_k)
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
45
template
<
typename
T>
46
void
filter::high_pass::HPF_1<T>::reset
()
47
{
48
x_k_1 = 0.0;
49
y_k_1 = 0.0;
50
start =
false
;
51
}
52
53
template
<
typename
T>
54
void
filter::high_pass::HPF_1<T>::set_fc
(T fc_)
55
{
56
set_param(fc_, dt);
57
}
58
59
template
<
typename
T>
60
void
filter::high_pass::HPF_1<T>::set_tau
(T tau_)
61
{
62
tau = tau_;
63
fc = 1.0 / (6.28318530717958647692528676655900576 * tau);
64
alpha = tau / (dt + tau);
65
}
66
67
template
<
typename
T>
68
void
filter::high_pass::HPF_1<T>::set_dt
(T dt_)
69
{
70
set_param(fc, dt_);
71
}
72
73
template
<
typename
T>
74
void
filter::high_pass::HPF_1<T>::set_alpha
(T alpha_)
75
{
76
alpha = alpha_;
77
tau = (alpha / (1.0 - alpha)) * dt;
78
fc = 1.0 / (6.28318530717958647692528676655900576 * tau);
79
}
80
81
template
<
typename
T>
82
T
filter::high_pass::HPF_1<T>::get_fc
()
83
{
84
return
fc;
85
}
86
87
template
<
typename
T>
88
T
filter::high_pass::HPF_1<T>::get_tau
()
89
{
90
return
tau;
91
}
92
93
template
<
typename
T>
94
T
filter::high_pass::HPF_1<T>::get_dt
()
95
{
96
return
dt;
97
}
98
99
template
<
typename
T>
100
T
filter::high_pass::HPF_1<T>::get_alpha
()
101
{
102
return
alpha;
103
}
104
105
template
<
typename
T>
106
T
filter::high_pass::HPF_1<T>::get_fs
()
107
{
108
return
1.0 / dt;
109
}
filter::high_pass::HPF_1::get_fs
T get_fs()
Gets the sampling frequency.
Definition
hpf_1.h:107
filter::high_pass::HPF_1::update
T update(T x_k)
Processes a new input sample.
Definition
hpf_1.h:27
filter::high_pass::HPF_1::set_tau
void set_tau(T tau_)
Sets the filter time constant.
Definition
hpf_1.h:61
filter::high_pass::HPF_1::set_param
void set_param(T fc_, T dt_)
Sets the filter parameters.
Definition
hpf_1.h:17
filter::high_pass::HPF_1::HPF_1
HPF_1()
Constructs a first-order high-pass filter.
Definition
hpf_1.h:5
filter::high_pass::HPF_1::set_fc
void set_fc(T fc_)
Sets the cutoff frequency.
Definition
hpf_1.h:55
filter::high_pass::HPF_1::get_fc
T get_fc()
Gets the cutoff frequency.
Definition
hpf_1.h:83
filter::high_pass::HPF_1::config
void config(T fc_, T dt_)
Configures the high-pass filter.
Definition
hpf_1.h:11
filter::high_pass::HPF_1::set_dt
void set_dt(T dt_)
Sets the sampling time.
Definition
hpf_1.h:69
filter::high_pass::HPF_1::get_alpha
T get_alpha()
Gets the filter coefficient.
Definition
hpf_1.h:101
filter::high_pass::HPF_1::set_alpha
void set_alpha(T alpha_)
Sets the filter coefficient.
Definition
hpf_1.h:75
filter::high_pass::HPF_1::get_tau
T get_tau()
Gets the filter time constant.
Definition
hpf_1.h:89
filter::high_pass::HPF_1::get_dt
T get_dt()
Gets the sampling time.
Definition
hpf_1.h:95
filter::high_pass::HPF_1::reset
void reset()
Resets the filter state.
Definition
hpf_1.h:47
hpf_1.h
First-order high-pass filter.
src
high_pass
hpf_1.tpp
Generated by
1.17.0