CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

A/D Averaging

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
AK



Joined: 20 Apr 2004
Posts: 33

View user's profile Send private message

A/D Averaging
PostPosted: Mon Dec 05, 2005 12:10 pm     Reply with quote

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
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Mon Dec 05, 2005 12:59 pm     Reply with quote

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.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Dec 05, 2005 3:47 pm     Reply with quote

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.
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

PostPosted: Mon Dec 05, 2005 5:44 pm     Reply with quote

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).
AK



Joined: 20 Apr 2004
Posts: 33

View user's profile Send private message

PostPosted: Tue Dec 06, 2005 8:29 am     Reply with quote

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
MikeValencia



Joined: 04 Aug 2004
Posts: 238
Location: Chicago

View user's profile Send private message Send e-mail Yahoo Messenger

PostPosted: Tue Dec 06, 2005 8:45 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group