On 23 Sep 97 at 12:32, Lawrence Lile wrote: > I've got a stream of numbers from 0 to 15 coming out of a PIC '620 > comparator representing temperature of an appliance. When I turn on > the flourescent lamp on my bench, the program picks up a spike, and > the relay in this thing fires momentarily, because it reads the > noise. "NO PROBLEM" I sez, and sat down to write an averaging > algoritm. > Lawrence, Are you sure that an averaging algorithm is what you need? The problem you describe suggests you need a spike filter. I have had good luck in cases like this by using 'median' filtering. This consists simply using the middle value of the N most recent readings. To make things unambiguous, N should be odd. I usually use 5. You need to keep a stack of the five most recent readings. Copy the stack, sort it and use the middle value. This tends to throw out extreme readings which sounds like it might fit your application. If you want some details, send me a note. -- Bob Fehrenbach Wauwatosa, WI bfehrenb@execpc.com