Complementary Filter
1.0
Complementary Filter for Real-Time Application
Toggle main menu visibility
Loading...
Searching...
No Matches
cf.h
Go to the documentation of this file.
1
5
*
6
* @details
7
* This file defines the @ref estimators::cf::CF class, which implements
8
* a complementary filter for sensor fusion.
9
*
10
* A complementary filter combines measurements from different sensors
11
* by exploiting their complementary frequency characteristics. For
12
* example, a low-frequency measurement from one sensor can be combined
13
* with a high-frequency measurement from another sensor to obtain a
14
* more stable estimate.
15
*
16
* The filter parameters are defined by the cutoff frequency, time step,
17
* time constant, and filter coefficient.
18
*
19
* @version 1.0
20
* @date 2026-08-11
21
*
22
* @copyright
23
* Copyright (c) 2026 Abhinay Kumar
24
*/
25
26
#ifndef ESTIMATORS_COMPLIMENTARY_FILTER
27
#define ESTIMATORS_COMPLIMENTARY_FILTER
28
29
namespace
estimators
30
{
34
35
36
namespace
cf
37
{
39
41
*/
42
45
47
* @details
48
* The CF class implements a first-order complementary filter that
49
* combines two input measurements into a single filtered output.
50
*
51
* The filter can be configured using either the cutoff frequency
52
* and sampling time or directly using the filter parameters.
53
*
54
* The class is templated so that the filter can operate on different
55
* numeric types such as @c float or @c double.
56
*
57
* @tparam T Numeric data type used for the filter calculations.
58
*
59
* @par Typical usage
60
* @code{.cpp}
61
* estimators::cf::CF<double> filter;
62
*
63
* filter.init(2.5, 0.006);
64
*
65
* double output = filter.update(x1, x2);
66
* @endcode
67
*/
68
template
<
typename
T>
69
class
CF
70
{
71
public
:
73
75
* @details
76
* The filter parameters are initialized to zero. Use
77
* @ref init() or the individual setter functions to configure
78
* the filter before using @ref update().
79
*/
80
CF
();
81
85
~CF
();
86
87
/**
88
* @brief Initializes the complementary filter.
89
*
90
* @param[in] fc_ Cutoff frequency of the filter.
91
* @param[in] dt_ Sampling time or control-loop period.
92
*
93
* @details
94
* This function initializes the filter parameters using the
95
* specified cutoff frequency and sampling time.
96
*/
97
void
init
(T fc_, T dt_);
98
109
void
set_param
(T fc_, T dt_);
110
124
T
update
(T x1_i, T x2_i);
125
133
void
reset
();
134
140
void
set_fc
(T fc_);
141
147
void
set_tau
(T tau_);
148
154
void
set_dt
(T dt_);
155
161
void
set_alpha
(T alpha_);
162
168
T
get_fc
();
169
175
T
get_tau
();
176
182
T
get_dt
();
183
189
T
get_alpha
();
190
191
private
:
195
T
fc
= 0.0;
196
200
T
tau
= 0.0;
201
205
T
dt
= 0.0;
206
210
T
alpha
= 0.0;
211
};
212
213
#include "
CF.tpp
"
214
215
}
// namespace cf
216
217
}
// namespace estimators
218
219
#endif
// ESTIMATORS_COMPLIMENTARY_FILTER
cf.tpp
estimators::cf::CF::update
T update(T x1_i, T x2_i)
Updates the complementary filter with new measurements.
Definition
cf.h:30
estimators::cf::CF::init
void init(T fc_, T dt_)
Initializes the complementary filter.
Definition
cf.h:15
estimators::cf::CF::dt
T dt
Sampling time or control-loop period.
Definition
cf.h:205
estimators::cf::CF::fc
T fc
Cutoff frequency of the filter.
Definition
cf.h:195
estimators::cf::CF::set_fc
void set_fc(T fc_)
Sets the cutoff frequency.
Definition
cf.h:41
estimators::cf::CF::alpha
T alpha
Complementary filter coefficient.
Definition
cf.h:210
estimators::cf::CF::tau
T tau
Time constant of the filter.
Definition
cf.h:200
estimators::cf::CF::set_param
void set_param(T fc_, T dt_)
Sets the filter parameters.
Definition
cf.h:21
estimators::cf::CF::~CF
~CF()
Destroys the complementary filter.
Definition
cf.h:10
estimators::cf::CF::set_alpha
void set_alpha(T alpha_)
Sets the complementary filter coefficient.
Definition
cf.h:61
estimators::cf::CF::reset
void reset()
Resets the filter state.
Definition
cf.h:36
estimators::cf::CF::set_dt
void set_dt(T dt_)
Sets the sampling time.
Definition
cf.h:55
estimators::cf::CF::CF
CF()
Constructs a complementary filter.
Definition
cf.h:5
estimators::cf::CF::get_tau
T get_tau()
Gets the filter time constant.
Definition
cf.h:75
estimators::cf::CF::get_dt
T get_dt()
Gets the sampling time.
Definition
cf.h:81
estimators::cf::CF::get_alpha
T get_alpha()
Gets the complementary filter coefficient.
Definition
cf.h:87
estimators::cf::CF::set_tau
void set_tau(T tau_)
Sets the filter time constant.
Definition
cf.h:47
estimators::cf::CF::get_fc
T get_fc()
Gets the cutoff frequency.
Definition
cf.h:69
cf
Contains the complementary filter implementation.
estimators
Contains estimation and sensor-fusion algorithms.
Definition
cf.h:30
include
cf.h
Generated by
1.17.0