At 09:28 PM 5/11/00 -0700, Andy wrote: >KŸbek Tony wrote: > > > I have an recursive moving average filter, 52 points with 3 bytes > > each, which works ok. However the ram usage is 'a bit' high :-) ( > > almost the entire two top ram banks on my 16f876, ) > > > > Are there any other, more space conservatory, techniques one could > > use to accomplish the same filtering ? > >Tony: > >The usual way to solve this problem is this: > > TEMP = AVERAGE * WIDTH > TEMP = TEMP - AVERAGE > TEMP = TEMP + NEW_SAMPLE > AVERAGE = TEMP/WIDTH The simplest method is to use an exponentially-weighted, moving average filter: NewEst = OldEst + alpha*(NewData-OldEst) where OldEst = previous filtered estimate (start with first data point) NewEst = new filtered estimate NewData = current data point (measurement) alpha = weighting factor This is asymptotically equivalent to a moving average filter of run length approximately 1/alpha. So alpha = 0.125 would roughly correspond to an 8-sample moving average, etc. Notes: 1. Obviously there is a time lag between the filtered estimate and the latest data (as there is in all integration filters) of about 1/(2 alpha) samples. 2. If you are concerned about the increased error in the first few samples, you can generate a slightly more complicated optimum (Kalman) filter. (This involves a changing weighting factor). 3. The optimum value for alpha is about equal in magnitude to the 1-order autocorrelation of the data. ================================================================ Robert A. LaBudde, PhD, PAS, Dpl. ACAFS e-mail: ral@lcfltd.com Least Cost Formulations, Ltd. URL: http://lcfltd.com/ 824 Timberlake Drive Tel: 757-467-0954 Virginia Beach, VA 23464-3239 Fax: 757-467-2947 "Vere scire est per causas scire" ================================================================