# What is the difference between linear and non-linear filters?

How a mean filter is called as linear filter and a median filter is called as non linear filter? I understand how a mean and median filter operates, but I was not able to relate with the term linear and non-linear. Please explain me with an example.

Nonlinear filters are those for which the linearity relationship breaks down. Consider two signals $A$ and $B$, for linear filter such as mean filter $F_m$,you have $F_m(A+\lambda B) = F_m(A) + \lambda F_m(B)$, but the equation is not satisfied for an nonlinear filter such as the median filter.

In application, the median filter removes outliers and shot noise that is independent of magnitude, while mean filter serves as smoothing purpose. To understand the linearity property more easily.Let us consider the above diagram,here we have 2 sequences namely Xn and Yn. when we add both the sequence we get Xn+Yn whose amplitude value are represented with blue colour. when any system which satisfy this condition then it is called linear. In case of mean filter, mean value for sequence Xn is 1+1+3/3=5/3.mean value for sequence Yn is 1+2+0/3=1.mean value for Xn+Yn is 2+3+3/3=8/3.

$mean(Xn)+mean(Yn)= mean(Xn+Yn), \\ \\ 5/3 + 1 = 8/3$

hence we called mean filter as linear filter. In case of median filter, if we calculate median value for sequence Xn, we get 1 (arrange the sequence in ascending order and then find the middle value). similarly median value of sequence Yn is 1 .median value of sequence Xn+Yn is 3.

$median(Xn)+median(Yn) \neq median(Xn+Yn).\\ \\ 1 + 1 \neq 3$

hence we call median filter as non-linear filter

• nice explanations especially for beginners like me! – snr Oct 29 '18 at 8:31
• should be the best ans – Turing101 Dec 9 '19 at 17:47

In a linear filter, the output will change linearly with a change in the input. You could plot some sort of straight line from the relationship between the two.

A median filter can change non-linearly with certain input changes. e.g. take an input vector where all the data values are different: a change in a non-middle value won't affect the median output at all, until when that value rises or falls enough to become the middle item, when it can suddenly completely affect the output. Thus producing a kinked line (non-linear), instead of a straight line (linear) when the relationship is plotted.