Calculations

Calculations Using a Moving Window

Many of the scripted calculations are implemented using a moving window with a specified window length and window overlap.  This makes it possible to apply the calculation to any desired length of data and to repeat the calculation for the entire data series.  The technique is portrayed below.  Note how the brackets indicating which samples from the original series product a sample in the output series overlap, as defined by the Window Overlap parameter.  Also, note that the first sample in the output series is 1/2 window width offset to the right from the start of the original data series.  The sampling frequency of the output series is much lower than the sampling rate of the original data series.  To maintain the sampling rate of the original series, set the window overlap in samples to be one less than the window length, resulting in a maximal overlap of each window.

 

If the user specifies, the data is zero padded.  It is zero padded with half of one window length at the beginning.  The number of points to pad at the rear is calculated by the following formula:

Rear Pad Size = (Front Pad Size + Data Series Length - Window Overlap)  % (Window Length - Window Overlap)

This ensures that the first point in the data series is in the middle of the first window, as well as that the total size of data series accommodates an whole number of windows.  This causes the calculation to look like this:

A sample implementation of a sliding window calculation looks like this (moving average):

for (var i = 0; i < x.NumPoints; i += winLen - winOverlap)
  y[j++] = x.subset(i, winLen).sum()/winLen;

Here the variable x is the input, and this loop creates a new series y that contains the moving average of the series x.