> -----Original Message----- > From: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu] On Behalf > Of Olin Lathrop > Sent: 23 November 2010 15:23 > To: Microcontroller discussion list - Public. > Subject: Re: [EE] Accurate measurement of battery voltage >=20 > Kerry Wentworth wrote: > >> FILT <-- FILT + FF(NEW - FILT) > >> > >> where FILT is the low pass filter being updated with input value NEW > >> each iteration. FF is the "filter fraction". FF =3D 1 is just a pass > >> thru filter, and FF =3D 0 is a infinitely heavy filter. Useful values > >> are obviously in between. In a small system with limited math > >> capabilities, you often arrange FF =3D 1/(2**N), so that the multiply > >> by FF becomes a right shift by N. > > > > I would normally implement such a filter as: > > > > Total =3D Total + New - Filt > > Filt =3D (Total+1) / Factor >=20 > I'm not sure what exactly that results in, but it's not a single pole low > pass filter, otherwise known as a exponential decay. The simple case of a > unit step input with N=3D1 proves that easily enough. Your filter jumps to > 1 > in the first iteration, then stays there. It also requires more > computation > and more persistant state, so it's not clear what the advantage is. Factor=3D2 causes the output to immediately jump to full scale with a unit input, but after the input falls below 1 it does actually start working as a filter. It's better behaved with high values of 'Factor', though it still has a glitch if the filter starts with an input of 0. =20 As you point out, it's difficult to see what the extra complexity buys you. Regards Mike =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D This e-mail is intended for the person it is addressed to only. The information contained in it may be confidential and/or protected by law. If you are not the intended recipient of this message, you must not make any use of this information, or copy or show it to any person. Please contact us immediately to tell us that you have received this e-mail, and return the original to us. Any use, forwarding, printing or copying of this message is strictly prohibited. No part of this message can be considered a request for goods or services. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .