MOVMEAN

Purpose:

Calculates the centered moving average of a series or table.

Syntax:

MOVMEAN(series, N, "naflag", "edgeflag")

series

-

A series or table.

N

-

An integer, the segment size. The number of points to average as the series is traversed.

"naflag"

-

Optional. A string, the NA handling method.

"omitnan"

:

ignore NA values)

"includenan"

:

include NA values (default)

"edgeflag"

-

Optional. A string, the edge processing flag.

"discard"

:

only process segments of length N, ignore partial segments

"shrink"

:

shrink the size of both the start and end segments to the actual number of samples in the segments (default)

Returns:

A series or table.

Example:

W1: {4, 3, 2, 1, 2, 3, 4}

W2: movmean(w1, 3)

W3: movavg(w1, 3)

W4: movavg(w1, 3, "center")

 

W2 == {3.5, 3, 2, 1.6667, 2, 3, 3.5}

W3 == {4, 3.5, 3, 2, 1.6667, 2, 3, 3.5, 4}

W4 == {3.5, 3, 2, 1.6667, 2, 3, 3.5}

 

W2 and W4 compute a standard 3-point centered moving average. The value at any point N is the average of points N-1, N and N+1.

 

W3 also calculates the average of each overlapping segment of up to length 3, but it employs variable edge handling to fully include the start and end points. The segment length and segment divisor smoothly adjust from 1 to 3 at the start edge and from 3 to 1 at the end edge.

Example:

W1: {4, 3, 2, nan, 2, 3, 4}

W2: movmean(w1, 3)

W3: movmean(w1, 3, "omitnan")

 

W2 == {3.5, 3, nan, nan, nan, 3, 3.5}

W3 == {3.5, 3, 2.5, 2, 2.5, 3, 3.5}

 

W2 preserves NaNs and returns NaN when any value in the segment is NaN.

 

W3 excludes NaNs, reducing the segment length and divisor accordingly.

Example:

W1: {4, 3, 2, 1, 2, 3, 4}

W2: movmean(w1, 3)

W3: movmean(w1, 3, "discard")

 

W2 == {3.5, 3, 2, 1.6667, 2, 3, 3.5}

W3 == {3, 2, 1.6667, 2, 3}

 

W2 computes a 3-point centered moving average identical to the first example.

 

W3 computes a 3-point moving for all overlapping segments that contain exactly 3 samples. Shorter segments at the start and end edges are discarded.

Remarks:

MOVMEAN computes a centered moving average by centering the result within the N-point sliding segments. The output length is the same as the input length. By centering the result, MOVMEAN eliminates the phase shift in peak locations resulting from the default application of MOVAVG.

 

NaN values are included by default. Set naflag to "omitnan" to ignore NaN values.

 

For edgeflag == "discard", only segments that contain exactly N samples are processed. Shorter segments at the start and end edges are discarded.

 

See MOVAVG for more details on the naflag and edgeflag flags.

 

See LINAVG to for an alternate computation of the moving average with zero phase shift.

See Also:

AVGFILT

BLOCKAVG

CUMAVG

EXPMOVAVG

LINAVG

MOVAVG

MOVAVG2

MOVMAX

MOVMEDIAN

MOVMIN

MOVSTD

SGOLAYFILT

XBLOCKAVG

XMOVAVG