30#ifndef LOW_PASS_FILTER_H
31#define LOW_PASS_FILTER_H
36#define INT32_FILT_FRAC 8
175 float poly =
K *
K +
K / Q + 1.0f;
176 filter->
a[0] = 2.0f * (
K *
K - 1.0f) /
poly;
177 filter->
a[1] = (
K *
K -
K / Q + 1.0f) /
poly;
179 filter->
b[1] = 2.0f * filter->
b[0];
180 filter->
i[0] = filter->
i[1] = filter->
o[0] = filter->
o[1] = value;
192 filter->
i[0] = filter->
i[1] = filter->
o[0] = filter->
o[1] = value;
204 float out = filter->
b[0] * value
205 + filter->
b[1] * filter->
i[0]
206 + filter->
b[0] * filter->
i[1]
207 - filter->
a[0] * filter->
o[0]
208 - filter->
a[1] * filter->
o[1];
209 filter->
i[1] = filter->
i[0];
210 filter->
i[0] = value;
211 filter->
o[1] = filter->
o[0];
247 float tau = 7.0f / (44.0f *
cut_off);
249 float poly =
K *
K +
K / Q + 1.0f;
261 filter->
b[1] = 2 * filter->
b[0];
262 filter->
i[0] = filter->
i[1] = filter->
o[0] = filter->
o[1] = value;
275 + filter->
b[1] * filter->
i[0]
276 + filter->
b[0] * filter->
i[1]
277 - filter->
a[0] * filter->
o[0]
278 - filter->
a[1] * filter->
o[1];
280 filter->
i[1] = filter->
i[0];
281 filter->
i[0] = value;
282 filter->
o[1] = filter->
o[0];
446 return filter->
lp2.
o[0];
458 filter->
lp2.
o[0] = filter->
lp2.
o[1] = value;
512 return filter->
lp2.
o[0];
#define BFP_OF_REAL(_vr, _frac)
int32_t loop_gain
loop gain
static float get_second_order_low_pass(const struct SecondOrderLowPass *filter)
Get current value of the second order low pass filter.
static int32_t get_second_order_low_pass_int(const struct SecondOrderLowPass_int *filter)
Get current value of the second order low pass filter(fixed point version).
static int32_t update_second_order_low_pass_int(struct SecondOrderLowPass_int *filter, const int32_t value)
Update second order low pass filter state with a new value(fixed point version).
static void update_first_order_low_pass_tau(struct FirstOrderLowPass *filter, const float tau, const float sample_time)
Update time constant (tau parameter) for first order low pass filter.
static int32_t get_butterworth_4_low_pass_int(const Butterworth4LowPass_int *filter)
Get current value of the fourth order Butterworth low pass filter(fixed point version).
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 int32_t update_butterworth_2_low_pass_int(Butterworth2LowPass_int *filter, const int32_t value)
Update second order Butterworth low pass filter state with a new value(fixed point version).
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.
struct SecondOrderLowPass lp2
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 void init_butterworth_2_low_pass(Butterworth2LowPass *filter, const float tau, const float sample_time, const float value)
Init a second order Butterworth filter.
static int32_t get_butterworth_2_low_pass_int(const Butterworth2LowPass_int *filter)
Get current value of the second order Butterworth low pass filter(fixed point version).
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 reset_butterworth_2_low_pass(Butterworth2LowPass *filter, const float value)
Reset a Butterworth low-pass filter to a specific value.
float a[2]
denominator gains
static float get_first_order_low_pass(const struct FirstOrderLowPass *filter)
Get current value of the first order low pass filter.
struct SecondOrderLowPass_int lp1
int32_t o[2]
output history
static void init_butterworth_2_low_pass_int(Butterworth2LowPass_int *filter, const float cut_off, const float sample_time, int32_t value)
Init a second order Butterworth filter.
static float update_butterworth_2_low_pass(Butterworth2LowPass *filter, const float value)
Update second order Butterworth low pass filter state with a new value.
int32_t b[2]
numerator gains
static int32_t update_butterworth_4_low_pass_int(Butterworth4LowPass_int *filter, const int32_t value)
Update fourth order Butterworth low pass filter state with a new value(fixed point version).
static void init_second_order_low_pass_int(struct SecondOrderLowPass_int *filter, const float cut_off, const float Q, float sample_time, int32_t value)
Init second order low pass filter(fixed point version).
struct SecondOrderLowPass_int lp2
static float update_butterworth_4_low_pass(Butterworth4LowPass *filter, const float value)
Update fourth order Butterworth low pass filter state with a new value.
static void init_butterworth_4_low_pass_int(Butterworth4LowPass_int *filter, const float cut_off, const float sample_time, int32_t value)
Init a fourth order Butterworth filter(fixed point version).
int32_t i[2]
input history
float b[2]
numerator gains
struct SecondOrderLowPass lp1
int32_t a[2]
denominator gains
static float get_butterworth_2_low_pass(const Butterworth2LowPass *filter)
Get current value of the second order Butterworth low pass filter.
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.
Fourth order Butterworth low pass filter(fixed point version).
First order low pass filter structure.
Second order low pass filter structure.
Paparazzi fixed point algebra.
int int32_t
Typedef defining 32 bit int type.