2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
25 typedef struct filter_s filter_t
;
27 typedef struct pt1Filter_s
{
32 typedef struct pt2Filter_s
{
38 typedef struct pt3Filter_s
{
45 typedef struct slewFilter_s
{
51 /* this holds the data required to update samples thru a filter */
52 typedef struct biquadFilter_s
{
53 float b0
, b1
, b2
, a1
, a2
;
58 typedef struct laggedMovingAverage_s
{
59 uint16_t movingWindowIndex
;
64 } laggedMovingAverage_t
;
71 } lowpassFilterType_e
;
74 FILTER_LPF
, // 2nd order Butterworth section
79 typedef float (*filterApplyFnPtr
)(filter_t
*filter
, float input
);
81 float nullFilterApply(filter_t
*filter
, float input
);
83 void biquadFilterInitLPF(biquadFilter_t
*filter
, float filterFreq
, uint32_t refreshRate
);
84 void biquadFilterInit(biquadFilter_t
*filter
, float filterFreq
, uint32_t refreshRate
, float Q
, biquadFilterType_e filterType
, float weight
);
85 void biquadFilterUpdate(biquadFilter_t
*filter
, float filterFreq
, uint32_t refreshRate
, float Q
, biquadFilterType_e filterType
, float weight
);
86 void biquadFilterUpdateLPF(biquadFilter_t
*filter
, float filterFreq
, uint32_t refreshRate
);
88 float biquadFilterApplyDF1(biquadFilter_t
*filter
, float input
);
89 float biquadFilterApplyDF1Weighted(biquadFilter_t
*filter
, float input
);
90 float biquadFilterApply(biquadFilter_t
*filter
, float input
);
91 float filterGetNotchQ(float centerFreq
, float cutoffFreq
);
93 void laggedMovingAverageInit(laggedMovingAverage_t
*filter
, uint16_t windowSize
, float *buf
);
94 float laggedMovingAverageUpdate(laggedMovingAverage_t
*filter
, float input
);
96 float pt1FilterGain(float f_cut
, float dT
);
97 void pt1FilterInit(pt1Filter_t
*filter
, float k
);
98 void pt1FilterUpdateCutoff(pt1Filter_t
*filter
, float k
);
99 float pt1FilterApply(pt1Filter_t
*filter
, float input
);
101 float pt2FilterGain(float f_cut
, float dT
);
102 void pt2FilterInit(pt2Filter_t
*filter
, float k
);
103 void pt2FilterUpdateCutoff(pt2Filter_t
*filter
, float k
);
104 float pt2FilterApply(pt2Filter_t
*filter
, float input
);
106 float pt3FilterGain(float f_cut
, float dT
);
107 void pt3FilterInit(pt3Filter_t
*filter
, float k
);
108 void pt3FilterUpdateCutoff(pt3Filter_t
*filter
, float k
);
109 float pt3FilterApply(pt3Filter_t
*filter
, float input
);
111 void slewFilterInit(slewFilter_t
*filter
, float slewLimit
, float threshold
);
112 float slewFilterApply(slewFilter_t
*filter
, float input
);
114 typedef struct simpleLowpassFilter_s
{
118 } simpleLowpassFilter_t
;
120 int32_t simpleLPFilterUpdate(simpleLowpassFilter_t
*filter
, int32_t newVal
);
121 void simpleLPFilterInit(simpleLowpassFilter_t
*filter
, int32_t beta
, int32_t fpShift
);