27 #ifndef LOW_PASS_FILTER_H
28 #define LOW_PASS_FILTER_H
33 #define INT32_FILT_FRAC 8
141 float K = sample_time / (2.0f * tau);
142 float poly = K * K + K / Q + 1.0f;
143 filter->
a[0] = 2.0f * (K * K - 1.0f) / poly;
144 filter->
a[1] = (K * K - K / Q + 1.0f) / poly;
145 filter->
b[0] = K * K / poly;
146 filter->
b[1] = 2.0f * filter->
b[0];
147 filter->
i[0] = filter->
i[1] = filter->
o[0] = filter->
o[1] = value;
158 float out = filter->
b[0] * value
159 + filter->
b[1] * filter->
i[0]
160 + filter->
b[0] * filter->
i[1]
161 - filter->
a[0] * filter->
o[0]
162 - filter->
a[1] * filter->
o[1];
163 filter->
i[1] = filter->
i[0];
164 filter->
i[0] = value;
165 filter->
o[1] = filter->
o[0];
197 float sample_time,
int32_t value)
200 float tau = 7.0f / (44.0f * cut_off);
201 float K = sample_time / (2.0f * tau);
202 float poly = K * K + K / Q + 1.0f;
205 filter_temp.
a[0] = 2.0f * (K * K - 1.0f) / poly;
206 filter_temp.
a[1] = (K * K - K / Q + 1.0f) / poly;
207 filter_temp.
b[0] = K * K / poly;
208 filter_temp.
b[1] = 2.0f * filter_temp.
b[0];
209 loop_gain_f = 1.0f / filter_temp.
b[0];
214 filter->
b[1] = 2 * filter->
b[0];
215 filter->
i[0] = filter->
i[1] = filter->
o[0] = filter->
o[1] = value;
228 + filter->
b[1] * filter->
i[0]
229 + filter->
b[0] * filter->
i[1]
230 - filter->
a[0] * filter->
o[0]
231 - filter->
a[1] * filter->
o[1];
233 filter->
i[1] = filter->
i[0];
234 filter->
i[0] = value;
235 filter->
o[1] = filter->
o[0];
384 return filter->
lp2.
o[0];
437 return filter->
lp2.
o[0];
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 float update_butterworth_2_low_pass(Butterworth2LowPass *filter, float value)
Update second order Butterworth low pass filter state with a new value.
static void init_butterworth_2_low_pass(Butterworth2LowPass *filter, float tau, float sample_time, float value)
Init a second order Butterworth filter.
static float update_second_order_low_pass(struct SecondOrderLowPass *filter, float value)
Update second order low pass filter state with a new value.
Fourth order Butterworth low pass filter.
int32_t b[2]
numerator gains
static void init_butterworth_4_low_pass(Butterworth4LowPass *filter, float tau, float sample_time, float value)
Init a fourth order Butterworth filter.
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.
First order low pass filter structure.
int32_t loop_gain
loop gain
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).
Fourth order Butterworth low pass filter(fixed point version).
#define BFP_OF_REAL(_vr, _frac)
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).
int32_t o[2]
output history
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).
struct SecondOrderLowPass_int lp1
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)...
static float get_butterworth_2_low_pass(Butterworth2LowPass *filter)
Get current value of the second order Butterworth low pass filter.
static float get_first_order_low_pass(struct FirstOrderLowPass *filter)
Get current value of the first order low pass filter.
float a[2]
denominator gains
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 float get_butterworth_4_low_pass(Butterworth4LowPass *filter)
Get current value of the fourth order Butterworth low pass filter.
static float update_butterworth_4_low_pass(Butterworth4LowPass *filter, float value)
Update fourth order Butterworth low pass filter state with a new value.
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).
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)...
static void init_first_order_low_pass(struct FirstOrderLowPass *filter, float tau, float sample_time, float value)
Init first order low pass filter.
struct SecondOrderLowPass lp2
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).
Second order low pass filter structure.
float b[2]
numerator gains
static float get_second_order_low_pass(struct SecondOrderLowPass *filter)
Get current value of the second order low pass filter.
int32_t a[2]
denominator gains
int32_t i[2]
input history
struct SecondOrderLowPass_int lp2
struct SecondOrderLowPass lp1
Paparazzi fixed point algebra.
static float update_first_order_low_pass(struct FirstOrderLowPass *filter, float value)
Update first order low pass filter state with a new value.