Hi Olin/folks, See comments below.... > What exactly to you mean by "median filter". It finds the center of the > min/max range of the numbers? Or do you mean box filter which finds the > average? > What I mean is that if you have say five values you sort them into low/high order than select the 3rd value as the output of the filter. Not quite the same as finding the centre of the min max range, rather is selects the "middle value" from the data set. > In any case, this is not hard to do. The processing can be done without > regard to the order of the samples. This means you can keep a circular > buffer with a pointer to the oldest entry. A new entry overwrites the > oldest, then the pointer is advanced by one. If the pointer advances past > the end of the buffer, you reset it to the beginning. To do the > computations, just loop thru the buffer from beginning to end, since it > appears your operation doesn't depend on the order of the samples. > Problem is that most examples I've seen mean that the sort phase re-orders the set of samples making dropping the oldest hard. Obviously you can take a copy and sort that but that requires more storage. > > Note this does not have to be a perfect median filter so an efficient > > implementation that has similar noise removal properties would also work > for > > me. > > A simple low pass filter usually is easier to compute, requires less state, > and has better frequency characteristics. Consider > > FILT <-- FILT + (NEW - FILT) * FF > > where FILT is the filtered output and also the only persistant state, NEW is > the new sample value that the filter is being updated with, and FF is the > filter fraction. Useful values of FF are from 0 to 1, control the > "heaviness" of the filter. FF = 0 makes the filter infinitely heavy in that > its output never changes. FF = 1 disables all filtering as the filter > output is just the value of the last input sample. If samples are coming at > regular intervals, then FF directly controls the filter time constant or > the -3dB rolloff point. Note that if FF is 1 / 2**n, then the multiply by > FF can be performed with a right shift by N. > Yeah the problem with this sort of filter is that a couple of values that are "spikes" can have a big and lasting impact on the filter output. The nice thing about a median filter is that it works very well with data that generally has a very similar value but which has occasional spikes in it..... Thanks Andy -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics