@@ -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
5150FAST_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
7372FAST_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 );
0 commit comments