Skip to content

pilotak/MovingAverageFloat

Repository files navigation

Moving average filter for float numbers

Build status Framework Badge Arduino Framework Badge mbed

Arduino example

Please see examples folder

Mbed example

#include "mbed.h"
#include "MovingAverageFloat.h"

// Buffer will be 16 samples long, it will take 16 * sizeof(float) = 64 bytes of RAM
MovingAverageFloat <16> filter;

int main() {
    printf("result: %.2f\n", filter.add(1.5)); // insert new number and get result
    printf("result: %.2f\n", filter.add(2.5)); // insert new number and get result
    printf("result: %.2f\n", filter.add(2.4)); // insert new number and get result
    printf("result: %.2f\n", filter.get()); // get last result, without adding a newone

    return 0;
}

Output

result: 1.50

result: 1.56

result: 1.62

result: 1.62