filtering noise with arduino coding for Maxsonar sensor

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
suj10
 
Posts: 3
Joined: Sun Mar 20, 2011 5:48 pm

Re: filtering noise with arduino coding for Maxsonar sensor

Post by suj10 »

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!

User avatar
adafruit_support_bill
 
Posts: 88087
Joined: Sat Feb 07, 2009 10:11 am

Re: filtering noise with arduino coding for Maxsonar sensor

Post by adafruit_support_bill »

the new reading needs to be compared with the last 'N' "most recurring" readings.
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.

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.

suj10
 
Posts: 3
Joined: Sun Mar 20, 2011 5:48 pm

Re: filtering noise with arduino coding for Maxsonar sensor

Post by suj10 »

Thank you Arduwino! Bob's explanation now makes more sense to me.

Diaoul
 
Posts: 1
Joined: Sun Jun 24, 2012 5:02 am

Re: filtering noise with arduino coding for Maxsonar sensor

Post by Diaoul »

Hi,

I developed a library for this: https://github.com/Diaoul/arduino-Maxbotix
It handles filtering for you and makes your code easier.

Enjoy

User avatar
adafruit_support_bill
 
Posts: 88087
Joined: Sat Feb 07, 2009 10:11 am

Re: filtering noise with arduino coding for Maxsonar sensor

Post by adafruit_support_bill »

Cool! Thanks for posting that. :D

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”