Pages: 1 [2]   Go Down
Author Topic: RunningAverage Class on playground (updated)  (Read 4854 times)
0 Members and 1 Guest are viewing this topic.
Brasil
Offline Offline
Full Member
***
Karma: 4
Posts: 124
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Take a look at my Library, that works perfecly for a moving average...

https://github.com/ivanseidel/Gaussian
Logged


Mid-Atlantic, USA
Offline Offline
Sr. Member
****
Karma: 22
Posts: 459
"Remember kids, the only difference between Science and screwing around is writing it down." - Adam Savage
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

[... snipped ...]
The results of these measurements can be found in the attached pdf file "Diff_Pressure_averaged_median.pdf". Now there is something strange about the averaging value. The buffer size seems not to change.  even the 200 value buffer size ("RunningMedian diff_p_RA(200); ") looks more like the 25 or even 10. The RunningMedian Code I used is from your (Rob Tillaart) github repository. Furthermore, I expected something else from the RunningMedian. Let me know what you think.

Best regards,
Jan

P.S.: I now added the raw data of these measurements.


If you look in RunningMedian.h you will see
Code:
#define MEDIAN_MAX_SIZE     19          // adjust if needed

If you don't change that, requesting a median array size of anything larger than 19 will only give you a 19 element array to run your medians and averages against. Did you change that line before compiling your sketch that requests a 200 element array?
Logged


Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi there,

thank you  Sembazuru for pointing that out.  I guess that means I should have set "MEDIAN_MAX_SIZE" to somewhat around 200 and then define a
Code:
RunningMedian samples = RunningMedian(50);
Well, as I learned yesterday the RunningMedian takes more processing time as it needs to sort the array. As I´m taking my measurements each 50ms I guess that would not be an option - especially not with a large array size (which seem absolutley logical now to limit the array size). I´m now using the RunningAverage-library as I found my optimum array size for my setup via the tests I did. So everything is fine now. But I still wonder if the array size can be made user configurable during runtime.

@ivanseidel: Thank you for pointing me to your library. But I allready implemented the RunningAverage-library by Rob Tillaart and only needed some fine tuning (and understanding on whats going on behind the scenes). The last results I got were  suficiently constant. I just needed to adjust the array size to get the timing right (because a large array size means smoother data but more timeleg  on steep gradients ).

Best regards,
Jan 
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 170
Posts: 12483
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have tried to reproduce the getMedian() error but I could not. Using the [partial] data from your zip file I got no errors.

A possible cause I cannot verify is how much free RAM you have as it might be a problem during allocating the internal arrays as the lib uses dynamic memory. That could explain the behaviour seen.
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 170
Posts: 12483
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
But I still wonder if the array size can be made user configurable during runtime.
The lib could be rewritten to use dynamic memory and you could reallocate the memory. However as an Arduino has very limited RAM this gives fragmented (useless) memory quite fast.

that said, you might try with largest allocation first and gradually decrease the size to an optimum. Then the reallocation should less fragment the memory in theory ...


Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Brasil
Offline Offline
Full Member
***
Karma: 4
Posts: 124
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
But I still wonder if the array size can be made user configurable during runtime.
The lib could be rewritten to use dynamic memory and you could reallocate the memory. However as an Arduino has very limited RAM this gives fragmented (useless) memory quite fast.

that said, you might try with largest allocation first and gradually decrease the size to an optimum. Then the reallocation should less fragment the memory in theory ...


That's true, but it's already implemented with my library (I use a self made LinkedList). Worth a try =)

You can change the size whenever you want, and it will not crash the code.

Also, you can use it with basic numbers 10 = Gaussian(10); or with numbers with variance: Gaussian(10,variance);, witch gives you much more flexibility on the average...

Just a tip... take a look at the documentation.

https://github.com/ivanseidel/Gaussian
Logged


Pages: 1 [2]   Go Up
Jump to: