cancel
Showing results for
Did you mean:
cancel
Showing results for
Did you mean:

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

6-Contributor

## smoothing with movavg creates offset ??

hi all,

i'm using prime 2.  when i smooth some data with the movavg function, the resulting data is offset by the size of the smoothing window.  in fact, even the helpcenter example on using moving average to smooth data shows this resulting offset!  but with no comment.  attached.

is this a bug or am i using movavg wrong?

1 ACCEPTED SOLUTION

Accepted Solutions
24-Ruby V
(To:bsimpkins)

Here is a suggestion for a symmetrical moving average window

The attached file is in P3 format, so your P2 will not be able to read it - therefor the pic.

WE

5 REPLIES 5
24-Ruby V
(To:bsimpkins)

> is this a bug or am i using movavg wrong?

Neither of the two.

Its simply the way this algorithm works and its explained in more detail in the Data-Smooth-Example. Here the help clearly states

 NoteLarge window widths introduce a time lag.

The reason is that only values to left of the time value are used for calculating the average. You might consider writing your own routine using a synmmetrical window.

Or maybe "medsmooth" or "medfilt1d" (deprecated but still available; replaced by "medsmooth") are more suitable for your purposes.

WE

19-Tanzanite
(To:Werner_E)
 Note Large window widths introduce a time lag.

Yes, a decidedly inaccurate statement, since it's obvious that any window width will introduce a time lag, it's just a question of how big a lag.

 You might consider writing your own routine using a synmmetrical window.

A trick you can use with smoothing functions like this is to reduce the window size, run one smooth, reverse the data, run a second smooth. The second smooth undoes the shift created by the first smooth.

24-Ruby V
(To:bsimpkins)

Here is a suggestion for a symmetrical moving average window

The attached file is in P3 format, so your P2 will not be able to read it - therefor the pic.

WE

19-Tanzanite
(To:Werner_E)

Here is a Savistsky-Golay filter (and a modified version of it that is marginally better). It is a pure convolution operation, and as such does not introduce a shift.

Also look up the ksmooth function, which uses a symmetrical kernel and therefore does not introduce a shift.

6-Contributor
(To:Werner_E)

super!  the symmetric moving average works like a charm.

i'm looking at the savistky-golay versions as well.

Announcements
Top Tags