.. highlightlang:: us .. index:: smooth .. index:: moving_average .. _moving_average: moving_average ============== .. us.tag moving_average ENGLISH Interpolation New520 The :ref:`moving_average` function calculates a moving average. This filter can be used to reduce random noise. .. function:: rvMean = moving_average(rvY, nNeighbor) .. us.return **Return Value** *rvMean* is the moving average. It has the same length as *rvY*. .. us.params **Parameters** .. uparam:: rvY *rvY* is a signal. .. uparam:: nNeighbor *nNeighbor* specifies the window width. The window width is ``2 * nNeighbor + 1``. .. us.example **Example** :: x = linspace(0, 2*PI, 1000) y = sin(x) + rand(1, 1000) * 0.1 yy = moving_average(y, 10); h = plot(x, y); XYSetProps(h[3], "curve_color = 'blue'"); h = plot(x, yy, h[2]); XYSetProps(h[3], "curve_color = 'red'"); :: * moving_average([1,2,3,4,5,6], 1) 1.5000 2.0000 3.0000 4.0000 5.0000 5.5000 .. us.history **History** .. list-table:: :header-rows: 1 * - Version - Description * - 5.2.0 - New .. seealso:: :ref:`overview-mathematic`, :ref:`moving_median`, :ref:`fspline`, :ref:`pspline`, :ref:`akimaspline`, :ref:`sgolayfilt` :sub:`id-1189333`