Reply to post: high speed moving average

Real talk: You're gonna have to get real about real-time analytics if you wanna make IoT work

bombastic bob Silver badge
Devil

high speed moving average

one way to accomplish a nice high speed moving average (using integers, even) would be to do something like this:

int accum = 0; // accumulator, in this case stores "impossible" value

...

void loop(void) { int value = read_data();

if(!accum) accum = value; else accum = (accum * 7 + value) / 8;

send_data_to_the_web(accum); time_delay(); }

that way you can respond quickly to changes, but also use a moving average to help get rid of noisy data. It's also simple enough (using integers) in a way that approximates a weighted moving average with an infinite period. [I've done things _like_ this for _years_, so it's nothing new, really]

That being said, it's a possible solution for the data 'noise' and averaging problem. The sensor would do the calculation and send the 'crunched' value to the server. If you need the raw value too, you can still send both. But this also makes scanning for 'alarm' conditions easier, because the 'crunched' value will already be stored on the server [well, ideally].

POST COMMENT House rules

Not a member of The Register? Create a new account here.

  • Enter your comment

  • Add an icon

Anonymous cowards cannot choose their icon