4 * Created on: 24 jun. 2015
13 #include "common/filter.h"
14 #include "common/axis.h"
17 // PT1 Low Pass filter (when no dT specified it will be calculated from the cycleTime)
18 float filterApplyPt1(float input
, filterStatePt1_t
*filter
, uint8_t f_cut
, float dT
) {
20 // Pre calculate and store RC
22 filter
->RC
= 1.0f
/ ( 2.0f
* (float)M_PI
* f_cut
);
25 filter
->state
= filter
->state
+ dT
/ (filter
->RC
+ dT
) * (input
- filter
->state
);
30 // 7 Tap FIR filter as described here:
32 void filterApply7TapFIR(int16_t data
[]) {
33 int16_t FIRcoeff
[7] = { 12, 23, 40, 51, 52, 40, 38 }; // TODO - More coefficients needed. Now fixed to 1khz
34 static int16_t gyro_delay
[3][7] = { {0}, {0}, {0} };
38 // 7 tap FIR, <-20dB at >170Hz with looptime 1ms, groupdelay = 2.5ms
39 for (axis
= 0; axis
< XYZ_AXIS_COUNT
; axis
++) {
41 for (i
= 0; i
<= 5; i
++) {
42 gyro_delay
[axis
][i
] = gyro_delay
[axis
][i
+ 1];
43 FIRsum
+= gyro_delay
[axis
][i
] * FIRcoeff
[i
];
45 gyro_delay
[axis
][6] = data
[axis
];
46 FIRsum
+= gyro_delay
[axis
][6] * FIRcoeff
[6];
47 data
[axis
] = FIRsum
/ 256;