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

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

smoothing with movavg creates offset ??

bsimpkins
12-Amethyst

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?

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(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

View solution in original post

5 REPLIES 5
Werner_E
25-Diamond I
(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

Note

Large 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

RichardJ
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.

Werner_E
25-Diamond I
(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

RichardJ
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.

bsimpkins
12-Amethyst
(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