27 #ifndef LOW_PASS_FILTER_H
28 #define LOW_PASS_FILTER_H
33 #define INT32_FILT_FRAC 8
155 float K = tanf(sample_time / (2.0f * tau));
156 float poly =
K *
K +
K / Q + 1.0f;
157 filter->
a[0] = 2.0f * (
K *
K - 1.0f) / poly;
158 filter->
a[1] = (
K *
K -
K / Q + 1.0f) / poly;
159 filter->
b[0] =
K *
K / poly;
160 filter->
b[1] = 2.0f * filter->
b[0];
161 filter->
i[0] = filter->
i[1] = filter->
o[0] = filter->
o[1] = value;
172 float out = filter->
b[0] * value
173 + filter->
b[1] * filter->
i[0]
174 + filter->
b[0] * filter->
i[1]
175 - filter->
a[0] * filter->
o[0]
176 - filter->
a[1] * filter->
o[1];
177 filter->
i[1] = filter->
i[0];
178 filter->
i[0] = value;
179 filter->
o[1] = filter->
o[0];
211 float sample_time,
int32_t value)
214 float tau = 7.0f / (44.0f * cut_off);
215 float K = sample_time / (2.0f * tau);
216 float poly =
K *
K +
K / Q + 1.0f;
219 filter_temp.
a[0] = 2.0f * (
K *
K - 1.0f) / poly;
220 filter_temp.
a[1] = (
K *
K -
K / Q + 1.0f) / poly;
221 filter_temp.
b[0] =
K *
K / poly;
222 filter_temp.
b[1] = 2.0f * filter_temp.
b[0];
223 loop_gain_f = 1.0f / filter_temp.
b[0];
228 filter->
b[1] = 2 * filter->
b[0];
229 filter->
i[0] = filter->
i[1] = filter->
o[0] = filter->
o[1] = value;
242 + filter->
b[1] * filter->
i[0]
243 + filter->
b[0] * filter->
i[1]
244 - filter->
a[0] * filter->
o[0]
245 - filter->
a[1] * filter->
o[1];
247 filter->
i[1] = filter->
i[0];
248 filter->
i[0] = value;
249 filter->
o[1] = filter->
o[0];
398 return filter->
lp2.
o[0];
451 return filter->
lp2.
o[0];
#define BFP_OF_REAL(_vr, _frac)
int32_t loop_gain
loop gain
static float update_second_order_low_pass(struct SecondOrderLowPass *filter, float value)
Update second order low pass filter state with a new value.
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).
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.
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).
struct SecondOrderLowPass lp2
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).
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).
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.
static float get_butterworth_2_low_pass(Butterworth2LowPass *filter)
Get current value of the second order Butterworth low pass filter.
static float get_butterworth_4_low_pass(Butterworth4LowPass *filter)
Get current value of the fourth order Butterworth low pass filter.
static void init_butterworth_4_low_pass(Butterworth4LowPass *filter, float tau, float sample_time, float value)
Init a fourth order Butterworth filter.
static float get_second_order_low_pass(struct SecondOrderLowPass *filter)
Get current value of the second order low pass filter.
static float update_first_order_low_pass(struct FirstOrderLowPass *filter, float value)
Update first order low pass filter state with a new value.
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).
static void init_butterworth_2_low_pass(Butterworth2LowPass *filter, float tau, float sample_time, float value)
Init a second order Butterworth filter.
float a[2]
denominator gains
struct SecondOrderLowPass_int lp1
int32_t o[2]
output history
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.
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).
int32_t b[2]
numerator gains
static void init_first_order_low_pass(struct FirstOrderLowPass *filter, float tau, float sample_time, float value)
Init first order low pass filter.
static float update_butterworth_2_low_pass(Butterworth2LowPass *filter, float value)
Update second order Butterworth low pass filter state with a new value.
static float update_butterworth_4_low_pass(Butterworth4LowPass *filter, float value)
Update fourth order Butterworth low pass filter state with a new value.
struct SecondOrderLowPass_int lp2
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).
int32_t i[2]
input history
float b[2]
numerator gains
struct SecondOrderLowPass lp1
int32_t a[2]
denominator gains
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).
static float get_first_order_low_pass(struct FirstOrderLowPass *filter)
Get current value of the first 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.