I agree. Since most of the time you will be scaling the result, you can
add up samples (effectively muliplying by the number of samples) and then divide by a different integer to give the result you need. The end result that you have averaged the readings and scaled the result using the fewest possible processor cycles. Charles Linquist ----- Original Message ----- From: "Harold Hallikainen" <> To: <> Sent: Friday, February 20, 2004 12:40 PM Subject: Re: [piclist] Re: Looking for codes to average adc results > > Why do a circular buffer? I just accumulate a sum as the A/D samples come in. I maintain a sum and a count. In several applications, I accumulate 256 samples (just watch for the counter to hit zero!), then divide by 256 by throwing out the 8 lsb of the sum. > > Harold > FCC Rules Online at http://www.hallikainen.com > to unsubscribe, go to http://www.yahoogroups.com and follow the instructions > Yahoo! Groups Links |
Re: Looking for codes to average adc results
Started by ●February 20, 2004
Reply by ●February 20, 20042004-02-20
Reply by ●February 20, 20042004-02-20
--- Scott Lee <> wrote: > --- In , Chad Russel <chadrussel@y...> wrote: > > > The answer is, set up a circular buffer of 8 or 16. Add all the > > numbers and save the total. On each sample, subtract the last > buffer > > value from the total, replace it in the buffer with the new value, > and > > add it to the total. Increment the pointer and shift the total by > 3 or > > 4. > > Don't forget to add 4 (if you have 8 values) or 8 (if you have 16 > values) before dividing in order to properly round the result. If > you don't your result will always be truncated. > > For example, if you had the set {2,2,2,2,2,2,2,1} the sum is 15 and > if you do the shift (15 >> 3) you get 1. However, if you add half > the divisor to the sum before dividing you would get 15 + 4 = 19 and > after dividing (19 >> 3) you get the proper result of 2. > > The worst part about this is you must use 24 bit math since you have > 16 bit values. But that is not terribly difficult to deal with. > > --Scott > Good idea, I did not need that much accuracy in my app. Chad ===== My software has no bugs. Only undocumented features. __________________________________ |
|
Reply by ●February 20, 20042004-02-20
--- Harold Hallikainen <> wrote: > > Why do a circular buffer? I just accumulate a sum as the A/D samples > come in. I maintain a sum and a count. In several applications, I > accumulate 256 samples (just watch for the counter to hit zero!), > then divide by 256 by throwing out the 8 lsb of the sum. > > Harold > FCC Rules Online at http://www.hallikainen.com The reason for the circular buffer is that you have a new average computed every sample time. Otherwise you have to wait for exactly a power of 2 cycles or divide by some number like 107. Not good for real time stuff. Chad ===== My software has no bugs. Only undocumented features. __________________________________ |
Reply by ●February 20, 20042004-02-20
Why do a circular buffer? I just accumulate a sum as the A/D samples come in. I maintain a sum and a count. In several applications, I accumulate 256 samples (just watch for the counter to hit zero!), then divide by 256 by throwing out the 8 lsb of the sum. Harold FCC Rules Online at http://www.hallikainen.com |
|
Reply by ●February 21, 20042004-02-21
--- In , "Leon Heller" <leon_heller@h...> wrote: > > ----- Original Message ----- > From: "Paul James E." <jamesp@i...> > To: <> > Cc: <chadrussel@y...> > Sent: Friday, February 20, 2004 6:24 AM > Subject: Re: [piclist] Re: Looking for codes to average adc results > > > > Sorting and finding the middle number is the median, not the mean. > > The median can sometimes be more 'meaningful' than the mean; it depends on > how the data are distributed. It is another type of average. > > Leon Yup, If one has a noisy input, all the averaging will not reveal the correct value and it will be very noisy. Taking 20 reading and throwing out the 5 highest and 5 lowest is a simple method of ignoring the noise. OF course as low pass filter will do wonders. Dave |
|
Reply by ●February 21, 20042004-02-21
--- Dave MuMuchadadavemuchaujunoom> wrote: > --- In pipiclistayahoogroupsom, "Leon Heller" <leleoneller@h...> > wrote: > > > > ----- Original Message ----- > > From: "Paul James E." <jajamesp...> > > To: <pipiclistayahoogroupsom> > > Cc: <chchadrussel...> > > Sent: Friday, February 20, 2004 6:24 AM > > Subject: Re: [pipiclistRe: Looking for codes to average adadcesults > > > > > > > > > > Sorting and finding the middle number is the median, not the > mean. > > > > The median can sometimes be more 'meaningful' than the mean; it > depends on > > how the data are distributed. It is another type of average. > > > > Leon > Yup, > > If one has a noisy input, all the averaging will not reveal the > correct value and it will be very noisy. > > Taking 20 reading and throwing out the 5 highest and 5 lowest is a > simple method of ignoring the noise. > > OF course as low pass filter will do wonders. > > Dave As with any black box, formula, or algorithm the desired transfer function, range, and domain need to be defined. A square wave at a multiple of the sample rate will give interesting results in any sampling situation, for example. Chad :D ===== My software has no bugs. Only undocumented features. __________________________________ |
Reply by ●February 25, 20042004-02-25
Thank you all for your kind help, this gives me some idea for the above problem, but when it comes to coding in assembly I am not good. The problem was, when you have 16 bit resolution, last bits will be going all over the place because of instability, noise, analoge voltage not settled etc. so some way of seeing them stable or changing slowly until it is stabilized. Once stable seeing on lcd a stable number especially the last digits not changing so much. |
|
Reply by ●February 25, 20042004-02-25
Same problem here. So what I did with moving average was to subtract min from max of buffer. If less than certain value, then stable. Chad --- burt0072003 <> wrote: > Thank you all for your kind help, this gives me some idea for the > above problem, but when it comes to coding in assembly I am not good. > > The problem was, when you have 16 bit resolution, last bits will be > going all over the place because of instability, noise, analoge > voltage not settled etc. so some way of seeing them stable or > changing slowly until it is stabilized. Once stable seeing on lcd a > stable number especially the last digits not changing so much. ===== My software has no bugs. Only undocumented features. __________________________________ |
|
Reply by ●February 25, 20042004-02-25
The last one or two bits on the
LSB would normally not be used to display. You could dampen the display
further by display updating slower or averageing the display updating. The
resolution is only 10-12 bit on the LSB and not the full 16 bit.
regards
Martin
|
|
Reply by ●February 25, 20042004-02-25
I've had decent results by doing a simple filter that uses the previous filtered value in the majority. for example, new = 3/4*current + 1/4*sample current = new by using a power of 2 as the divisor, it makes the math easy. this tends to converge some what slowly so you can't measure fast moving values. It works just fine in temperature measurements. --- In , "martin de lange" <martin_de_lange@x> wrote: > The last one or two bits on the LSB would normally not be used to display. You could dampen the display further by display updating slower or averageing the display updating. The resolution is only 10- 12 bit on the LSB and not the full 16 bit. > > regards > Martin > ----- Original Message ----- > From: burt0072003 > To: > Sent: Thursday, February 26, 2004 3:20 AM > Subject: [piclist] Re: Looking for codes to average adc results > Thank you all for your kind help, this gives me some idea for the > above problem, but when it comes to coding in assembly I am not good. > The problem was, when you have 16 bit resolution, last bits will be > going all over the place because of instability, noise, analoge > voltage not settled etc. so some way of seeing them stable or > changing slowly until it is stabilized. Once stable seeing on lcd a > stable number especially the last digits not changing so much. > > to unsubscribe, go to http://www.yahoogroups.com and follow the instructions > -------------------------------- ---------- > Yahoo! Groups Links > > a.. To |