OK, I think I see it. My Total is your Filt, except Total is right=20 justified, and Filt is left justified. Both contain 14 significant bits=20 (assuming N=3D16). My Filt is the Total (or your Filt) right justified and truncated (or=20 rounded) to 10 bits, to give a filtered A/D between 0 and 1023. This=20 step is optional, if one wanted the 14 bit number, one could skip the=20 conversion. And your FF(NEW - FILT) is really (NEW - FILT) / FF. Is this correct? Kerry Olin Lathrop wrote: > Kerry Wentworth wrote: > =20 >>> Right. You generally want to use Log2 fraction bits to avoid this. >>> =20 >> Where are your fractional bits? >> =20 > > Where they ususally are, to the right of the binary point. > > =20 >> In Filt? >> =20 > > In all the values. Everything is a fixed point number with the specified > number of fraction bits. To be clear, the algorithm I mentioned was: > > FILT <-- FILT + FF(NEW - FILT) > > NEW and FILT are expressed as fixed point values. This is usually easy o= n a > PIC when NEW is successive A/D readings by using the left justify A/D res= ult > mode. For example, with the common 10 bit PIC A/D, you automatically get > each reading in 10.6 fixed point format in left justify mode. > > The minimum number of fraction bits you need to not loose information > is -Log2(FF). For example, if FF =3D 1/16, then you need 4 fraction bits= .. > > In the other method that uses TOTAL, you still need the extra 4 bits but > they are on the high end of the number. For example, if filtering 10 bit > values with FF =3D 1/16, then TOTAL needs to be 14 bits wide. Note that = TOTAL > then has exactly the same representation as FILT. It makes no difference > whether you consider it in the scale of the original value with 4 fractio= n > bits, or in the scale of the original value times 16. The bits inside th= e > processor are exactly the same. > > The only real difference between these methods is that yours requires the > additional piece of persistant state, being the TOTAL accumulator. You c= an > do some substitutions in your algorithm to reduce it to what I described > above. > > =20 >> Are you doing floating point math? >> =20 > > You can, but this discussion was about fixed point. There have been a fe= w > cases where I've done that where I needed precise control over the time > constant or on the host computer with floating point hardware or where > cycles don't matter anyway. > > > ******************************************************************** > Embed Inc, Littleton Massachusetts, http://www.embedinc.com/products > (978) 742-9014. Gold level PIC consultants since 2000. > =20 --=20 Internal Virus Database is out-of-date. Checked by AVG Anti-Virus. Version: 7.0.289 / Virus Database: 267.11.13 - Release Date: 10/6/05 --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .