Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
low_pass_filter.h File Reference

Simple first order low pass filter with bilinear transform. More...

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

Go to the source code of this file.

Data Structures

struct  FirstOrderLowPass
 First order low pass filter structure. More...
 
struct  SecondOrderLowPass
 Second order low pass filter structure. More...
 
struct  SecondOrderLowPass_int
 
struct  Butterworth4LowPass
 Fourth order Butterworth low pass filter. More...
 
struct  Butterworth4LowPass_int
 Fourth order Butterworth low pass filter(fixed point version). More...
 

Macros

#define INT32_FILT_FRAC   8
 

Typedefs

typedef struct SecondOrderLowPass Butterworth2LowPass
 Second order Butterworth low pass filter. More...
 
typedef struct SecondOrderLowPass_int Butterworth2LowPass_int
 Second order Butterworth low pass filter(fixed point version). More...
 

Functions

static void init_first_order_low_pass (struct FirstOrderLowPass *filter, float tau, float sample_time, float value)
 Init first order low pass filter. More...
 
static float update_first_order_low_pass (struct FirstOrderLowPass *filter, float value)
 Update first order low pass filter state with a new value. More...
 
static float get_first_order_low_pass (struct FirstOrderLowPass *filter)
 Get current value of the first order low pass filter. More...
 
static void update_first_order_low_pass_tau (struct FirstOrderLowPass *filter, float tau, float sample_time)
 Update time constant (tau parameter) for first order low pass filter. More...
 
static void init_second_order_low_pass (struct SecondOrderLowPass *filter, float tau, float Q, float sample_time, float value)
 Init second order low pass filter. More...
 
static float update_second_order_low_pass (struct SecondOrderLowPass *filter, float value)
 Update second order low pass filter state with a new value. More...
 
static float get_second_order_low_pass (struct SecondOrderLowPass *filter)
 Get current value of the second order low pass filter. More...
 
static void init_second_order_low_pass_int (struct SecondOrderLowPass_int *filter, float cut_off, float Q, float sample_time, int32_t value)
 Init second order low pass filter(fixed point version). More...
 
static int32_t update_second_order_low_pass_int (struct SecondOrderLowPass_int *filter, int32_t value)
 Update second order low pass filter state with a new value(fixed point version). More...
 
static int32_t get_second_order_low_pass_int (struct SecondOrderLowPass_int *filter)
 Get current value of the second order low pass filter(fixed point version). More...
 
static void init_butterworth_2_low_pass (Butterworth2LowPass *filter, float tau, float sample_time, float value)
 Init a second order Butterworth filter. More...
 
static float update_butterworth_2_low_pass (Butterworth2LowPass *filter, float value)
 Update second order Butterworth low pass filter state with a new value. More...
 
static float get_butterworth_2_low_pass (Butterworth2LowPass *filter)
 Get current value of the second order Butterworth low pass filter. More...
 
static void init_butterworth_2_low_pass_int (Butterworth2LowPass_int *filter, float cut_off, float sample_time, int32_t value)
 Init a second order Butterworth filter. More...
 
static int32_t update_butterworth_2_low_pass_int (Butterworth2LowPass_int *filter, int32_t value)
 Update second order Butterworth low pass filter state with a new value(fixed point version). More...
 
static int32_t get_butterworth_2_low_pass_int (Butterworth2LowPass_int *filter)
 Get current value of the second order Butterworth low pass filter(fixed point version). More...
 
static void init_butterworth_4_low_pass (Butterworth4LowPass *filter, float tau, float sample_time, float value)
 Init a fourth order Butterworth filter. More...
 
static float update_butterworth_4_low_pass (Butterworth4LowPass *filter, float value)
 Update fourth order Butterworth low pass filter state with a new value. More...
 
static float get_butterworth_4_low_pass (Butterworth4LowPass *filter)
 Get current value of the fourth order Butterworth low pass filter. More...
 
static void init_butterworth_4_low_pass_int (Butterworth4LowPass_int *filter, float cut_off, float sample_time, int32_t value)
 Init a fourth order Butterworth filter(fixed point version). More...
 
static int32_t update_butterworth_4_low_pass_int (Butterworth4LowPass_int *filter, int32_t value)
 Update fourth order Butterworth low pass filter state with a new value(fixed point version). More...
 
static int32_t get_butterworth_4_low_pass_int (Butterworth4LowPass_int *filter)
 Get current value of the fourth order Butterworth low pass filter(fixed point version). More...
 

Detailed Description

Simple first order low pass filter with bilinear transform.

Definition in file low_pass_filter.h.


Data Structure Documentation

◆ FirstOrderLowPass

struct FirstOrderLowPass

First order low pass filter structure.

using bilinear z transform

Definition at line 39 of file low_pass_filter.h.

Data Fields
float last_in
float last_out
float time_const

◆ SecondOrderLowPass

struct SecondOrderLowPass

Second order low pass filter structure.

using biquad filter with bilinear z transform

http://en.wikipedia.org/wiki/Digital_biquad_filter http://www.earlevel.com/main/2003/03/02/the-bilinear-z-transform

Laplace continious form:

            1

H(s) = ----------------— s^2/w^2 + s/w*Q + 1

Polynomial discrete form:

   b0 + b1 z^-1 + b2 z^-2

H(z) = -------------------— a0 + a1 z^-1 + a2 z^-2

with: a0 = 1 a1 = 2*(K^2 - 1) / (K^2 + K/Q + 1) a2 = (K^2 - K/Q + 1) / (K^2 + K/Q + 1) b0 = K^2 / (K^2 + K/Q + 1) b1 = 2*b0 b2 = b0 K = tan(pi*Fc/Fs) ~ pi*Fc/Fs = Ts/(2*tau) Fc: cutting frequency Fs: sampling frequency Ts: sampling period tau: time constant (tau = 1/(2*pi*Fc)) Q: gain at cutoff frequency

Note that b[0]=b[2], so we don't need to save b[2]

Definition at line 136 of file low_pass_filter.h.

Data Fields
float a[2] denominator gains
float b[2] numerator gains
float i[2] input history
float o[2] output history

◆ SecondOrderLowPass_int

struct SecondOrderLowPass_int

Definition at line 194 of file low_pass_filter.h.

Data Fields
int32_t a[2] denominator gains
int32_t b[2] numerator gains
int32_t i[2] input history
int32_t loop_gain loop gain
int32_t o[2] output history

◆ Butterworth4LowPass

struct Butterworth4LowPass

Fourth order Butterworth low pass filter.

using two cascaded second order filters

Definition at line 353 of file low_pass_filter.h.

+ Collaboration diagram for Butterworth4LowPass:
Data Fields
struct SecondOrderLowPass lp1
struct SecondOrderLowPass lp2

◆ Butterworth4LowPass_int

struct Butterworth4LowPass_int

Fourth order Butterworth low pass filter(fixed point version).

using two cascaded second order filters

Definition at line 405 of file low_pass_filter.h.

+ Collaboration diagram for Butterworth4LowPass_int:
Data Fields
struct SecondOrderLowPass_int lp1
struct SecondOrderLowPass_int lp2

Macro Definition Documentation

◆ INT32_FILT_FRAC

#define INT32_FILT_FRAC   8

Definition at line 33 of file low_pass_filter.h.

Typedef Documentation

◆ Butterworth2LowPass

Second order Butterworth low pass filter.

Definition at line 259 of file low_pass_filter.h.

◆ Butterworth2LowPass_int

Second order Butterworth low pass filter(fixed point version).

Definition at line 301 of file low_pass_filter.h.

Function Documentation

◆ get_butterworth_2_low_pass()

static float get_butterworth_2_low_pass ( Butterworth2LowPass filter)
inlinestatic

Get current value of the second order Butterworth low pass filter.

Parameters
filtersecond order Butterworth low pass filter structure
Returns
current value of the filter

Definition at line 301 of file low_pass_filter.h.

Referenced by airspeed_ms45xx_i2c_change_tau(), and reinit_cf2().

+ Here is the caller graph for this function:

◆ get_butterworth_2_low_pass_int()

static int32_t get_butterworth_2_low_pass_int ( Butterworth2LowPass_int filter)
inlinestatic

Get current value of the second order Butterworth low pass filter(fixed point version).

Parameters
filtersecond order Butterworth low pass filter structure
Returns
current value of the filter

Definition at line 344 of file low_pass_filter.h.

References SecondOrderLowPass_int::o.

Referenced by mavlink_send_highres_imu().

+ Here is the caller graph for this function:

◆ get_butterworth_4_low_pass()

static float get_butterworth_4_low_pass ( Butterworth4LowPass filter)
inlinestatic

Get current value of the fourth order Butterworth low pass filter.

Parameters
filterfourth order Butterworth low pass filter structure
Returns
current value of the filter

Definition at line 396 of file low_pass_filter.h.

References Butterworth4LowPass::lp2, and SecondOrderLowPass::o.

Referenced by reinit_cf4().

+ Here is the caller graph for this function:

◆ get_butterworth_4_low_pass_int()

static int32_t get_butterworth_4_low_pass_int ( Butterworth4LowPass_int filter)
inlinestatic

Get current value of the fourth order Butterworth low pass filter(fixed point version).

Parameters
filterfourth order Butterworth low pass filter structure
Returns
current value of the filter

Definition at line 449 of file low_pass_filter.h.

References Butterworth4LowPass_int::lp2, and SecondOrderLowPass_int::o.

◆ get_first_order_low_pass()

static float get_first_order_low_pass ( struct FirstOrderLowPass filter)
inlinestatic

Get current value of the first order low pass filter.

Parameters
filterfirst order low pass filter structure
Returns
current value of the filter

Definition at line 84 of file low_pass_filter.h.

References FirstOrderLowPass::last_out.

◆ get_second_order_low_pass()

static float get_second_order_low_pass ( struct SecondOrderLowPass filter)
inlinestatic

Get current value of the second order low pass filter.

Parameters
filtersecond order low pass filter structure
Returns
current value of the filter

Definition at line 189 of file low_pass_filter.h.

References SecondOrderLowPass::o.

◆ get_second_order_low_pass_int()

static int32_t get_second_order_low_pass_int ( struct SecondOrderLowPass_int filter)
inlinestatic

Get current value of the second order low pass filter(fixed point version).

Parameters
filtersecond order low pass filter structure
Returns
current value of the filter

Definition at line 259 of file low_pass_filter.h.

◆ init_butterworth_2_low_pass()

static void init_butterworth_2_low_pass ( Butterworth2LowPass filter,
float  tau,
float  sample_time,
float  value 
)
inlinestatic

Init a second order Butterworth filter.

based on the generic second order filter with Q = 0.7071 = 1/sqrt(2)

http://en.wikipedia.org/wiki/Butterworth_filter

Parameters
filtersecond order Butterworth low pass filter structure
tautime constant of the second order low pass filter
sample_timesampling period of the signal
valueinitial value of the filter

Definition at line 280 of file low_pass_filter.h.

References init_second_order_low_pass().

Referenced by adaptive_notch_filter_init(), airspeed_ms45xx_i2c_change_tau(), airspeed_uavcan_init(), approach_moving_target_set_low_pass_freq(), eff_scheduling_rotwing_init(), ekf_aw_wrapper_init(), ground_detect_init(), guidance_indi_enter(), guidance_indi_init(), guidance_indi_quadplane_init(), imu_init(), indi_init_filters(), init_cf2(), init_filter(), init_filters(), ms45xx_i2c_init(), reinit_cf2(), sdp3x_init(), and stabilization_indi_update_filt_freq().

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

◆ init_butterworth_2_low_pass_int()

static void init_butterworth_2_low_pass_int ( Butterworth2LowPass_int filter,
float  cut_off,
float  sample_time,
int32_t  value 
)
inlinestatic

Init a second order Butterworth filter.

based on the generic second order filter with Q = 0.7071 = 1/sqrt(2)

http://en.wikipedia.org/wiki/Butterworth_filter

Parameters
filtersecond order Butterworth low pass filter structure
cut_offCutoff frequency of the filter with -3dB
sample_timesampling period of the signal
valueinitial value of the filter

Definition at line 322 of file low_pass_filter.h.

References init_second_order_low_pass_int().

Referenced by hff_init(), jevois_mavlink_filter_init(), and stabilization_attitude_heli_indi_init().

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

◆ init_butterworth_4_low_pass()

static void init_butterworth_4_low_pass ( Butterworth4LowPass filter,
float  tau,
float  sample_time,
float  value 
)
inlinestatic

Init a fourth order Butterworth filter.

based on two generic second order filters with Q1 = 1.30651 and Q2 = 0.541184

http://en.wikipedia.org/wiki/Butterworth_filter

Parameters
filterfourth order Butterworth low pass filter structure
tautime constant of the fourth order low pass filter
sample_timesampling period of the signal
valueinitial value of the filter

Definition at line 371 of file low_pass_filter.h.

References init_second_order_low_pass(), Butterworth4LowPass::lp1, and Butterworth4LowPass::lp2.

Referenced by init_cf4(), and reinit_cf4().

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

◆ init_butterworth_4_low_pass_int()

static void init_butterworth_4_low_pass_int ( Butterworth4LowPass_int filter,
float  cut_off,
float  sample_time,
int32_t  value 
)
inlinestatic

Init a fourth order Butterworth filter(fixed point version).

based on two generic second order filters with Q1 = 1.30651 and Q2 = 0.541184

http://en.wikipedia.org/wiki/Butterworth_filter

Parameters
filterfourth order Butterworth low pass filter structure
cut_offCutoff frequency of the filter with -3dB
sample_timesampling period of the signal
valueinitial value of the filter

Definition at line 423 of file low_pass_filter.h.

References init_second_order_low_pass_int(), Butterworth4LowPass_int::lp1, and Butterworth4LowPass_int::lp2.

+ Here is the call graph for this function:

◆ init_first_order_low_pass()

static void init_first_order_low_pass ( struct FirstOrderLowPass filter,
float  tau,
float  sample_time,
float  value 
)
inlinestatic

Init first order low pass filter.

Laplace transform in continious time: 1 H(s) = ------— 1 + tau*s

Parameters
filterfirst order low pass filter structure
tautime constant of the first order low pass filter
sample_timesampling period of the signal
valueinitial value of the filter

Definition at line 57 of file low_pass_filter.h.

References FirstOrderLowPass::last_in, FirstOrderLowPass::last_out, and FirstOrderLowPass::time_const.

Referenced by cloud_sensor_init(), indi_init_filters(), init_filters(), nps_fdm_init(), rpm_sensor_init(), stabilization_indi_simple_reset_r_filter_cutoff(), stabilization_indi_update_filt_freq(), and sys_id_chirp_init().

+ Here is the caller graph for this function:

◆ init_second_order_low_pass()

static void init_second_order_low_pass ( struct SecondOrderLowPass filter,
float  tau,
float  Q,
float  sample_time,
float  value 
)
inlinestatic

Init second order low pass filter.

Parameters
filtersecond order low pass filter structure
tautime constant of the second order low pass filter
QQ value of the second order low pass filter
sample_timesampling period of the signal
valueinitial value of the filter

Definition at line 152 of file low_pass_filter.h.

References SecondOrderLowPass::a, SecondOrderLowPass::b, SecondOrderLowPass::i, K, and SecondOrderLowPass::o.

Referenced by init_butterworth_2_low_pass(), and init_butterworth_4_low_pass().

+ Here is the caller graph for this function:

◆ init_second_order_low_pass_int()

static void init_second_order_low_pass_int ( struct SecondOrderLowPass_int filter,
float  cut_off,
float  Q,
float  sample_time,
int32_t  value 
)
inlinestatic

Init second order low pass filter(fixed point version).

Parameters
filtersecond order low pass filter structure
cut_offCutoff frequency of the filter with -3dB
QQ value of the second order low pass filter
sample_timesampling period of the signal
valueinitial value of the filter

Definition at line 210 of file low_pass_filter.h.

References SecondOrderLowPass::a, SecondOrderLowPass_int::a, SecondOrderLowPass::b, SecondOrderLowPass_int::b, BFP_OF_REAL, SecondOrderLowPass_int::i, INT32_FILT_FRAC, K, SecondOrderLowPass_int::loop_gain, and SecondOrderLowPass_int::o.

Referenced by init_butterworth_2_low_pass_int(), init_butterworth_4_low_pass_int(), and stabilization_init().

+ Here is the caller graph for this function:

◆ update_butterworth_2_low_pass()

static float update_butterworth_2_low_pass ( Butterworth2LowPass filter,
float  value 
)
inlinestatic

Update second order Butterworth low pass filter state with a new value.

Parameters
filtersecond order Butterworth low pass filter structure
valuenew input value of the filter
Returns
new filtered value

Definition at line 291 of file low_pass_filter.h.

References update_second_order_low_pass().

Referenced by adaptive_notch_filter_update(), airspeed_uavcan_cb(), eff_scheduling_rotwing_update_wing_angle(), ekf_aw_wrapper_fetch(), filter_pqr(), ground_detect_filter_accel(), guidance_indi_propagate_filters(), guidance_indi_quadplane_propagate_filters(), imu_accel_raw_cb(), imu_gyro_raw_cb(), lms_estimation(), ms45xx_i2c_event(), oneloop_andi_propagate_filters(), sdp3x_event(), and stabilization_indi_rate_run().

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

◆ update_butterworth_2_low_pass_int()

static int32_t update_butterworth_2_low_pass_int ( Butterworth2LowPass_int filter,
int32_t  value 
)
inlinestatic

Update second order Butterworth low pass filter state with a new value(fixed point version).

Parameters
filtersecond order Butterworth low pass filter structure
valuenew input value of the filter
Returns
new filtered value

Definition at line 334 of file low_pass_filter.h.

References update_second_order_low_pass_int().

Referenced by hff_propagate(), indi_apply_actuator_butterworth_filters(), indi_apply_measurement_butterworth_filters(), and jevois_mavlink_filter_periodic().

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

◆ update_butterworth_4_low_pass()

static float update_butterworth_4_low_pass ( Butterworth4LowPass filter,
float  value 
)
inlinestatic

Update fourth order Butterworth low pass filter state with a new value.

using two cascaded second order filters

Parameters
filterfourth order Butterworth low pass filter structure
valuenew input value of the filter
Returns
new filtered value

Definition at line 385 of file low_pass_filter.h.

References Butterworth4LowPass::lp1, Butterworth4LowPass::lp2, and update_second_order_low_pass().

Referenced by oneloop_andi_propagate_filters().

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

◆ update_butterworth_4_low_pass_int()

static int32_t update_butterworth_4_low_pass_int ( Butterworth4LowPass_int filter,
int32_t  value 
)
inlinestatic

Update fourth order Butterworth low pass filter state with a new value(fixed point version).

using two cascaded second order filters

Parameters
filterfourth order Butterworth low pass filter structure
valuenew input value of the filter
Returns
new filtered value

Definition at line 438 of file low_pass_filter.h.

References Butterworth4LowPass_int::lp1, Butterworth4LowPass_int::lp2, and update_second_order_low_pass_int().

+ Here is the call graph for this function:

◆ update_first_order_low_pass()

static float update_first_order_low_pass ( struct FirstOrderLowPass filter,
float  value 
)
inlinestatic

Update first order low pass filter state with a new value.

Parameters
filterfirst order low pass filter structure
valuenew input value of the filter
Returns
new filtered value

Definition at line 71 of file low_pass_filter.h.

References FirstOrderLowPass::last_in, FirstOrderLowPass::last_out, and FirstOrderLowPass::time_const.

Referenced by cloud_sensor_filtering(), gazebo_write(), rpm_sensor_periodic(), set_current_chirp_values(), and stabilization_indi_rate_run().

+ Here is the caller graph for this function:

◆ update_first_order_low_pass_tau()

static void update_first_order_low_pass_tau ( struct FirstOrderLowPass filter,
float  tau,
float  sample_time 
)
inlinestatic

Update time constant (tau parameter) for first order low pass filter.

Parameters
filterfirst order low pass filter structure
tautime constant of the first order low pass filter
sample_timesampling period of the signal

Definition at line 95 of file low_pass_filter.h.

References FirstOrderLowPass::time_const.

Referenced by cloud_sensor_update_tau().

+ Here is the caller graph for this function:

◆ update_second_order_low_pass()

static float update_second_order_low_pass ( struct SecondOrderLowPass filter,
float  value 
)
inlinestatic

Update second order low pass filter state with a new value.

Parameters
filtersecond order low pass filter structure
valuenew input value of the filter
Returns
new filtered value

Definition at line 170 of file low_pass_filter.h.

References SecondOrderLowPass::a, SecondOrderLowPass::b, SecondOrderLowPass::i, and SecondOrderLowPass::o.

Referenced by update_butterworth_2_low_pass(), and update_butterworth_4_low_pass().

+ Here is the caller graph for this function:

◆ update_second_order_low_pass_int()

static int32_t update_second_order_low_pass_int ( struct SecondOrderLowPass_int filter,
int32_t  value 
)
inlinestatic

Update second order low pass filter state with a new value(fixed point version).

Parameters
filtersecond order low pass filter structure
valuenew input value of the filter
Returns
new filtered value

Definition at line 239 of file low_pass_filter.h.

References SecondOrderLowPass_int::a, SecondOrderLowPass_int::b, SecondOrderLowPass_int::i, SecondOrderLowPass_int::loop_gain, and SecondOrderLowPass_int::o.

Referenced by stab_sp_to_eulers_f(), update_butterworth_2_low_pass_int(), and update_butterworth_4_low_pass_int().

+ Here is the caller graph for this function: