Solved – Tuning an exponential moving average to a moving window mean

calibrationexponential-smoothingmoving averagemoving window

The alpha parameter of an exponential moving average defines the smoothing that the average applies to a time series. In a similar way, the window size of a moving window mean also defines the smoothing.

Is there some way to tune the alpha parameter such that the smoothing is approximately the same as that of a moving window mean of a given size? (Not looking for identical results, obviously, and offsets are OK). So, say tune alpha such that the resultant time series is as close as possible in shape to the result provided by a 3-month moving window?

edit: context: I'm trying to generate multiple proxy for soil moisture, from rainfall data, which abstractly represent different depths (which I'm assuming are related to long-term rainfall averages). A moving window allows me to calculate e.g total rainfall in the past 3 days, 3 months, or year, which might correspond to top few centimetres of soil, the top meter, and the extended soil column, respectively. However, a moving window requires data from the past, which isn't always available (e.g. at the start of a series). If an exponential average is used instead, then I only need to store one value for each average (the average from the previous time step), and this value can be initialised with the long-term mean.

Best Answer

Let $x$ be the original time series and $x_m$ be the result of smoothing with a simple moving average with some window width. Let $f(x, \alpha)$ be a function that returns a smoothed version of $x$ using smoothing parameter $\alpha$.

Define a loss function $L$ that measures the dissimilarity between the windowed moving average and the exponential moving average. A simple choice would be the squared error:

$$L(\alpha) = \|x_m - f(x, \alpha)\|^2$$

If you want the error to be invariant to shift/scaling, you could define $L$ to be something like the negative of the peak height of the normalized cross correlation.

Find the value of $\alpha$ that minimizes $L$:

$$\underset{\alpha}{\min} L(\alpha)$$

Here's an example using a noisy sinusoidal signal and the mean squared error as the loss function:

enter image description here

Another example using white noise as the signal:

enter image description here

The loss function appears to be well behaved and have a single global minimum for these two different signals, suggesting a standard 1d optimization solver could work (as I used to select $\alpha$ here). But, I haven't verified that this must be the case. If in doubt, plot the loss function and use a more sophisticated optimization method if necessary.

Edit:

Here's a plot of the optimal alpha (for exponential smoothing) as a function of window size (for simple moving average). Plotted for each of the signals shown above.

enter image description here