FILTER: PT1 with rate of change limiting
[betaflight.git] / src / main / common / filter.h
blobf92e9b8a58fe9d0cef378edae47c4678dbe86efe
1 /*
2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
18 #pragma once
20 typedef struct filterStatePt1_s {
21 float state;
22 float RC;
23 float constdT;
24 } filterStatePt1_t;
26 /* this holds the data required to update samples thru a filter */
27 typedef struct biquad_s {
28 float b0, b1, b2, a1, a2;
29 float d1, d2;
30 } biquad_t;
32 float filterApplyPt1(float input, filterStatePt1_t *filter, float f_cut, float dt);
33 float filterApplyPt1WithRateLimit(float input, filterStatePt1_t *filter, float f_cut, float rate_limit, float dT);
34 void filterResetPt1(filterStatePt1_t *filter, float input);
36 void filterInitBiQuad(uint8_t filterCutFreq, biquad_t *newState, int16_t samplingRate);
37 float filterApplyBiQuad(float sample, biquad_t *state);
39 void filterUpdateFIR(int filterLength, float *shiftBuf, float newSample);
40 float filterApplyFIR(int filterLength, const float *shiftBuf, const float *coeffBuf, float commonMultiplier);