RobTillaart / RunningAverage

Arduino library to calculate the running average by means of a circular buffer.
MIT License
53 stars 10 forks source link

Investigate larger runs (16 bit) samples to overcome 255 limit #9

Closed RobTillaart closed 3 years ago

RobTillaart commented 3 years ago

Some applications need to handle larger sets of values to define their running average. Investigate how to handle 16 bit's sizes.

Teddyz commented 3 years ago

I agree. I would also like the possibility to limit the number of samples to do average on, while running. Like the way you can do on a Spectrum Analyzer. As an example, if I reserve 256 samples, I could choose to use only 64 of them. Ok if a change of that number clears all data.

RobTillaart commented 3 years ago

@Teddyz

So you mean that initially you allocate 256 samples, but runtime you can adjust the part that is used, to increase performance (whatever reason) without reallocating memory.

RunningAverage myRA(256);

...
myRA.usePartial(64);  // condition n <= size else use all

Q: What would be a good function name to indicate only a subset of the allocated MAXSIZE elements is used?

Q: Should it just use element [0...n-1] (my preference) , or should it use [start .. start+n-1]

RobTillaart commented 3 years ago

Started develop branch

Teddyz commented 3 years ago

Thanks, you have understood my intention correctly. What name to use is not easy for me to say. My favourite is setWindowSize(64)but it is rather long and might lead someone to think it can be used to increase the allocated memory.

Use element from [0...n-1].

What shall happen when size is changed? Easy and predictable to clear all data. Or a fancy design that tries to save as much data as possible? I think clearing data is easier and will never go wrong.

RobTillaart commented 3 years ago

@Teddyz No new example code tested yet, but no existing code seems broken - https://github.com/RobTillaart/RunningAverage/actions So if you have time to spare feel free to do some tests

RobTillaart commented 3 years ago

What shall happen when size is changed?

Clears all, it is only impossible to go beyond the initial size given in the constructor.

RobTillaart commented 3 years ago

added two basic examples

RobTillaart commented 3 years ago

merged 0.4.0

Teddyz commented 3 years ago

Tested OK and is now used in my experiments. Thank you! I also read the code and the implementation seems bulletproof to me. Please include setPartial and getPartial in keywords.txt if you make a future release.

RobTillaart commented 3 years ago

Good to hear it works well. Keywords will be updated asap

Thanks for testing

RobTillaart commented 3 years ago

Updated keywords.txt in master branch, reordered them so they match the order in the runningAverage.h file

idea: a script that extracts keywords.txt from the .h file.