From a0add440f065a26a70e84d6bd0cffd9db150abce Mon Sep 17 00:00:00 2001 From: AJ Christensen Date: Fri, 23 Mar 2018 13:42:56 +1300 Subject: [PATCH] common filters: pt1FilterGain must accept uint16_t (#5513) * all places that call pt1FilterGain use lpfHz which is of type uint16_t. I have not confirmed yet but believe that when lpfHz were greater than 255 we would have seen data loss / overflow / wrap around. TBC --- src/main/common/filter.c | 2 +- src/main/common/filter.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/common/filter.c b/src/main/common/filter.c index 8258103f4b..3e0de982bc 100644 --- a/src/main/common/filter.c +++ b/src/main/common/filter.c @@ -42,7 +42,7 @@ FAST_CODE float nullFilterApply(filter_t *filter, float input) // PT1 Low Pass filter -float pt1FilterGain(uint8_t f_cut, float dT) +float pt1FilterGain(uint16_t f_cut, float dT) { float RC = 1 / ( 2 * M_PI_FLOAT * f_cut); return dT / (RC + dT); diff --git a/src/main/common/filter.h b/src/main/common/filter.h index 08257cb595..61ae82ad5a 100644 --- a/src/main/common/filter.h +++ b/src/main/common/filter.h @@ -129,7 +129,7 @@ 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(uint8_t f_cut, float dT); +float pt1FilterGain(uint16_t f_cut, float dT); void pt1FilterInit(pt1Filter_t *filter, float k); float pt1FilterApply(pt1Filter_t *filter, float input);