Filters 1.0
LPF, HPF, BPF, BSF, SRL
Loading...
Searching...
No Matches
hpf_2.h
Go to the documentation of this file.
1
5 * @details
6 * This file defines the @ref filter::high_pass::HPF_2 class, which
7 * implements a discrete-time second-order high-pass filter.
8 *
9 * The filter attenuates low-frequency and DC components while allowing
10 * high-frequency components of the input signal to pass.
11 *
12 * The filter is configured using the cutoff frequency and sampling time.
13 * The cutoff frequency is prewarped during filter design to compensate
14 * for the frequency transformation associated with the bilinear
15 * transformation.
16 *
17 * The implementation maintains previous input and output samples as
18 * internal filter state.
19 *
20 * The class is templated to support different numeric types such as
21 * @c float and @c double.
22 *
23 * @tparam T Numeric data type used for the filter calculations.
24 *
25 * @author Abhinay Kumar
26 * @version 1.0.0
27 *
28 * @copyright
29 * Copyright (c) 2026 Abhinay Kumar
30 */
31
32#ifndef FILTER_HPF_2_H
33#define FILTER_HPF_2_H
34
35#include <cstdint>
36
37namespace filter
43
44 namespace high_pass
45 {
50
58
60 * while allowing higher-frequency components to pass.
61 *
62 * The filter is configured using the cutoff frequency and
63 * sampling time. During configuration, the cutoff frequency
64 * is prewarped to compensate for frequency distortion introduced
65 * by the bilinear transformation.
66 *
67 * The filter maintains two previous input samples and two
68 * previous output samples as its internal state.
69 *
70 * @tparam T Numeric data type used for the filter.
71 *
72 * @par Example
73 * @code{.cpp}
74 * filter::high_pass::HPF_2<double> filter;
75 *
76 * filter.config(2.5, 0.001);
77 *
78 * double output = filter.update(input);
79 * @endcode
80 */
81 template <typename T>
82 class HPF_2
83 {
84 public:
86
88 * @details
89 * Constructs the filter with its parameters and internal
90 * state initialized to their default values.
91 */
92 HPF_2();
93
94 /**
95 * @brief Configures the high-pass filter.
96 *
97 * @param[in] fc_ Cutoff frequency of the filter in Hz.
98 * @param[in] dt_ Sampling time of the filter in seconds.
99 *
100 * @details
101 * Configures the filter using the specified cutoff frequency
102 * and sampling time and calculates the required filter
103 * coefficients.
104 */
105 void config(T fc_, T dt_);
106
117 void set_param(T fc_, T dt_);
118
131 T update(T x_k);
132
140 void reset();
141
147 void set_fc(T fc_);
148
154 void set_dt(T dt_);
155
161 T get_fc();
162
168 T get_dt();
169
183 T get_fs();
184
185 private:
192 T fc = 0.0;
193
200 T dt = 0.0;
201
209 T lambda_1 = 0.0;
210
214 T lambda_2 = 0.0;
215
219 T lambda_3 = 0.0;
220
224 T lambda_4 = 0.0;
225
229 T lambda_5 = 0.0;
230
237 T y_k_1 = 0.0;
238
242 T y_k_2 = 0.0;
243
250 T x_k_1 = 0.0;
251
255 T x_k_2 = 0.0;
256
264 uint8_t start_counter = 0;
265
279 T prewarp_freq(T wc_, T dt_);
280 };
281
283
284 } // namespace high_pass
285
286} // namespace filter
287
288#endif // FILTER_HPF_2_H
void set_param(T fc_, T dt_)
Sets the filter parameters.
Definition hpf_2.h:17
T lambda_1
First filter coefficient.
Definition hpf_2.h:209
T get_fc()
Gets the cutoff frequency.
Definition hpf_2.h:82
T dt
Sampling time of the filter.
Definition hpf_2.h:200
T x_k_1
Previous input sample.
Definition hpf_2.h:250
T update(T x_k)
Processes a new input sample.
Definition hpf_2.h:38
T lambda_4
Fourth filter coefficient.
Definition hpf_2.h:224
T prewarp_freq(T wc_, T dt_)
Prewarps an angular cutoff frequency.
Definition hpf_2.h:100
T lambda_2
Second filter coefficient.
Definition hpf_2.h:214
void config(T fc_, T dt_)
Configures the high-pass filter.
Definition hpf_2.h:11
T x_k_2
Input sample from two iterations ago.
Definition hpf_2.h:255
void set_fc(T fc_)
Sets the cutoff frequency.
Definition hpf_2.h:70
void set_dt(T dt_)
Sets the sampling time.
Definition hpf_2.h:76
T lambda_5
Fifth filter coefficient.
Definition hpf_2.h:229
void reset()
Resets the filter state.
Definition hpf_2.h:60
T lambda_3
Third filter coefficient.
Definition hpf_2.h:219
T get_fs()
Gets the sampling frequency.
Definition hpf_2.h:94
HPF_2()
Constructs a second-order high-pass filter.
Definition hpf_2.h:5
T y_k_1
Previous filter output sample.
Definition hpf_2.h:237
uint8_t start_counter
Number of samples processed during filter startup.
Definition hpf_2.h:264
T get_dt()
Gets the sampling time.
Definition hpf_2.h:88
T y_k_2
Filter output sample from two iterations ago.
Definition hpf_2.h:242
T fc
Cutoff frequency of the filter.
Definition hpf_2.h:192
Contains digital signal filtering algorithms.
Definition bpf_2.h:38
Contains high-pass filter implementations.