Skip to content

Commit 511c079

Browse files
Quick-FlashnerdCopter
authored andcommitted
improve cpu load, remove bandpass
1 parent 14906a1 commit 511c079

File tree

3 files changed

+4
-12
lines changed

3 files changed

+4
-12
lines changed

src/main/common/auto_notch.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,17 @@ void initAutoNotch(autoNotch_t *autoNotch, float initial_frequency, int q, int n
4343

4444
autoNotch->preVariance = 0.0;
4545
pt1FilterInit(&autoNotch->preVarianceFilter, pt1FilterGain(10.0, looptimeUs * 1e-6f));
46-
biquadFilterInit(&autoNotch->preVarianceBandpass, initial_frequency, looptimeUs, q, FILTER_BPF, 1.0f);
4746

4847
biquadFilterInit(&autoNotch->notchFilter, initial_frequency, looptimeUs, q, FILTER_NOTCH, 1.0f);
4948
}
5049

5150
FAST_CODE float applyAutoNotch(autoNotch_t *autoNotch, float input) {
52-
float preNotchNoise = biquadFilterApplyDF1(&autoNotch->preVarianceBandpass, input);
51+
float notchFilteredNoise = biquadFilterApplyDF1(&autoNotch->notchFilter, input);
52+
53+
float preNotchNoise = input - notchFilteredNoise;
5354
// variance is approximately the noise squared and averaged
5455
autoNotch->preVariance = pt1FilterApply(&autoNotch->preVarianceFilter, preNotchNoise * preNotchNoise);
5556

56-
float notchFilteredNoise = biquadFilterApplyDF1(&autoNotch->notchFilter, input);
57-
5857
return autoNotch->weight * notchFilteredNoise + autoNotch->invWeight * input;
5958
}
6059

@@ -63,15 +62,14 @@ FAST_CODE void updateWeight(autoNotch_t *autoNotch, float frequency, float weigh
6362
arm_sqrt_f32(autoNotch->preVariance, &deviation);
6463
// 1 / 360
6564
// higher freq have less delay when filtering anyhow and make more dterm noise
66-
float frequencyAccounter = 1.0f + frequency * 0.002777777777f;
65+
float frequencyAccounter = 1.0f + frequency * 0.002777777777f; // the 0.0027 is 1/360
6766
float weight = deviation * frequencyAccounter * autoNotch->noiseLimitInv;
6867

6968
autoNotch->weight = MIN(weight * weightMultiplier, 1.0);
7069
autoNotch->invWeight = 1.0 - autoNotch->weight;
7170
}
7271

7372
FAST_CODE void updateAutoNotch(autoNotch_t *autoNotch, float frequency, float q, float weightMultiplier, float looptimeUs) {
74-
biquadFilterInit(&autoNotch->preVarianceBandpass, frequency, looptimeUs, q, FILTER_BPF, 1.0f);
7573
biquadFilterUpdate(&autoNotch->notchFilter, frequency, looptimeUs, q, FILTER_NOTCH, 1.0f);
7674

7775
updateWeight(autoNotch, frequency, weightMultiplier);

src/main/common/auto_notch.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
typedef struct autoNotch_s {
2626
float preVariance;
2727
pt1Filter_t preVarianceFilter; // used as an exponential average, setup k to act like exponential average
28-
biquadFilter_t preVarianceBandpass;
2928

3029
float noiseLimitInv; // default of 50 allows 70 amplitude noise to be totally notched
3130
float weight;

src/main/flight/rpm_filter.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,6 @@ FAST_CODE_NOINLINE void rpmFilterUpdate(void)
210210
clone->notchFilter.a1 = template->notchFilter.a1;
211211
clone->notchFilter.a2 = template->notchFilter.a2;
212212

213-
clone->preVarianceBandpass.b0 = template->preVarianceBandpass.b0;
214-
//clone->preVarianceBandpass.b1 = template->preVarianceBandpass.b1; // always 0
215-
clone->preVarianceBandpass.b2 = template->preVarianceBandpass.b2;
216-
clone->preVarianceBandpass.b0 = template->preVarianceBandpass.a1;
217-
clone->preVarianceBandpass.b2 = template->preVarianceBandpass.a2;
218213
updateWeight(clone, frequency, weight);
219214
}
220215

0 commit comments

Comments
 (0)