Coder Social home page Coder Social logo

pilotak / movingaveragefloat Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 1.0 12 KB

Arduino & Mbed Library for averaging float numbers

License: MIT License

C++ 100.00%
mbed mbed-os arduino arduino-library averaging-filter moving-average filter float floating-point

movingaveragefloat's Introduction

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

movingaveragefloat's People

Contributors

gleue avatar pilotak avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

gleue

movingaveragefloat's Issues

Incorrect average

Thanks for this nice library.

I noticed the computation of the moving average is not correct. The bug is in MovingAverageFloat.h:84 where it should be

_next = (_next + 1) % N;

instead of

_next = (_next + 1) & (N - 1);

since this does only work for N being a power of two -- 2, 4, 8, 16 etc.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.