@@ -43,18 +43,17 @@ void initAutoNotch(autoNotch_t *autoNotch, float initial_frequency, int q, int n
43
43
44
44
autoNotch -> preVariance = 0.0 ;
45
45
pt1FilterInit (& autoNotch -> preVarianceFilter , pt1FilterGain (10.0 , looptimeUs * 1e-6f ));
46
- biquadFilterInit (& autoNotch -> preVarianceBandpass , initial_frequency , looptimeUs , q , FILTER_BPF , 1.0f );
47
46
48
47
biquadFilterInit (& autoNotch -> notchFilter , initial_frequency , looptimeUs , q , FILTER_NOTCH , 1.0f );
49
48
}
50
49
51
50
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 ;
53
54
// variance is approximately the noise squared and averaged
54
55
autoNotch -> preVariance = pt1FilterApply (& autoNotch -> preVarianceFilter , preNotchNoise * preNotchNoise );
55
56
56
- float notchFilteredNoise = biquadFilterApplyDF1 (& autoNotch -> notchFilter , input );
57
-
58
57
return autoNotch -> weight * notchFilteredNoise + autoNotch -> invWeight * input ;
59
58
}
60
59
@@ -63,15 +62,14 @@ FAST_CODE void updateWeight(autoNotch_t *autoNotch, float frequency, float weigh
63
62
arm_sqrt_f32 (autoNotch -> preVariance , & deviation );
64
63
// 1 / 360
65
64
// 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
67
66
float weight = deviation * frequencyAccounter * autoNotch -> noiseLimitInv ;
68
67
69
68
autoNotch -> weight = MIN (weight * weightMultiplier , 1.0 );
70
69
autoNotch -> invWeight = 1.0 - autoNotch -> weight ;
71
70
}
72
71
73
72
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 );
75
73
biquadFilterUpdate (& autoNotch -> notchFilter , frequency , looptimeUs , q , FILTER_NOTCH , 1.0f );
76
74
77
75
updateWeight (autoNotch , frequency , weightMultiplier );
0 commit comments