moving_averageΒΆ

The moving_average function calculates a moving average. This filter can be used to reduce random noise.

rvMean = moving_average(rvY, nNeighbor)

Return Value

rvMean is the moving average. It has the same length as rvY.

Parameters

rvY

rvY is a signal.

nNeighbor

nNeighbor specifies the window width. The window width is 2 * nNeighbor + 1.

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

History

Version Description
5.2.0 New

id-1189333