# Low-pass vs median filter delay

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?

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}$.