3.85 FAQ-323 How to perform column calculation over a sliding window, such as moving average or moving standard deviation?

Last Update: 10/31/2022

Use Built-in Moving/Rolling Functions

Origin provides several built-in functions that let you specify backward and/or forward window size:
Movavg, Emovavg, Mmovavg, Movcoef, Movrms, Movslope, Tmovavg, and Wmovavg.

For example, to use the Movavg function, in the Set Values dialog, do the following:

  1. Select the column or cells where you want to put the result.
  2. Select from menu Column: Set Column Value... to open the dialog (or press CTRL + Q from keyboard).
  3. In the opened dialog, click Function: Statistics: Movavg(vd,back,forward) to auto-fill the movavg function in the column formula text box.
  4. Replace vd with the range on which you want to compute a moving average.
  5. Replace back with the backward offset respect to current position, and forward with the forward offset respect to current position.
  6. Click the OK button.


Modify other functions to be Moving/Rolling Functions

You can use sub-ranges in your Set Column Value formula to specify a sliding window.

For example, to calculate the standard deviation over a window size of 11, you can specify sub-range in your formula, such as:

StdDev(A[i-5:i+5])

Calculating the moving standard deviation on large data sets may be very slow. In such cases, we can define the formula using embedded Python in Origin. In the example below, the rolling() function in the Pandas package is used which greatly expedites the calculation speed.


PythonSVC.png


Use the Formula: Load Sample menu in the Set Values dialog for examples on column value calculations.





Note: To calculate moving average on a plot, you can use Analysis: Signal Processing: Smoothing tool and set Method as Adjacent-Averaging.


Keywords:Moving, Rolling, Sliding, average, mean, standard deviation, std, SMA