Filters 1.0
LPF, HPF, BPF, BSF, SRL
Loading...
Searching...
No Matches
lpf_1.h
Go to the documentation of this file.
1
5 * @details
6 * This file defines the @ref filter::low_pass::LPF_1 class, which
7 * implements a first-order low-pass filter for attenuating high-frequency
8 * components of an input signal.
9 *
10 * The filter is parameterized by its cutoff frequency and sampling time.
11 * The implementation maintains the previous output value as its internal
12 * state.
13 *
14 * The class is templated to support different numeric types such as
15 * @c float and @c double.
16 *
17 * @tparam T Numeric data type used for the filter calculations.
18 *
19 * @author Abhinay Kumar
20 * @version 1.0.0
21 *
22 * @copyright
23 * Copyright (c) 2026 Abhinay Kumar
24 */
25
26#ifndef FILTER_LPF_1
27#define FILTER_LPF_1
28
29namespace filter
30{
35
36 namespace low_pass
37 {
42
44 * @class LPF_1
45 * @brief First-order low-pass filter.
46 *
47 * @details
48 * The LPF_1 class implements a discrete-time first-order
49 * low-pass filter.
50 *
51 * The filter attenuates high-frequency components while allowing
52 * low-frequency components of the input signal to pass.
53 *
54 * The filter can be configured using the cutoff frequency and
55 * sampling time. Alternatively, individual filter parameters such
56 * as the cutoff frequency, time constant, sampling time, and
57 * filter coefficient can be configured directly.
58 *
59 * @tparam T Numeric data type used for the filter.
60 *
61 * @par Example
62 * @code{.cpp}
63 * filter::low_pass::LPF_1<double> filter;
64 *
65 * filter.config(10.0, 0.001);
66 *
67 * double output = filter.update(input);
68 * @endcode
69 */
70 template <typename T>
71 class LPF_1
72 {
73 public:
77
79 * their default values.
80 */
81 LPF_1();
82
83
85 *
86 * @param[in] fc_ Cutoff frequency of the filter in Hz.
87 * @param[in] dt_ Sampling time of the filter in seconds.
88 *
89 * @details
90 * Configures the filter using the cutoff frequency and
91 * sampling time.
92 */
93 void config(T fc_, T dt_);
94
95
97 *
98 * @param[in] fc_ Cutoff frequency of the filter in Hz.
99 * @param[in] dt_ Sampling time of the filter in seconds.
100 *
101 * @details
102 * Updates the cutoff frequency and sampling time used by
103 * the filter.
104 */
105 void set_param(T fc_, T dt_);
106
107
118 T update(T x_k);
119
126 void reset();
127
133 void set_fc(T fc_);
134
140 void set_tau(T tau_);
141
147 void set_dt(T dt_);
148
155 void set_alpha(T alpha_);
156
162 T get_fc();
163
169 T get_tau();
170
176 T get_dt();
177
183 T get_alpha();
184
198 T get_fs();
199
200 private:
207 T fc = 0.0;
208
215 T tau = 0.0;
216
223 T dt = 0.0;
224
228 T alpha = 0.0;
229
236 T y_k_1 = 0.0;
237
245 bool start = false;
246 };
247
249 } // namespace low_pass
250
251} // namespace filter
252
253#endif // FILTER_LPF_1
T update(T x_k)
Processes a new input sample.
Definition lpf_1.h:26
T fc
Cutoff frequency of the filter.
Definition lpf_1.h:207
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
T alpha
Discrete-time filter coefficient.
Definition lpf_1.h:228
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 tau
Filter time constant.
Definition lpf_1.h:215
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
bool start
Indicates whether the filter has received its first sample.
Definition lpf_1.h:245
T dt
Sampling time of the filter.
Definition lpf_1.h:223
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
T y_k_1
Previous filter output.
Definition lpf_1.h:236
Contains digital signal filtering algorithms.
Definition bpf_2.h:38
Contains low-pass filter implementations.