Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
complementary_filter.h File Reference

Implementation of complementary filters (first order, second order, and Butterworth variants) More...

#include "std.h"
#include "filters/low_pass_filter.h"
+ Include dependency graph for complementary_filter.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  FirstOrderComplementary
 First order complementary filter structure. More...
 
struct  SecondOrderComplementary
 Second order complementary filter structure. More...
 
struct  Butterworth4Complementary
 4th order Butterworth complementary filter structure. More...
 

Typedefs

typedef struct SecondOrderComplementary Butterworth2Complementary
 

Functions

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 update_first_order_complementary (struct FirstOrderComplementary *filter, float value_x, float value_y)
 Update the first order 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 get_first_order_complementary (const struct FirstOrderComplementary *filter)
 Get current value of the first order complementary filter.
 
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_second_order_complementary (struct SecondOrderComplementary *filter, float value_x, float value_y)
 Update the second order complementary filter with new input values.
 
static float reset_second_order_complementary (struct SecondOrderComplementary *filter, float value)
 Reset the second order complementary filter to a specific value.
 
static float get_second_order_complementary (const struct SecondOrderComplementary *filter)
 Get current value of the second order complementary 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 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 void reset_butterworth_2_complementary (Butterworth2Complementary *filter, float value)
 Reset the Butterworth 2nd order complementary filter to a specific value.
 
static float get_butterworth_2_complementary (const Butterworth2Complementary *filter)
 Get current value of 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_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 float get_butterworth_4_complementary (const Butterworth4Complementary *filter)
 Get current value of the Butterworth 4th order low-pass complementary filter.
 

Detailed Description

Implementation of complementary filters (first order, second order, and Butterworth variants)

Provides structures and functions to initialize, update, reset, and get outputs from first order and second order complementary filters, as well as Butterworth complementary filters.

FIXME: This implementation of complementary filters forces user to first integrate or differentiate the signals outside of the filter before passing them in. Consider extending the filter to handle integration and differentiation internally. Maybe implement cascaded complementary filters for this purpose.

Author
Justin Dubois j.p.g.nosp@m..dub.nosp@m.ois@s.nosp@m.tude.nosp@m.nt.tu.nosp@m.delf.nosp@m.t.nl

Definition in file complementary_filter.h.


Data Structure Documentation

◆ FirstOrderComplementary

struct FirstOrderComplementary

First order complementary filter structure.

This structure contains two first order low-pass filters, one for the high-pass path and one for the low-pass path.

Definition at line 49 of file complementary_filter.h.

+ Collaboration diagram for FirstOrderComplementary:
Data Fields
struct FirstOrderLowPass x_lp_filter
struct FirstOrderLowPass y_lp_filter

◆ SecondOrderComplementary

struct SecondOrderComplementary

Second order complementary filter structure.

This structure contains two second order low-pass filters, one for the high-pass path and one for the low-pass path.

Definition at line 118 of file complementary_filter.h.

+ Collaboration diagram for SecondOrderComplementary:
Data Fields
struct SecondOrderLowPass x_lp_filter
struct SecondOrderLowPass y_lp_filter

◆ Butterworth4Complementary

struct Butterworth4Complementary

4th order Butterworth complementary filter structure.

This structure contains two 4th order Butterworth low-pass filters, one for the high-pass path and one for the low-pass path.

Definition at line 243 of file complementary_filter.h.

+ Collaboration diagram for Butterworth4Complementary:
Data Fields
Butterworth4LowPass x_lp_filter
Butterworth4LowPass y_lp_filter

Typedef Documentation

◆ Butterworth2Complementary

Function Documentation

◆ get_butterworth_2_complementary()

static float get_butterworth_2_complementary ( const Butterworth2Complementary filter)
inlinestatic

Get current value of the Butterworth 2nd order low-pass complementary filter.

Parameters
filterComplementary filter struct
Returns
Current output value of the filter

Definition at line 232 of file complementary_filter.h.

References get_second_order_complementary().

Referenced by get_butterworth_2_complementary_array(), get_butterworth_2_complementary_rates(), and get_butterworth_2_complementary_vect3().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_butterworth_4_complementary()

static float get_butterworth_4_complementary ( const Butterworth4Complementary filter)
inlinestatic

Get current value of the Butterworth 4th order low-pass complementary filter.

Parameters
filterComplementary filter struct
Returns
Current output value of the filter

Definition at line 293 of file complementary_filter.h.

References foo, get_butterworth_4_low_pass(), SecondOrderLowPass::i, Butterworth4LowPass::lp1, Butterworth4Complementary::x_lp_filter, and Butterworth4Complementary::y_lp_filter.

Referenced by get_butterworth_4_complementary_array(), get_butterworth_4_complementary_rates(), and get_butterworth_4_complementary_vect3().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_first_order_complementary()

static float get_first_order_complementary ( const struct FirstOrderComplementary filter)
inlinestatic

Get current value of the first order complementary filter.

Parameters
filterComplementary filter struct
Returns
Current output value of the filter

Definition at line 105 of file complementary_filter.h.

References foo, get_first_order_low_pass(), FirstOrderLowPass::last_in, FirstOrderComplementary::x_lp_filter, and FirstOrderComplementary::y_lp_filter.

Referenced by get_first_order_complementary_array(), get_first_order_complementary_rates(), and get_first_order_complementary_vect3().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_second_order_complementary()

static float get_second_order_complementary ( const struct SecondOrderComplementary filter)
inlinestatic

Get current value of the second order complementary filter.

Parameters
filterComplementary filter struct
Returns
Current output value of the filter

Definition at line 177 of file complementary_filter.h.

References foo, get_second_order_low_pass(), SecondOrderLowPass::i, SecondOrderComplementary::x_lp_filter, and SecondOrderComplementary::y_lp_filter.

Referenced by get_butterworth_2_complementary().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init_butterworth_2_complementary()

static void init_butterworth_2_complementary ( Butterworth2Complementary filter,
float  cut_off,
float  sample_time,
float  value 
)
inlinestatic

Initialize the Butterworth 2nd order low-pass complementary filter.

Parameters
filterComplementary filter struct
cut_offTime constant of the low-pass filter
sample_timeSampling period
valueInitial value for filter history

Definition at line 193 of file complementary_filter.h.

References foo, and init_second_order_complementary().

Referenced by init_butterworth_2_complementary_array(), and init_butterworth_2_complementary_vect3().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init_butterworth_4_complementary()

static void init_butterworth_4_complementary ( Butterworth4Complementary filter,
float  cut_off,
float  sample_time,
float  value 
)
inlinestatic

Initialize the Butterworth 4th order low-pass complementary filter.

Parameters
filterComplementary filter struct
cut_offTime constant of the low-pass filter
sample_timeSampling period
valueInitial value for filter history

Definition at line 255 of file complementary_filter.h.

References foo, init_butterworth_4_low_pass(), Butterworth4Complementary::x_lp_filter, and Butterworth4Complementary::y_lp_filter.

Referenced by init_butterworth_4_complementary_array(), and init_butterworth_4_complementary_vect3().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init_first_order_complementary()

static void init_first_order_complementary ( struct FirstOrderComplementary filter,
float  cut_off,
float  sample_time,
float  value 
)
inlinestatic

Initialize the first order complementary filter.

Parameters
filterComplementary filter struct
cut_offTime constant of the low-pass filter
sample_timeSampling period
valueInitial value for filter history

Definition at line 61 of file complementary_filter.h.

References foo, init_first_order_low_pass(), FirstOrderComplementary::x_lp_filter, and FirstOrderComplementary::y_lp_filter.

Referenced by init_first_order_complementary_array(), and init_first_order_complementary_vect3().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init_second_order_complementary()

static void init_second_order_complementary ( struct SecondOrderComplementary filter,
float  cut_off,
float  Q,
float  sample_time,
float  value 
)
inlinestatic

Initialize the second order complementary filter.

Parameters
filterComplementary filter struct
cut_offTime constant of the low-pass filter
QQ factor of the low-pass filter
sample_timeSampling period
valueInitial value for filter history

Definition at line 131 of file complementary_filter.h.

References foo, init_second_order_low_pass(), SecondOrderComplementary::x_lp_filter, and SecondOrderComplementary::y_lp_filter.

Referenced by init_butterworth_2_complementary().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reset_butterworth_2_complementary()

static void reset_butterworth_2_complementary ( Butterworth2Complementary filter,
float  value 
)
inlinestatic

Reset the Butterworth 2nd order complementary filter to a specific value.

Parameters
filterComplementary filter struct
valueValue to reset the filter to

Definition at line 222 of file complementary_filter.h.

References reset_second_order_complementary().

Referenced by reset_butterworth_2_complementary_array(), reset_butterworth_2_complementary_rates(), and reset_butterworth_2_complementary_vect3().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reset_butterworth_4_complementary()

static void reset_butterworth_4_complementary ( Butterworth4Complementary filter,
float  value 
)
inlinestatic

Reset the Butterworth 4th order complementary filter to a specific value.

Parameters
filterComplementary filter struct
valueValue to reset the filter to

Definition at line 282 of file complementary_filter.h.

References reset_butterworth_4_low_pass(), Butterworth4Complementary::x_lp_filter, and Butterworth4Complementary::y_lp_filter.

Referenced by reset_butterworth_4_complementary_array(), reset_butterworth_4_complementary_rates(), and reset_butterworth_4_complementary_vect3().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reset_first_order_complementary()

static float reset_first_order_complementary ( struct FirstOrderComplementary filter,
float  value 
)
inlinestatic

Reset the first order complementary filter to a specific value.

Parameters
filterComplementary filter struct
valueValue to reset the filter to
Returns
The reset value

Definition at line 92 of file complementary_filter.h.

References reset_first_order_low_pass(), FirstOrderComplementary::x_lp_filter, and FirstOrderComplementary::y_lp_filter.

Referenced by reset_first_order_complementary_array(), reset_first_order_complementary_rates(), and reset_first_order_complementary_vect3().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reset_second_order_complementary()

static float reset_second_order_complementary ( struct SecondOrderComplementary filter,
float  value 
)
inlinestatic

Reset the second order complementary filter to a specific value.

Parameters
filterComplementary filter struct
valueValue to reset the filter to
Returns
The reset value

Definition at line 163 of file complementary_filter.h.

References reset_second_order_low_pass(), SecondOrderComplementary::x_lp_filter, and SecondOrderComplementary::y_lp_filter.

Referenced by reset_butterworth_2_complementary().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ update_butterworth_2_complementary()

static float update_butterworth_2_complementary ( Butterworth2Complementary filter,
float  value_x,
float  value_y 
)
inlinestatic

Update the Butterworth 2nd order low-pass complementary filter with new input values.

Parameters
filterComplementary filter struct
value_xNew input value from the high-pass path
value_yNew input value from the low-pass path
Returns
New filtered output value

Definition at line 211 of file complementary_filter.h.

References foo, and update_second_order_complementary().

Referenced by update_butterworth_2_complementary_array(), update_butterworth_2_complementary_rates(), and update_butterworth_2_complementary_vect3().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ update_butterworth_4_complementary()

static float update_butterworth_4_complementary ( Butterworth4Complementary filter,
float  value_x,
float  value_y 
)
inlinestatic

Update the Butterworth 4th order low-pass complementary filter with new input values.

Parameters
filterComplementary filter struct
value_xNew input value from the high-pass path
value_yNew input value from the low-pass path
Returns
New filtered output value

Definition at line 269 of file complementary_filter.h.

References foo, SecondOrderLowPass::i, Butterworth4LowPass::lp1, update_butterworth_4_low_pass(), Butterworth4Complementary::x_lp_filter, and Butterworth4Complementary::y_lp_filter.

Referenced by update_butterworth_4_complementary_array(), update_butterworth_4_complementary_rates(), and update_butterworth_4_complementary_vect3().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ update_first_order_complementary()

static float update_first_order_complementary ( struct FirstOrderComplementary filter,
float  value_x,
float  value_y 
)
inlinestatic

Update the first order complementary filter with new input values.

Parameters
filterComplementary filter struct
value_xNew input value from the high-pass path
value_yNew input value from the low-pass path
Returns
New filtered output value

Definition at line 76 of file complementary_filter.h.

References foo, FirstOrderLowPass::last_in, update_first_order_low_pass(), FirstOrderComplementary::x_lp_filter, and FirstOrderComplementary::y_lp_filter.

Referenced by update_first_order_complementary_array(), update_first_order_complementary_rates(), and update_first_order_complementary_vect3().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ update_second_order_complementary()

static float update_second_order_complementary ( struct SecondOrderComplementary filter,
float  value_x,
float  value_y 
)
inlinestatic

Update the second order complementary filter with new input values.

Parameters
filterComplementary filter struct
value_xNew input value from the high-pass path
value_yNew input value from the low-pass path
Returns
New filtered output value

Definition at line 147 of file complementary_filter.h.

References foo, SecondOrderLowPass::i, update_second_order_low_pass(), SecondOrderComplementary::x_lp_filter, and SecondOrderComplementary::y_lp_filter.

Referenced by update_butterworth_2_complementary().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: