Simplified lmaSmoothingUpdate and made it's state aligned for all members (#5510)

This commit is contained in:
Andrey Mironov 2018-03-23 03:41:40 +03:00 committed by Michael Keller
parent a539bd60bc
commit eca6fb3a0c
2 changed files with 3 additions and 6 deletions

View File

@ -420,11 +420,8 @@ FAST_CODE float lmaSmoothingUpdate(laggedMovingAverage_t *filter, float input)
filter->buf[filter->movingWindowIndex] = input;
filter->movingSum += input;
uint8_t windowIndex = filter->movingWindowIndex;
if (++windowIndex >= filter->windowSize) {
if (++filter->movingWindowIndex == filter->windowSize) {
filter->movingWindowIndex = 0;
} else {
filter->movingWindowIndex = windowIndex;
}
return input + (((filter->movingSum / filter->windowSize) - input) * filter->weight);

View File

@ -69,8 +69,8 @@ typedef struct fastKalman_s {
} fastKalman_t;
typedef struct laggedMovingAverage_s {
uint8_t movingWindowIndex;
uint8_t windowSize;
uint16_t movingWindowIndex;
uint16_t windowSize;
float weight;
float movingSum;
float buf[MAX_LMA_WINDOW_SIZE];