.. highlightlang:: us .. index:: smooth .. index:: moving_median .. _moving_median: moving_median ============= .. us.tag moving_median ENGLISH Interpolation New5149 The :ref:`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. .. function:: rvMedian = moving_median(rvY, nNeighbor) .. us.return **Return Value** *rvMedian* is the moving median. It has the same length as *rvY*. .. us.params **Parameters** .. uparam:: rvY *rvY* is a signal. .. uparam:: nNeighbor *nNeighbor* specifies the window width. 3 <= *nNeighbor* <= 1025. .. us.example **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'"); .. us.history **History** .. list-table:: :header-rows: 1 * - Version - Description * - 5.14.9 - New .. seealso:: :ref:`overview-mathematic`, :ref:`moving_average`, :ref:`fspline`, :ref:`pspline`, :ref:`akimaspline`, :ref:`sgolayfilt` :sub:`id-244162`