Olin Lathrop wrote: > It might be better to detect and reject spikes up front, then use > a simple filter afterwards. That's what Fr. Tom seems to have suggested, as well. That approach, however, won't give the same sort of results as a median filter would. Median filters are WONDERFUL for pulling square-wave pulses out of noise; because a median filter always SELECTS from the sampled data rather than creating new data, pulse edges are REALLY sharp. Additionally, the performance of the filter is relatively insensitive to the width of the moving filter window; the filtered output doesn't degrade until the window gets VERY large relative to the width of the pulses you're trying to find. If I were Andy Shaw, I'd probably sample data into a circular buffer, then NOT sort it. Instead of sorting, I'd find the median value by just comparing each value in the buffer with the others, until I found a value that was greater-than or equal to "x" other values AND less-than or equal to "x" other values, where "x" is (number of samples in the buffer - 1)/2. I'm assuming an odd number of samples in the buffer, and that the buffer is relatively small... Like 5 to 15 samples. That process can be really fast, especially if you think a little before implementing the algorithm, and it will let you do the FIFO thing with your circular buffer without requiring any extra RAM for a sorted buffer or array of timestamps. -Andy === Andrew Warren -- aiw@cypress.com === Principal Design Engineer === Cypress Semiconductor Corporation === === Opinions expressed above do not === necessarily represent those of === Cypress Semiconductor Corporation -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.