Reply by Dave Mucha February 28, 20042004-02-28
--- In , Chad Russel <chadrussel@y...> wrote:
> 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


One simple way to get rid of some of the noise is to delete the min
max readings.

since it seems you are talking about a 16 bit value, and if you want
to stay in 16 bit numbers, another way is to take the average you had
and then find out how much your current reading is different.

This is averaging the deviation. Then just adding it back to the
average to get a new average.

This method stops working when you have really noisy signals in the
upper end of the range. ie: 4.8 volts or so.

To handle that, you can just subtract some value from everything and
then add it back in the final stages.

Dave



Reply by jr66a February 26, 20042004-02-26
If you are havin problems with code here is some to get you started.
I find this method simple and sufficiently accurate for most
programs. This routine works by reading the A/D signal 256 times
adding the result each time to a running total. With an 8 bit reading
you will have a 16 bit result after 256 readings. The most sig. 8
bits of this result is the average input.

With this method there is no maths involved apart from a simple
addition. If you are using a 10 bit A/D the same method can be used
with some mods. If you want you can drop the least sig 2 bits of the
10 bit reading and use the same routine! It depends on the number of
quantizing steps you require. You will need 4 working regs

count - used to count 256 loops.

result - holds your A/D reading (not really necessary you can read
it from your A/D reg.)

reshi - stores the most significant 8 bits of averaged signal.

reslo - stores the least sig 8 bits of averaged signal. clrf count ; first DECFSZ instruction will cause
; this reg to go from 00h to 0FFh
Loop
call (Your A/D read routine) ; get the reading, store it
; in the reg called result
; in your A/D routine

movf result,W ; Copy the reading to W reg

addwf reslo,F ; Add it to the LSB reg

btfsc STATUS,C ; if overflow occurs inc MSB reg
incf reshi,F

decfsz count,F ; do it 256 times to get average
goto Loop

movf reshi,W ; (256 readings)/256 in reshi

You're averaged 8 bit reading is now in the reshi reg.
Hope this helps. --- In , "burt0072003" <burt007@i...> 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.


Reply by Phil 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




Reply by martin de lange 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
----- Original Message -----
From: burt0072003
To: p...@yahoogroups.com
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

Reply by Chad Russel 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 burt0072003 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 Chad Russel 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 Dave Mucha 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 Harold Hallikainen 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 Chad Russel 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.

__________________________________