# The Logic Behind Cascading a Moving Average Filter After a Median Filter

Why do we cascade a median filter and a moving average filter?

I know how each filter performs, but I do not know the difference between these two filters in denoising application and what is the effect of cascading them?

• In the cascaded filters you're studying does the averaging filter follow the median filter? Nov 28, 2022 at 12:32
• Hello @RichardLyons , yes, averaging filter is placed after the median filter. Nov 28, 2022 at 12:36
• Ah ha. OK, that makes sense. If the output sequence of the median filter, what ever that output means, is fluctuating in value then the averaging filter smooths (reduces fluctuations) of the median filter’s output to give you a more statistically accurate measure of the median filter’s output. Nov 29, 2022 at 2:06

You may look at it as an outlier rejection step.
We can visualize it by a simple example.

Assume that we have a signal from a DC source with added Gaussian White Noise.
Assume the signal has 10 samples.

In order to estimate the DC level one can calculate the mean of those samples.
Now assume there is a single sample which is corrupted by a big outlier value.

Now if we calculate the mean of the samples the output is deviated by the outlier sample.
By applying the median filter we minimize the effect of the outlier and then the output of the mean filter is stabilized.

In the context of Denoising the median filter is considered an Edge Preserving Filter. Because of its ability to remove Salt and Pepper like noise (Impulse noise) while preserving details (Piece Wise Smooth model).

So you may think of this operation as filtering impulse noise and then filtering wide band noise given our data model is relatively narrow band.

A sliding median filter can and does have some jump discontinuities in its output. A sliding average filter is an LTI low-pass filter and any jump discontinuity will become a sloping function that moves toward the final value.

So the averaging filter is there just to smooth things out. But the result really is a median result, and being a median, will not be affected by extreme outliers, whereas if the median filter was removed, the output of the sliding average definitely would be affected by extreme outliers.