Calculates the moving average of a series or table.
MOVAVG(series, N, rampflag, "naflag", "edgeflag")
series |
- |
A series or table |
||||||||||||
N |
- |
An integer, the segment size. The number of points to average as the series is traversed. |
||||||||||||
rampflag |
- |
Optional. An integer, endpoint ramp flag.
|
||||||||||||
"naflag" |
- |
Optional. A string, the NA handling method.
|
||||||||||||
"edgeflag" |
- |
Optional. A string, the edge processing flag.
|
A series or table.
W1: {4, 3, 2, 1, 2, 3, 4}
W2: movavg(w1, 3)
W2 == {4, 3.5, 3, 2, 1.6667, 2, 3, 3.5, 4}
Computes the average of each overlapping moving segment of length 3 but the segment length and segment divisor adjust from 1 to 3 at the start edge and from 3 to 1 at the end edge.
W1: {4, 3, 2, 1, 2, 3, 4}
W3: movavg(w1, 3, 0)
W3 == {1.3333, 2.3333, 3, 2, 1.6667, 2, 3, 2.3333, 1.3333}
Same as above where the segment length adjusts from 1 to 3 at the start edge and from 3 to 1 at the end edge but the segment divisor remains fixed at 3.
W1: {4, 3, 2, nan, 2, 3, 4}
W2: movavg(w1, 3)
W3: movavg(w1, 3, "includenan")
W2 == {4, 3.5, 3, 2.5, 2, 2.5, 3, 3.5, 4}
W3 == {4, 3.5, 3, nan, nan, nan, 3, 3.5, 4}
W2 excludes all NaN values by removing them from the segment and adjusting the segment size and segment divisor down.
W3 retains NaN values and returns NaN if any NaN is present in the segment.
W1: {4, 3, 2, nan, 2, 3, 4}
W2: movavg(w1, 3, 0)
W3: movavg(w1, 3, 0, "includenan")
W2 == {1.3333, 2.3333, 3, 2.5, 2, 2.5, 3, 2.3333, 1.3333}
W3 == {1.3333, 2.3333, 3, nan, nan, nan, 3, 2.3333, 1.3333}
Same as above except the segment divisor remains fixed at 3.
W1: {4, 3, 2, 1, 2, 3, 4}
W2: movavg(w1, 3, "center")
W3: movavg(w1, 3, 0, "center")
W2 == {3.5, 3, 2, 1.6667, 2, 3, 3.5}
W3 == {2.3333, 3, 2, 1, 2, 3, 2.3333}
W2 and W3 compute a 3-point centered moving average where the result at point N is the average of points N-1, N and N+1.
For W2, the segment length and segment divisor adjust from 1 to 3 at the start edge and from 3 to 1 at the end edge.
For W3, the segment length also adjusts from 1 to 3 at the start edge and from 3 to 1 at the end edge, but the segment divisor remains fixed at 3.
W1: {4, 3, 2, 1, 2, 3, 4}
W2: movavg(w1, 3, "discard")
W3: movavg(w1, 3, 0, "discard")
W2 == {3, 2, 1.6667, 2, 3}
W3 == {3, 2, 1.6667, 2, 3}
W2 and W3 compute a 3-point moving for all overlapping segments that contain exactly 3 samples. Shorter segments at the start and end edges are discarded. The rampflag parameter has no effect.
W1: {4, 3, 2, 1, 2, 3, 4}
W2: movavg(w1, 3, "shrink")
W3: movavg(w1, 3, 0, "shrink")
W2 == {4, 3.5, 3, 2, 1.6667, 2, 3, 3.5, 4}
W3 == {4, 3.5, 3, 2, 1.6667, 2, 3, 3.5, 4}
Same as the first example, where the average of each overlapping moving segment of length 3 is computed but the segment length and segment divisor adjust from 1 to 3 at the start edge and from 3 to 1 at the end edge. The rampflag is essentially forced to 1.
In particular, for series x of length N, movavg(x, 3) returns the following N+2 length series:
If rampflag is 0, movavg(x, 3, 0) returns the following N+2 length series:
MOVAVG operates on Real and Complex series.
NaN values are ignored by default. Set naflag to "includenan" to process NaN values.
For the default, where
The default options cause a phase shift
in peak locations. Use
For
For
MOVAVG pads the series with zeros at the beginning and end before computing the average. MOVAVG2 does not pad in such a way.
See MOVMEAN to compute a centered moving average.
See LINAVG to compute a moving average with zero phase shift.
See EXPMOVAVG to compute the exponential moving average.
See BLOCKAVG to compute a non-overlapping moving average.
See XMOVAVG to compute a moving average given a time duration.