Skip to content

Commit 4a3d000

Browse files
Quick-FlashnerdCopter
authored andcommitted
add frequency accounter
1 parent 33c3d00 commit 4a3d000

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

src/main/cli/settings.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,6 +1701,7 @@ const clivalue_t valueTable[] = {
17011701
#ifdef USE_RPM_FILTER
17021702
{ PARAM_NAME_RPM_FILTER_HARMONICS, VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 0, 3 }, PG_RPM_FILTER_CONFIG, offsetof(rpmFilterConfig_t, rpm_filter_harmonics) },
17031703
{ PARAM_NAME_RPM_FILTER_Q, VAR_UINT16 | MASTER_VALUE, .config.minmaxUnsigned = { 250, 3000 }, PG_RPM_FILTER_CONFIG, offsetof(rpmFilterConfig_t, rpm_filter_q) },
1704+
{ "rpm_noise_limit", VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 1, 255 }, PG_RPM_FILTER_CONFIG, offsetof(rpmFilterConfig_t, noise_limit) },
17041705
{ PARAM_NAME_RPM_FILTER_MIN_HZ, VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 30, 200 }, PG_RPM_FILTER_CONFIG, offsetof(rpmFilterConfig_t, rpm_filter_min_hz) },
17051706
{ PARAM_NAME_RPM_FILTER_FADE_RANGE_HZ, VAR_UINT16 | MASTER_VALUE, .config.minmaxUnsigned = { 0, 1000 }, PG_RPM_FILTER_CONFIG, offsetof(rpmFilterConfig_t, rpm_filter_fade_range_hz) },
17061707
{ PARAM_NAME_RPM_FILTER_LPF_HZ, VAR_UINT16 | MASTER_VALUE, .config.minmaxUnsigned = { 100, 500 }, PG_RPM_FILTER_CONFIG, offsetof(rpmFilterConfig_t, rpm_filter_lpf_hz) },

src/main/common/auto_notch.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838

3939
void initAutoNotch(autoNotch_t *autoNotch, float initial_frequency, int q, int noiseLimit, float looptimeUs) {
40-
autoNotch->noiseLimit = noiseLimit;
40+
autoNotch->noiseLimitInv = 1.0 / noiseLimit;
4141
autoNotch->weight = 1.0;
4242
autoNotch->invWeight = 0.0;
4343

@@ -58,10 +58,13 @@ FAST_CODE float applyAutoNotch(autoNotch_t *autoNotch, float input) {
5858
return autoNotch->weight * notchFilteredNoise + autoNotch->invWeight * input;
5959
}
6060

61-
FAST_CODE void updateWeight(autoNotch_t *autoNotch, float weightMultiplier) {
61+
FAST_CODE void updateWeight(autoNotch_t *autoNotch, float frequency, float weightMultiplier) {
6262
float deviation;
6363
arm_sqrt_f32(autoNotch->preVariance, &deviation);
64-
float weight = deviation / autoNotch->noiseLimit;
64+
// 1 / 360
65+
// higher freq have less delay when filtering anyhow and make more dterm noise
66+
float frequencyAccounter = 1.0f + frequency * 0.002777777777f;
67+
float weight = deviation * frequencyAccounter * autoNotch->noiseLimitInv;
6568

6669
autoNotch->weight = MIN(weight * weightMultiplier, 1.0);
6770
autoNotch->invWeight = 1.0 - autoNotch->weight;
@@ -71,5 +74,5 @@ FAST_CODE void updateAutoNotch(autoNotch_t *autoNotch, float frequency, float q,
7174
biquadFilterInit(&autoNotch->preVarianceBandpass, frequency, looptimeUs, q, FILTER_BPF, 1.0f);
7275
biquadFilterUpdate(&autoNotch->notchFilter, frequency, looptimeUs, q, FILTER_NOTCH, 1.0f);
7376

74-
updateWeight(autoNotch, weightMultiplier);
77+
updateWeight(autoNotch, frequency, weightMultiplier);
7578
}

src/main/common/auto_notch.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ typedef struct autoNotch_s {
2727
pt1Filter_t preVarianceFilter; // used as an exponential average, setup k to act like exponential average
2828
biquadFilter_t preVarianceBandpass;
2929

30-
float noiseLimit; // default of 50 allows 70 amplitude noise to be totally notched
30+
float noiseLimitInv; // default of 50 allows 70 amplitude noise to be totally notched
3131
float weight;
3232
float invWeight;
3333

@@ -36,5 +36,5 @@ typedef struct autoNotch_s {
3636

3737
void initAutoNotch(autoNotch_t *autoNotch, float initial_frequency, int q, int noiseLimit, float looptimeUs);
3838
float applyAutoNotch(autoNotch_t *autoNotch, float input);
39-
void updateWeight(autoNotch_t *autoNotch, float weightMultiplier);
39+
void updateWeight(autoNotch_t *autoNotch, float frequency, float weightMultiplier);
4040
void updateAutoNotch(autoNotch_t *autoNotch, float frequency, float q, float weightMultiplier, float looptimeUs);

src/main/flight/rpm_filter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ FAST_CODE_NOINLINE void rpmFilterUpdate(void)
215215
clone->preVarianceBandpass.b2 = template->preVarianceBandpass.b2;
216216
clone->preVarianceBandpass.b0 = template->preVarianceBandpass.a1;
217217
clone->preVarianceBandpass.b2 = template->preVarianceBandpass.a2;
218-
updateWeight(clone, weight);
218+
updateWeight(clone, frequency, weight);
219219
}
220220

221221
if (++currentHarmonic == currentFilter->harmonics) {

0 commit comments

Comments
 (0)