Thank you Arduwino!
What I get from your explanation is that the new reading needs to be compared with the last 'N' "most recurring" readings. correct? I understand that to get the sample size of most recurring samples, the array must be sorted, which the code does.
So I think i need another array to store the current maximum count and the sample that is been counted like say: modeCount[2] = {the current maximum count,the sample that is been counted};
and then make my comparison. Does my thought process make sense? If yes, I would greatly appreciate if you could assist me to write a for loop to count the sample size of the most recurring samples within the array.
Thank you again!
filtering noise with arduino coding for Maxsonar sensor
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
-
- Posts: 3
- Joined: Sun Mar 20, 2011 5:48 pm
- adafruit_support_bill
- Posts: 88087
- Joined: Sat Feb 07, 2009 10:11 am
Re: filtering noise with arduino coding for Maxsonar sensor
You never want to keep any more than the last N readings - good or bad. The difference between static analysis and real-time analysis is that for real-time control, old data is worse than spurious data.the new reading needs to be compared with the last 'N' "most recurring" readings.
Your filter size 'N' will determine how responsive your filter is. Smaller N will give you quick response. Larger N will improve noise rejection. Bob's suggested algorithm used an N of 2. Basically it boils down to "if you get two readings in a row that are similar, use the most recent one." You can scale up this simple approach for small values of N. "if you get N readings in a row that are similar, use the most recent one.
For larger values of N this simplistic algorithm won't work so well, because one bad reading will invalidate the next N. In that case you could start looking at comparing the most recent reading to the most recurring of the last N. But before I got bogged down in the complexity of that, I would try out the simple approach with a small N (2-4).
As Bob said:
. Obviously with very noisy data, one might have to do a larger group of readings, but for most this works very well.
-
- Posts: 3
- Joined: Sun Mar 20, 2011 5:48 pm
Re: filtering noise with arduino coding for Maxsonar sensor
Thank you Arduwino! Bob's explanation now makes more sense to me.
-
- Posts: 1
- Joined: Sun Jun 24, 2012 5:02 am
Re: filtering noise with arduino coding for Maxsonar sensor
Hi,
I developed a library for this: https://github.com/Diaoul/arduino-Maxbotix
It handles filtering for you and makes your code easier.
Enjoy
I developed a library for this: https://github.com/Diaoul/arduino-Maxbotix
It handles filtering for you and makes your code easier.
Enjoy
- adafruit_support_bill
- Posts: 88087
- Joined: Sat Feb 07, 2009 10:11 am
Re: filtering noise with arduino coding for Maxsonar sensor
Cool! Thanks for posting that.
Please be positive and constructive with your questions and comments.