Re: [Algorithms] Truncate then average? Or average then truncate?
Brought to you by:
vexxed72
From: Tom F. <tom...@ee...> - 2010-05-28 22:19:06
|
Not sure I understand what answer you want out of the last example. The value is 63.5 +/- 0.5. You can either get back 63 or 64, but no matter how you filter it, that value will still oscillate slightly at some ADC setting. If you literally want no change if there's only a noise variance, just do a threshold trick - do the filtering the way you're doing it, and then if the filtered result is within some epsilon of the previously-returned value, keep returning that previous value. Otherwise, send the new value. It's a standard trick for things like analogue joysticks. It works OKish, but has bizarre stair-step response to slow movement (whereas a properly-filtered answer will also move slowly). TomF. > -----Original Message----- > From: Robin Green [mailto:rob...@gm...] > Sent: Friday, May 28, 2010 10:02 AM > To: Game Development Algorithms > Subject: Re: [Algorithms] Truncate then average? Or average then > truncate? > > OK, imagine this. We have a noisy two lowest bits, so we're removing > the bottom three bits of the value and averaging four samples. If the > value is around 180 we get: > > 10110101b > + 10110100b > + 10110110b > + 10110101b > --------------- > 1011010100b >> 2 > --------------- > = 1011010b > > But if the value is close to a power of two, e.g. 64, we get unstable > values: > > 1000000b > + 0111111b > + 1000001b > + 0111111b > ------------ > 11111111b >> 2 > ------------ > = 0111111b > > The noise in the LSBs ends up bits flipping bits high up in the number > in a way that truncating doesn't solve. Mr Bunnell is right, I should > probably look more into numerical filtering rather than bit tricks. > Duh. > > - Robin Green. > > > On Fri, May 28, 2010 at 9:06 AM, Jeremiah Zanin > <Jer...@vo...> wrote: > > Broken divider? I don't see how the noise bits can bleed into the > other bits after dividing unless it's rounding up. Have you tried > taking a power of two samples and shifting instead of dividing? > > > > ----------------------------------------------------------------------- > ------- > > _______________________________________________ > GDAlgorithms-list mailing list > GDA...@li... > https://lists.sourceforge.net/lists/listinfo/gdalgorithms-list > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_name=gdalgorithms- > list > No virus found in this incoming message. > Checked by AVG - www.avg.com > Version: 8.5.437 / Virus Database: 271.1.1/2861 - Release Date: > 05/28/10 06:25:00 |