Filters
1.0
LPF, HPF, BPF, BSF, SRL
Toggle main menu visibility
Loading...
Searching...
No Matches
bsf_2.h
Go to the documentation of this file.
1
5
* @details
6
* This file defines the @ref filter::band_stop::BSF_2 class, which
7
* implements a discrete-time second-order band-stop filter.
8
*
9
* The filter attenuates frequency components within a specified
10
* frequency band while allowing frequencies below and above the
11
* stopband to pass.
12
*
13
* The filter is parameterized by its center frequency, bandwidth,
14
* and sampling time. The quality factor is derived from the center
15
* frequency and bandwidth.
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_BSF_2_H
33
#define FILTER_BSF_2_H
34
35
#include <cstdint>
36
#include <cmath>
37
38
namespace
filter
39
{
44
45
namespace
band_stop
46
{
51
56
* @details
57
* The BSF_2 class implements a discrete-time second-order
58
* band-stop filter.
59
*
60
* The filter attenuates frequency components around the specified
61
* center frequency while allowing frequencies outside the stopband
62
* to pass.
63
*
64
* The filter is configured using the center frequency, bandwidth,
65
* and sampling time. The quality factor is calculated from the
66
* center frequency and bandwidth.
67
*
68
* @tparam T Numeric data type used for the filter.
69
*
70
* @par Example
71
* @code{.cpp}
72
* filter::band_stop::BSF_2<double> filter;
73
*
74
* filter.config(50.0, 5.0, 0.001);
75
*
76
* double output = filter.update(input);
77
* @endcode
78
*/
79
template
<
typename
T>
80
class
BSF_2
81
{
82
public
:
88
* state initialized to their default values.
89
*/
90
BSF_2
();
91
92
94
*
95
* @param[in] f0_ Center frequency of the filter in Hz.
96
* @param[in] B_ Bandwidth of the filter in Hz.
97
* @param[in] dt_ Sampling time of the filter in seconds.
98
*
99
* @details
100
* Configures the filter using the specified center frequency,
101
* bandwidth, and sampling time, and calculates the required
102
* filter coefficients.
103
*/
104
void
config
(T f0_, T B_, T dt_);
105
106
/**
107
* @brief Sets the filter parameters.
108
*
109
* @param[in] f0_ Center frequency of the filter in Hz.
110
* @param[in] B_ Bandwidth of the filter in Hz.
111
* @param[in] dt_ Sampling time of the filter in seconds.
112
*
113
* @details
114
* Updates the center frequency, bandwidth, and sampling time
115
* used by the filter.
116
*/
117
void
set_param
(T f0_, T B_, T dt_);
118
122
124
* @return Filtered output sample.
125
*
126
* @details
127
* Processes the current input sample using the second-order
128
* band-stop filter equation and updates the internal filter
129
* state.
130
*/
131
T
update
(T x_k);
132
134
136
* @details
137
* Resets the previous input and output samples and the
138
* startup counter.
139
*/
140
void
reset
();
141
147
void
set_f0
(T f0_);
148
154
void
set_B
(T B_);
155
161
void
set_dt
(T dt_);
162
168
T
get_f0
();
169
175
T
get_B
();
176
182
T
get_dt
();
183
200
T
get_Q
();
201
215
T
get_fs
();
216
217
private
:
224
T
f0
= 0.0;
225
232
T
B
= 0.0;
233
240
T
dt
= 0.0;
241
250
T
Q
= 0.0;
251
259
T
lambda_1
= 0.0;
260
264
T
lambda_2
= 0.0;
265
269
T
lambda_3
= 0.0;
270
274
T
lambda_4
= 0.0;
275
279
T
lambda_5
= 0.0;
280
287
T
y_k_1
= 0.0;
288
292
T
y_k_2
= 0.0;
293
300
T
x_k_1
= 0.0;
301
305
T
x_k_2
= 0.0;
306
314
uint8_t
start_counter
= 0;
315
329
T
prewarp_freq
(T wc_, T dt_);
330
};
331
332
#include "
../../src/band_stop/bsf_2.tpp
"
333
334
}
// namespace band_stop
335
336
}
// namespace filter
337
338
#endif
// FILTER_BSF_2_H
bsf_2.tpp
filter::band_stop::BSF_2::f0
T f0
Center frequency of the filter.
Definition
bsf_2.h:224
filter::band_stop::BSF_2::update
T update(T x_k)
Processes a new input sample.
Definition
bsf_2.h:56
filter::band_stop::BSF_2::lambda_3
T lambda_3
Third filter coefficient.
Definition
bsf_2.h:269
filter::band_stop::BSF_2::set_B
void set_B(T B_)
Sets the bandwidth.
Definition
bsf_2.h:94
filter::band_stop::BSF_2::dt
T dt
Sampling time of the filter.
Definition
bsf_2.h:240
filter::band_stop::BSF_2::y_k_1
T y_k_1
Previous filter output sample.
Definition
bsf_2.h:287
filter::band_stop::BSF_2::reset
void reset()
Resets the filter state.
Definition
bsf_2.h:78
filter::band_stop::BSF_2::B
T B
Bandwidth of the filter.
Definition
bsf_2.h:232
filter::band_stop::BSF_2::BSF_2
BSF_2()
Constructs a second-order band-stop filter.
Definition
bsf_2.h:5
filter::band_stop::BSF_2::get_Q
T get_Q()
Gets the quality factor.
Definition
bsf_2.h:124
filter::band_stop::BSF_2::y_k_2
T y_k_2
Filter output sample from two iterations ago.
Definition
bsf_2.h:292
filter::band_stop::BSF_2::get_dt
T get_dt()
Gets the sampling time.
Definition
bsf_2.h:118
filter::band_stop::BSF_2::lambda_1
T lambda_1
First filter coefficient.
Definition
bsf_2.h:259
filter::band_stop::BSF_2::Q
T Q
Quality factor of the filter.
Definition
bsf_2.h:250
filter::band_stop::BSF_2::lambda_2
T lambda_2
Second filter coefficient.
Definition
bsf_2.h:264
filter::band_stop::BSF_2::prewarp_freq
T prewarp_freq(T wc_, T dt_)
Prewarps an angular cutoff frequency.
Definition
bsf_2.h:136
filter::band_stop::BSF_2::get_B
T get_B()
Gets the bandwidth.
Definition
bsf_2.h:112
filter::band_stop::BSF_2::lambda_4
T lambda_4
Fourth filter coefficient.
Definition
bsf_2.h:274
filter::band_stop::BSF_2::config
void config(T f0_, T B_, T dt_)
Configures the band-stop filter.
Definition
bsf_2.h:11
filter::band_stop::BSF_2::set_param
void set_param(T f0_, T B_, T dt_)
Sets the filter parameters.
Definition
bsf_2.h:17
filter::band_stop::BSF_2::set_dt
void set_dt(T dt_)
Sets the sampling time.
Definition
bsf_2.h:100
filter::band_stop::BSF_2::start_counter
uint8_t start_counter
Number of samples processed during filter startup.
Definition
bsf_2.h:314
filter::band_stop::BSF_2::lambda_5
T lambda_5
Fifth filter coefficient.
Definition
bsf_2.h:279
filter::band_stop::BSF_2::x_k_2
T x_k_2
Input sample from two iterations ago.
Definition
bsf_2.h:305
filter::band_stop::BSF_2::get_fs
T get_fs()
Gets the sampling frequency.
Definition
bsf_2.h:130
filter::band_stop::BSF_2::set_f0
void set_f0(T f0_)
Sets the center frequency.
Definition
bsf_2.h:88
filter::band_stop::BSF_2::x_k_1
T x_k_1
Previous input sample.
Definition
bsf_2.h:300
filter::band_stop::BSF_2::get_f0
T get_f0()
Gets the center frequency.
Definition
bsf_2.h:106
band_stop
Contains band-stop filter implementations.
filter
Contains digital signal filtering algorithms.
Definition
bpf_2.h:38
include
band_stop
bsf_2.h
Generated by
1.17.0