Contenuto principale

Median Filtering

The function medfilt1 implements one-dimensional median filtering, a nonlinear technique that applies a sliding window to a sequence. The median filter replaces the center value in the window with the median value of all the points within the window [5]. In computing this median, medfilt1 assumes zeros beyond the input points.

When the number of elements n in the window is even, medfilt1 sorts the numbers, then takes the average of the n/2 and n/2 + 1 elements.

Two simple examples with fourth- and third-order median filters are

medfilt1([4 3 5 2 8 9 1],4)
ans =
    1.500 3.500 3.500 4.000 6.500 5.000 4.500

medfilt1([4 3 5 2 8 9 1],3) ans = 3 4 3 5 8 8 1

See the medfilt2 (Image Processing Toolbox) function in the Image Processing Toolbox™ for information on two-dimensional median filtering.