mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-19 06:15:16 +03:00
Fixed notch Q calculation to be dimensionless as it should (#5529)
* Fixed notch Q calculation to be dimensionless as it should * Get rid of one division and leverage multiply-accumulate instr
This commit is contained in:
parent
0c7ae49464
commit
172642383d
3 changed files with 4 additions and 10 deletions
|
@ -86,11 +86,8 @@ FAST_CODE float slewFilterApply(slewFilter_t *filter, float input)
|
||||||
|
|
||||||
// get notch filter Q given center frequency (f0) and lower cutoff frequency (f1)
|
// get notch filter Q given center frequency (f0) and lower cutoff frequency (f1)
|
||||||
// Q = f0 / (f2 - f1) ; f2 = f0^2 / f1
|
// Q = f0 / (f2 - f1) ; f2 = f0^2 / f1
|
||||||
float filterGetNotchQ(uint16_t centerFreq, uint16_t cutoff) {
|
float filterGetNotchQ(float centerFreq, float cutoffFreq) {
|
||||||
const float f0sq = (float)centerFreq * centerFreq;
|
return centerFreq * cutoffFreq / (centerFreq * centerFreq - cutoffFreq * cutoffFreq);
|
||||||
const float f1 = cutoff;
|
|
||||||
|
|
||||||
return (f1 * f0sq) / (f0sq - f1 * f1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* sets up a biquad Filter */
|
/* sets up a biquad Filter */
|
||||||
|
|
|
@ -116,7 +116,7 @@ int biquadFilterLpfCascadeInit(biquadFilter_t *sections, int order, float filter
|
||||||
float biquadFilterApplyDF1(biquadFilter_t *filter, float input);
|
float biquadFilterApplyDF1(biquadFilter_t *filter, float input);
|
||||||
float biquadFilterApply(biquadFilter_t *filter, float input);
|
float biquadFilterApply(biquadFilter_t *filter, float input);
|
||||||
float biquadCascadeFilterApply(biquadFilterCascade_t *filter, float input);
|
float biquadCascadeFilterApply(biquadFilterCascade_t *filter, float input);
|
||||||
float filterGetNotchQ(uint16_t centerFreq, uint16_t cutoff);
|
float filterGetNotchQ(float centerFreq, float cutoffFreq);
|
||||||
|
|
||||||
void biquadRCFIR2FilterInit(biquadFilter_t *filter, float k);
|
void biquadRCFIR2FilterInit(biquadFilter_t *filter, float k);
|
||||||
|
|
||||||
|
@ -126,9 +126,6 @@ float fastKalmanUpdate(fastKalman_t *filter, float input);
|
||||||
void lmaSmoothingInit(laggedMovingAverage_t *filter, uint8_t windowSize, float weight);
|
void lmaSmoothingInit(laggedMovingAverage_t *filter, uint8_t windowSize, float weight);
|
||||||
float lmaSmoothingUpdate(laggedMovingAverage_t *filter, float input);
|
float lmaSmoothingUpdate(laggedMovingAverage_t *filter, float input);
|
||||||
|
|
||||||
// not exactly correct, but very very close and much much faster
|
|
||||||
#define filterGetNotchQApprox(centerFreq, cutoff) ((float)(cutoff * centerFreq) / ((float)(centerFreq - cutoff) * (float)(centerFreq + cutoff)))
|
|
||||||
|
|
||||||
float pt1FilterGain(uint16_t f_cut, float dT);
|
float pt1FilterGain(uint16_t f_cut, float dT);
|
||||||
void pt1FilterInit(pt1Filter_t *filter, float k);
|
void pt1FilterInit(pt1Filter_t *filter, float k);
|
||||||
float pt1FilterApply(pt1Filter_t *filter, float input);
|
float pt1FilterApply(pt1Filter_t *filter, float input);
|
||||||
|
|
|
@ -281,7 +281,7 @@ void gyroDataAnalyseUpdate(biquadFilter_t *notchFilterDyn)
|
||||||
// 7us
|
// 7us
|
||||||
// calculate new filter coefficients
|
// calculate new filter coefficients
|
||||||
float cutoffFreq = constrain(fftResult[axis].centerFreq - DYN_NOTCH_WIDTH, DYN_NOTCH_MIN_CUTOFF, DYN_NOTCH_MAX_CUTOFF);
|
float cutoffFreq = constrain(fftResult[axis].centerFreq - DYN_NOTCH_WIDTH, DYN_NOTCH_MIN_CUTOFF, DYN_NOTCH_MAX_CUTOFF);
|
||||||
float notchQ = filterGetNotchQApprox(fftResult[axis].centerFreq, cutoffFreq);
|
float notchQ = filterGetNotchQ(fftResult[axis].centerFreq, cutoffFreq);
|
||||||
biquadFilterUpdate(¬chFilterDyn[axis], fftResult[axis].centerFreq, gyro.targetLooptime, notchQ, FILTER_NOTCH);
|
biquadFilterUpdate(¬chFilterDyn[axis], fftResult[axis].centerFreq, gyro.targetLooptime, notchQ, FILTER_NOTCH);
|
||||||
DEBUG_SET(DEBUG_FFT_TIME, 1, micros() - startTime);
|
DEBUG_SET(DEBUG_FFT_TIME, 1, micros() - startTime);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue