View previous topic :: View next topic |
Author |
Message |
AK
Joined: 20 Apr 2004 Posts: 33
|
A/D Averaging |
Posted: Mon Dec 05, 2005 12:10 pm |
|
|
I'm using an averaging filter to help remove some unwanted noise in a 16 bit A/D system that samples a DC voltage that ranges from 0 to 1.024 Volts. The voltage will not change very quickly. Is there any standard number of data points that I should use when calculating the average?
Thanks,
AK |
|
![](templates/subSilver/images/spacer.gif) |
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Mon Dec 05, 2005 12:59 pm |
|
|
The more the better, but the answer only improves by the square root of the number of samples, and that is assuming the noise is gaussian.
What I often use is what I call "Olympic Scoring." I take a number of samples, often 10, and keep the maximun, the minimum, and the sum. Then I subtract out the max and the min and average the rest. The math and RAM consumption is minimal and you eliminate one outlyer either high, low, or both. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Dec 05, 2005 3:47 pm |
|
|
If you collect a bunch of data points, you can model your filter in Microsoft
Excel. Just use RS232 output from PIC to send data to a terminal
window, and then save it as a text file and import it into Excel.
Excel has many built-in averaging functions, or can write your own.
You can test different array sizes for your running average and see
which one will work best, based on your expected data. I did this with
a tachometer project and was able to choose a proper Median filter
and averaging filter. |
|
![](templates/subSilver/images/spacer.gif) |
kender
Joined: 09 Aug 2004 Posts: 768 Location: Silicon Valley
|
|
Posted: Mon Dec 05, 2005 5:44 pm |
|
|
Another age-old trick you can use to decrease the amount of processing time is to acumulate 2^n samples and then shift the sum right n bits. This way you avoid time-consuming division. Keep in mind that you'll need a 32-bit variable to accumulate 16-bit measurements (assuming that you are using all of the A/D dynamic range). |
|
![](templates/subSilver/images/spacer.gif) |
AK
Joined: 20 Apr 2004 Posts: 33
|
|
Posted: Tue Dec 06, 2005 8:29 am |
|
|
SherpaDoug,
I used your "Olympic Scoring" filter idea and it seems to be working pretty well. I take 40 samples and remove the highest 3 values and the lowest 3 values and I keep the rest. Do you think this is overdoing it or that I'll be hurting my results?
Thanks,
AK |
|
![](templates/subSilver/images/spacer.gif) |
MikeValencia
Joined: 04 Aug 2004 Posts: 238 Location: Chicago
|
|
Posted: Tue Dec 06, 2005 8:45 am |
|
|
I like using PCM Programmer's median filter that he posted in the past. I use it with A/D values measuring motor current.
If I interpret it correctly, it takes the most recent 7 a/d measurements and gives me the middle value.
In my case, a simple average was not good for me because I have a lot of stray values that would also get averaged in. |
|
![](templates/subSilver/images/spacer.gif) |
|