Analog averaging and oversampling

We are using the KOP Maxbotix sonar and I was wondering if there was any value to averaging and/or oversampling the analog channel we have it hooked up to? We are basically only using it as a depth sensor during autonomous, and being off an inch or two probably isn’t going to make any difference.

So, if it is worth doing, I have some questions:

  • Can you average without oversampling, or vice versa? (I think yes)
  • Do I understand the bits thing right? If I set the “average bits” to 2, then it averages 4 readings, if set to 4 it averages 16?
  • For this application (sonar) would oversampling actually gain us anything?

Thanks

The short answer:

1a. Not really. There’s nothing to average if you don’t oversample (if you read it multiple times in your code and average it without setting oversampling on, that’s still oversampling).
1b. It is possible to oversample without averaging. You just add up all the samples and, dont divide for the average. It may or may not be useful, though.
2. Yes.
3. If there were electrical noise the the line from the sensor to the ADC in the cRio module, one reading by be off by quite a bit. Oversampling and averaging could remove this electrical noise in the readings if its of a special type. If the noise was present and significant in the sensing done by the sonar sensor and it throws its calculations off, then oversampling is rather useless, as it will just average out to the correctly-obtained-but-realistically-incorrect value.

This is Tom Bonar from MaxBotix. If you’re looking to filter the readings of the sensor please read the pre-written response below on filtering.

-Filtering
The filtering that works best, is either a Mode filter or a Median filter. (Did I forget to say, “Do not average the readings”?)

-The Median Filter
The median filter would take the last group of readings and first sort them and then pull out the center reading. Here one might take three or more readings (up to say about 11 for people sensing) and after sorting the readings in order of range, pull out and use only the middle (median) reading. Fairly good filtering.
You can view an Arduino code example by clicking the link http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1288290319/3#3.

-The Mode Filter
The mode filter would take the largest group of the same readings out of a set of even larger readings. Very robust filtering.

-Filtering for most applications, the Very Simple Mode Filter
The simplest mode filter, is simple as this question, “Do the last two readings agree?” (with in a certain distance, and the certain distance depends upon how much variation one expects in the actual use. Even so most use the logic of “are these readings exactly the same”)? If so, use the readings, otherwise throw away to oldest reading, and compare the next reading with the most current reading and do this again. Obviously with very noisy data, one might have to sample a larger group of readings, and pull out the most common reading, but for most applications, this simple two reading filter works very well.