I need to design a filter to reduce noise from accelerometer readings and use this data to a control system. One of the problems of a simple low-pass filter (like a single pole IIR filter) is the delay introduced by the filter. As an alternative I saw many people using a kalman filter or a median filter. I'm very interested in this median filter due to its simple formulation. But then I realize that it will always have some samples lag in the output. For the filter being able to output the present term, it should be able to read N/2 (or (N-1)/2) terms from the future which is obviously not possible in real time systems. So, at best, its output would be N/2 samples late.

The only difference I see in terms of delay between these two filters is that the low-pass may have different delays for different frequencies input while the median-filter has a constant sample lag. The larger the window size is(which is also related to how smooth our output will be), larger will be this lag. So it might be interesting to reconsider a single pole filter.

Is that reasoning correct?


i would say that your reasoning is a teeny bit flawed.

the delay of an LTI filter is a deterministic function (of frequency) that is unambiguous. a sinusoid of some known frequency goes in and the sinusoid that comes out will be delayed by a predetermined amount of time.

a median filter is not linear. and, if a sinusoid goes in, it will not be a sinusoid coming out. let's say that your causal median filter is outputting the median value of the current input sample and the most recent past $N-1$ samples (the "formulation" may seem "simple", but you're gonna need to repeatedly sort $N$ samples to pick out your median value), you can come up with an expected value of the delay and, since the sample that is eventually chosen to be the median value can be any one those $N$ samples with equal likelihood, then the expected value of the delay is $\frac{N-1}{2}$.


Your reasoning is correct. Note, however, that nobody forces you to use a symmetric window for the median filter. You could use more past values than future values and in this way reduce the delay. You need to experiment with window size and lag to see whether an asymmetrical window gives you sufficient noise reduction.

  • $\begingroup$ I understand what you mean by symmetrical or asymmetrical window but I think that an asymmetrical window is the same as the symmetric one but with a shifted output signal, no? With that said, with a N size window, even though I can output one value immediately after each input, this output value would be the equivalent to the (N-1)/2 sample. So it will always exist this minimum lag, right? $\endgroup$ – FELIPE_RIBAS Jul 17 '14 at 15:48
  • $\begingroup$ @FELIPE_RIBAS: Of course the output is just shifted, but the difference is that you interpret the (time index of the) output differently, and in this way the lag is actually reduced. $\endgroup$ – Matt L. Jul 17 '14 at 16:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.