Simplified lmaSmoothingUpdate and made it's state aligned for all members (#5510)
This commit is contained in:
parent
a539bd60bc
commit
eca6fb3a0c
|
@ -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);
|
||||
|
|
|
@ -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];
|
||||
|
|
Loading…
Reference in New Issue