Filters
1.0
LPF, HPF, BPF, BSF, SRL
Toggle main menu visibility
Loading...
Searching...
No Matches
hpf_1.h
Go to the documentation of this file.
1
5
* @details
6
* This file defines the @ref filter::high_pass::HPF_1 class, which
7
* implements a discrete-time first-order high-pass filter.
8
*
9
* The filter attenuates low-frequency and DC components while allowing
10
* higher-frequency components of the input signal to pass.
11
*
12
* The filter is parameterized by its cutoff frequency and sampling time.
13
* The implementation maintains the previous input and output samples
14
* as internal state variables.
15
*
16
* The class is templated to support different numeric types such as
17
* @c float and @c double.
18
*
19
* @tparam T Numeric data type used for the filter calculations.
20
*
21
* @author Abhinay Kumar
22
* @version 1.0.0
23
*
24
* @copyright
25
* Copyright (c) 2026 Abhinay Kumar
26
*/
27
28
#ifndef FILTER_HPF_1
29
#define FILTER_HPF_1
30
31
namespace
filter
32
{
37
38
namespace
high_pass
39
{
44
47
* @brief First-order high-pass filter.
48
*
49
* @details
50
* The HPF_1 class implements a discrete-time first-order
51
* high-pass filter.
52
*
53
* The filter attenuates low-frequency components and DC offsets
54
* while allowing higher-frequency components to pass.
55
*
56
* The filter can be configured using the cutoff frequency and
57
* sampling time. Alternatively, individual filter parameters such
58
* as the cutoff frequency, time constant, sampling time, and
59
* filter coefficient can be configured directly.
60
*
61
* @tparam T Numeric data type used for the filter.
62
*
63
* @par Example
64
* @code{.cpp}
65
* filter::high_pass::HPF_1<double> filter;
66
*
67
* filter.config(2.5, 0.001);
68
*
69
* double output = filter.update(input);
70
* @endcode
71
*/
72
template
<
typename
T>
73
class
HPF_1
74
{
75
public
:
81
83
HPF_1
();
84
87
89
* @param[in] dt_ Sampling time of the filter in seconds.
90
*
91
* @details
92
* Configures the filter using the specified cutoff frequency
93
* and sampling time.
94
*/
95
void
config
(T fc_, T dt_);
96
99
101
* @param[in] dt_ Sampling time of the filter in seconds.
102
*
103
* @details
104
* Updates the cutoff frequency and sampling time used by
105
* the filter.
106
*/
107
void
set_param
(T fc_, T dt_);
108
111
120
T
update
(T x_k);
121
129
void
reset
();
130
136
void
set_fc
(T fc_);
137
143
void
set_tau
(T tau_);
144
150
void
set_dt
(T dt_);
151
158
void
set_alpha
(T alpha_);
159
165
T
get_fc
();
166
172
T
get_tau
();
173
179
T
get_dt
();
180
186
T
get_alpha
();
187
201
T
get_fs
();
202
203
private
:
210
T
fc
= 0.0;
211
218
T
tau
= 0.0;
219
226
T
dt
= 0.0;
227
231
T
alpha
= 0.0;
232
239
T
x_k_1
= 0.0;
240
247
T
y_k_1
= 0.0;
248
256
bool
start
=
false
;
257
};
258
259
#include "
../../src/high_pass/hpf_1.tpp
"
260
}
// namespace high_pass
261
262
}
// namespace filter
263
264
#endif
// FILTER_HPF_1
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::tau
T tau
Filter time constant.
Definition
hpf_1.h:218
filter::high_pass::HPF_1::fc
T fc
Cutoff frequency of the filter.
Definition
hpf_1.h:210
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::x_k_1
T x_k_1
Previous input sample.
Definition
hpf_1.h:239
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::dt
T dt
Sampling time of the filter.
Definition
hpf_1.h:226
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::alpha
T alpha
Discrete-time filter coefficient.
Definition
hpf_1.h:231
filter::high_pass::HPF_1::start
bool start
Indicates whether the filter has received its first sample.
Definition
hpf_1.h:256
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::y_k_1
T y_k_1
Previous filter output sample.
Definition
hpf_1.h:247
filter::high_pass::HPF_1::reset
void reset()
Resets the filter state.
Definition
hpf_1.h:47
hpf_1.tpp
filter
Contains digital signal filtering algorithms.
Definition
bpf_2.h:38
high_pass
Contains high-pass filter implementations.
include
high_pass
hpf_1.h
Generated by
1.17.0