Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
complementary_filter.h
Go to the documentation of this file.
1/*
2 *
3 * Copyright (C) 2025 Justin Dubois <j.p.g.dubois@student.tudelft.nl>
4 *
5 * This file is part of paparazzi
6 *
7 * paparazzi is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
11 *
12 * paparazzi is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with paparazzi; see the file COPYING. If not, see
19 * <http://www.gnu.org/licenses/>.
20 *
21 */
22
36#ifndef COMPLEMENTARY_FILTER_H
37#define COMPLEMENTARY_FILTER_H
38
39#include "std.h"
41
42
50 struct FirstOrderLowPass x_lp_filter; // Low pass filter instance for high pass path
51 struct FirstOrderLowPass y_lp_filter; // Low pass filter instance for low pass path
52};
53
62 struct FirstOrderComplementary *filter,
63 float cut_off, float sample_time,
64 float value)
65{
68}
69
77 struct FirstOrderComplementary *filter,
78 float value_x, float value_y)
79{
82 return filter->x_lp_filter.last_in - x_lp_output + y_lp_output;
83}
84
93 struct FirstOrderComplementary *filter,
94 float value)
95{
98 return value;
99}
100
105static inline float get_first_order_complementary(const struct FirstOrderComplementary *filter)
106{
109 return filter->x_lp_filter.last_in - x_lp_output + y_lp_output;
110}
111
119 struct SecondOrderLowPass x_lp_filter; // Low pass filter instance for high pass path
120 struct SecondOrderLowPass y_lp_filter; // Low pass filter instance for low pass path
121};
122
132 struct SecondOrderComplementary *filter,
133 float cut_off, float Q, float sample_time,
134 float value)
135{
136 init_second_order_low_pass(&filter->x_lp_filter, 1.0f / cut_off, Q, sample_time, value);
137 init_second_order_low_pass(&filter->y_lp_filter, 1.0f / cut_off, Q, sample_time, value);
138}
139
148 struct SecondOrderComplementary *filter,
149 float value_x, float value_y)
150{
153 return filter->x_lp_filter.i[0] - x_lp_output + y_lp_output;
154}
155
164 struct SecondOrderComplementary *filter,
165 float value)
166{
169 return value;
170}
171
177static inline float get_second_order_complementary(const struct SecondOrderComplementary *filter)
178{
181 return filter->x_lp_filter.i[0] - x_lp_output + y_lp_output;
182}
183
185
195 float cut_off, float sample_time,
196 float value)
197{
199 (struct SecondOrderComplementary *)filter,
200 cut_off, 0.7071, sample_time,
201 value);
202}
203
215
222static inline void reset_butterworth_2_complementary(Butterworth2Complementary *filter, float value)
223{
225}
226
233{
234 return get_second_order_complementary((const struct SecondOrderComplementary *)filter);
235}
236
243typedef struct {
244 Butterworth4LowPass x_lp_filter; // Low pass filter instance for high pass path
245 Butterworth4LowPass y_lp_filter; // Low pass filter instance for low pass path
247
256 float value)
257{
260}
261
275
282static inline void reset_butterworth_4_complementary(Butterworth4Complementary *filter, float value)
283{
286}
287
294{
297 return filter->x_lp_filter.lp1.i[0] - x_lp_output + y_lp_output;
298}
299
300
301
302
303
304
305
306
307#endif /* COMPLEMENTARY_FILTER_H */
struct SecondOrderLowPass y_lp_filter
struct SecondOrderLowPass x_lp_filter
static float get_second_order_complementary(const struct SecondOrderComplementary *filter)
Get current value of the second order complementary filter.
static float reset_second_order_complementary(struct SecondOrderComplementary *filter, float value)
Reset the second order complementary filter to a specific value.
static void init_second_order_complementary(struct SecondOrderComplementary *filter, float cut_off, float Q, float sample_time, float value)
Initialize the second order complementary filter.
static float update_butterworth_2_complementary(Butterworth2Complementary *filter, float value_x, float value_y)
Update the Butterworth 2nd order low-pass complementary filter with new input values.
static float reset_first_order_complementary(struct FirstOrderComplementary *filter, float value)
Reset the first order complementary filter to a specific value.
static float update_butterworth_4_complementary(Butterworth4Complementary *filter, float value_x, float value_y)
Update the Butterworth 4th order low-pass complementary filter with new input values.
static void reset_butterworth_4_complementary(Butterworth4Complementary *filter, float value)
Reset the Butterworth 4th order complementary filter to a specific value.
static void reset_butterworth_2_complementary(Butterworth2Complementary *filter, float value)
Reset the Butterworth 2nd order complementary filter to a specific value.
static float update_first_order_complementary(struct FirstOrderComplementary *filter, float value_x, float value_y)
Update the first order complementary filter with new input values.
static void init_first_order_complementary(struct FirstOrderComplementary *filter, float cut_off, float sample_time, float value)
Initialize the first order complementary filter.
static float get_butterworth_4_complementary(const Butterworth4Complementary *filter)
Get current value of the Butterworth 4th order low-pass complementary filter.
static float get_butterworth_2_complementary(const Butterworth2Complementary *filter)
Get current value of the Butterworth 2nd order low-pass complementary filter.
static float get_first_order_complementary(const struct FirstOrderComplementary *filter)
Get current value of the first order complementary filter.
struct FirstOrderLowPass y_lp_filter
struct FirstOrderLowPass x_lp_filter
static void init_butterworth_2_complementary(Butterworth2Complementary *filter, float cut_off, float sample_time, float value)
Initialize the Butterworth 2nd order low-pass complementary filter.
static void init_butterworth_4_complementary(Butterworth4Complementary *filter, float cut_off, float sample_time, float value)
Initialize the Butterworth 4th order low-pass complementary filter.
static float update_second_order_complementary(struct SecondOrderComplementary *filter, float value_x, float value_y)
Update the second order complementary filter with new input values.
4th order Butterworth complementary filter structure.
First order complementary filter structure.
Second order complementary filter structure.
Simple first order low pass filter with bilinear transform.
static float get_second_order_low_pass(const struct SecondOrderLowPass *filter)
Get current value of the second order low pass filter.
static void reset_butterworth_4_low_pass(Butterworth4LowPass *filter, const float value)
Reset a Butterworth low-pass filter to a specific value.
static float reset_first_order_low_pass(struct FirstOrderLowPass *filter, const float value)
Reset the first order low-pass filter to a specific value.
static float get_butterworth_4_low_pass(const Butterworth4LowPass *filter)
Get current value of the fourth order Butterworth low pass filter.
static void init_first_order_low_pass(struct FirstOrderLowPass *filter, float tau, const float sample_time, float value)
Init first order low pass filter.
static float update_first_order_low_pass(struct FirstOrderLowPass *filter, const float value)
Update first order low pass filter state with a new value.
static float update_second_order_low_pass(struct SecondOrderLowPass *filter, const float value)
Update second order low pass filter state with a new value.
static float reset_second_order_low_pass(struct SecondOrderLowPass *filter, const float value)
Reset the second order low-pass filter to a specific value.
static float get_first_order_low_pass(const struct FirstOrderLowPass *filter)
Get current value of the first order low pass filter.
static float update_butterworth_4_low_pass(Butterworth4LowPass *filter, const float value)
Update fourth order Butterworth low pass filter state with a new value.
struct SecondOrderLowPass lp1
float i[2]
input history
static void init_butterworth_4_low_pass(Butterworth4LowPass *filter, const float tau, const float sample_time, const float value)
Init a fourth order Butterworth filter.
static void init_second_order_low_pass(struct SecondOrderLowPass *filter, const float tau, const float Q, const float sample_time, float value)
Init second order low pass filter.
Fourth order Butterworth low pass filter.
First order low pass filter structure.
Second order low pass filter structure.
uint16_t foo
Definition main_demo5.c:58