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/>.
27 typedef struct filter_s filter_t
;
28 typedef float (*filterApplyFnPtr
)(filter_t
*filter
, float input
);
35 } lowpassFilterType_e
;
38 FILTER_LPF
, // 2nd order Butterworth section
43 typedef struct pt1Filter_s
{
48 typedef struct pt2Filter_s
{
54 typedef struct pt3Filter_s
{
61 /* this holds the data required to update samples thru a filter */
62 typedef struct biquadFilter_s
{
63 float b0
, b1
, b2
, a1
, a2
;
68 typedef struct phaseComp_s
{
73 typedef struct slewFilter_s
{
79 typedef struct laggedMovingAverage_s
{
80 uint16_t movingWindowIndex
;
85 } laggedMovingAverage_t
;
87 typedef struct simpleLowpassFilter_s
{
91 } simpleLowpassFilter_t
;
93 typedef struct meanAccumulator_s
{
98 float nullFilterApply(filter_t
*filter
, float input
);
100 float pt1FilterGain(float f_cut
, float dT
);
101 void pt1FilterInit(pt1Filter_t
*filter
, float k
);
102 void pt1FilterUpdateCutoff(pt1Filter_t
*filter
, float k
);
103 float pt1FilterApply(pt1Filter_t
*filter
, float input
);
105 float pt2FilterGain(float f_cut
, float dT
);
106 void pt2FilterInit(pt2Filter_t
*filter
, float k
);
107 void pt2FilterUpdateCutoff(pt2Filter_t
*filter
, float k
);
108 float pt2FilterApply(pt2Filter_t
*filter
, float input
);
110 float pt3FilterGain(float f_cut
, float dT
);
111 void pt3FilterInit(pt3Filter_t
*filter
, float k
);
112 void pt3FilterUpdateCutoff(pt3Filter_t
*filter
, float k
);
113 float pt3FilterApply(pt3Filter_t
*filter
, float input
);
115 float filterGetNotchQ(float centerFreq
, float cutoffFreq
);
117 void biquadFilterInitLPF(biquadFilter_t
*filter
, float filterFreq
, uint32_t refreshRate
);
118 void biquadFilterInit(biquadFilter_t
*filter
, float filterFreq
, uint32_t refreshRate
, float Q
, biquadFilterType_e filterType
, float weight
);
119 void biquadFilterUpdate(biquadFilter_t
*filter
, float filterFreq
, uint32_t refreshRate
, float Q
, biquadFilterType_e filterType
, float weight
);
120 void biquadFilterUpdateLPF(biquadFilter_t
*filter
, float filterFreq
, uint32_t refreshRate
);
121 float biquadFilterApplyDF1(biquadFilter_t
*filter
, float input
);
122 float biquadFilterApplyDF1Weighted(biquadFilter_t
*filter
, float input
);
123 float biquadFilterApply(biquadFilter_t
*filter
, float input
);
125 void phaseCompInit(phaseComp_t
*filter
, const float centerFreq
, const float centerPhase
, const uint32_t looptimeUs
);
126 void phaseCompUpdate(phaseComp_t
*filter
, const float centerFreq
, const float centerPhase
, const uint32_t looptimeUs
);
127 float phaseCompApply(phaseComp_t
*filter
, const float input
);
129 void slewFilterInit(slewFilter_t
*filter
, float slewLimit
, float threshold
);
130 float slewFilterApply(slewFilter_t
*filter
, float input
);
132 void laggedMovingAverageInit(laggedMovingAverage_t
*filter
, uint16_t windowSize
, float *buf
);
133 float laggedMovingAverageUpdate(laggedMovingAverage_t
*filter
, float input
);
135 void simpleLPFilterInit(simpleLowpassFilter_t
*filter
, int32_t beta
, int32_t fpShift
);
136 int32_t simpleLPFilterUpdate(simpleLowpassFilter_t
*filter
, int32_t newVal
);
138 void meanAccumulatorInit(meanAccumulator_t
*filter
);
139 void meanAccumulatorAdd(meanAccumulator_t
*filter
, const int8_t newVal
);
140 int8_t meanAccumulatorCalc(meanAccumulator_t
*filter
, const int8_t defaultValue
);