Bob Lunn 09/24/97 02:24 PM > Anybody got a good averaging algorithm? Lawrence, you've had a number of good responses (especially the suggestion to use a median filter, though this depends critically on your sample rate, spike width, etc.), but not much directly addressing your original question. First, keep in mind that because you have a continuous data stream you are actually interested in filtering rather than averaging. Casually, we often talk about 'rolling' or 'running' _averages_ when we really mean an IIR (infinite impulse response) filter. Take the simplest case: val = (val + sample) / 2 This requires only the calculated (running) value, and the latest sample. You can also see why this is called an INFINITE impulse response filter. A very large sample can effect a large number (potentially infinite number) of subsequently calculated values. The response of the filter to an impulse can extend indefinitely. Take the next simplest case: val = (val + old_sample + sample) / 3 old_sample = sample Take the next simplest case: val = (val + oldest_sample + old_sample + sample ) / 4 oldest_sample = old_sample old_sample = sample You get the picture... Now consider FIR (finite impulse response) filters. Take the simplest case: val = (old_sample + sample) / 2 old_sample = sample You can see the difference. The calculated value depends ONLY on the two latest samples. A very large sample can effect only the current value and the next calculated value. After that, the large sample (spike) no longer influences the calculated value. The response of the filter to an impulse extends finitely. Take the next simplest case: val = (oldest_sample + old_sample + sample ) / 3 oldest_sample = old_sample old_sample = sample Again, you get the picture... Now, in all the preceeding examples each sample is assigned the same 'weight'. If you really want to get into filtering you need to assign different weights to the samples and from this derive different filter characteristics. ___Bob