moving_medianΒΆ
The moving_median function calculates a moving median. The function operates over a moving window of values. For each window, the middle value found in the window is used.
This filter can be used to reduce random noise and spikes.

rvMedian = moving_median(rvY, nNeighbor)
Return Value
rvMedian is the moving median. It has the same length as rvY.
Parameters

rvY
rvY is a signal.

nNeighbor
nNeighbor specifies the window width. 3 <= nNeighbor <= 1025.
Example
In the following example 5 consecutive points are sorted ascending and the
third point is used. For a window size of 5, the first 2 point and the last 2
points are not altered. The first calculated point in rvOut is the third
point: [4,5,6,7,27] > 6
, [4,6,7,8,27] > 7
rvIn = [5, 7, 6, 4, 27, 8, 4, 5]
rvOut = moving_median(rvIn, 5)
rvOut > [5, 7, 6, 7, 6, 8, 4, 5]
x = linspace(0, 2*PI, 1000)
y = sin(x) + rand(1, 1000) * 0.1
yy = moving_median(y, 11);
h = plot(x, y);
XYSetProps(h[3], "curve_color = 'blue'");
h = plot(x, yy, h[2]);
XYSetProps(h[3], "curve_color = 'red'");
History
Version  Description 

5.14.9  New 
See also
Overview Mathematic, moving_average, fspline, pspline, akimaspline, sgolayfilt
_{id244162}