Exponential weighted moving average time constant

I think it is an easy question but I am stuck.

I want to derive that $$\alpha = -e^{\frac{-T}{\tau}}\,.$$

Can someone provide me with an answer?

[EDIT] Sorry guys, this was really a senseless question. Here are some more informations. The differential equation of the EWMA: $$y(n)=\alpha\cdot x(n)+(1-\alpha)y(n-1)$$ and the corresponding frequency magnitude response: $$H_E(z)=\frac{\alpha}{1-(1-\alpha)z^{-1}}$$ and in the frequency domain for $\omega_s=1 \rightarrow T=1$ : $$H_E(\omega)=\frac{\alpha}{\sqrt{1-2(1-\alpha)\cos(\omega)+(1-\alpha)^2}}$$ $$\tau=\frac{1}{2\pi\omega_{3dB}}$$

Hence $$H_E(\omega_{3dB})=\frac{\alpha}{\sqrt{1-2(1-\alpha)\cos(\omega_{3dB})+(1-\alpha)^2}}\overset!=\frac{1}{\sqrt{2}}\text.$$

I'm looking for $\alpha$, given an $\omega_{3dB}$.

• You will have to explain what $\alpha$ should be. Also, if you ask me, a moving average can't be exponentially weighted -- otherwise, it wouldn't really be an average (by the usual definition of average), but just a low pass filter. Jan 16 '16 at 12:48
• "can someone provide me with an answer?": Probably, yes, but you have not asked a question! Jan 16 '16 at 12:50
• (This should have been a comment if I had enough reputation.) In the comment to Matt's comprehensive answer, as well as in the original question, @Slev1n has asked about the relation suggesting $\alpha = -e^{-\frac{T}{\tau}}$, while Matt has arrived at the formula $1 - e^{-\frac{T}{\tau}}.$ While it is impossible to have $\alpha = -e^{-\frac{T}{\tau}}$ as $\alpha$ is assumed to be positive, it is possible to have $\alpha = e^{-\frac{T}{\tau}}$ with another interpretation of $\alpha$. In some sources, $\alpha$ is the coefficient before the previous output rather than the current input, so \$\alp Dec 11 '19 at 22:42

If I understood you correctly, you want to compute the value of $$\alpha$$ that results in a specified 3dB cut-off frequency for an exponentially weighted moving average filter. If you square your last equation, you get

$$\frac{\alpha^2}{1-2(1-\alpha)\cos(\omega_c)+(1-\alpha)^2}=\frac12\tag{1}$$

which can be rearranged into the following quadratic equation:

$$\alpha^2+2\alpha(1-\cos(\omega_c))-2(1-\cos(\omega_c))=0\tag{2}$$

with the positive solution

$$\alpha = \cos(\omega_c)-1+\sqrt{\cos^2(\omega_c)-4\cos(\omega_c)+3}\tag{3}$$

So, e.g., for a desired cut-off frequency $$\omega_c=0.2\pi$$, you obtain from $$(3)$$ a value of $$\alpha=0.455886780102867$$. The figure below shows the magnitude of the frequency response of the resulting exponentially weighted moving average filter, from which you can see that the desired cut-off frequency is achieved. EDIT: The formula for $$\alpha$$ in your question should actually be

$$\alpha=1-e^{-T/\tau},\qquad \tau=1/\Omega_c\tag{4}$$

Note that unlike $$\omega_c$$ in Eq. $$(3)$$, $$\Omega_c$$ in Eq. $$(4)$$ is not normalized by the sampling frequency. So we have $$-T/\tau=-\Omega_cT=-\omega_c$$.

Eq. $$(4)$$ is an approximation, and it comes from applying the impulse invariant transformation to the continuous-time transfer function

$$H(s)=\frac{1}{1+s\tau}\tag{5}$$

which has a 3dB cut-off frequency $$\omega_c=1/\tau$$. Applying the impulse invariant transformation to $$(5)$$ gives

$$H(z)=\frac{T}{\tau}\frac{1}{1-e^{-T/\tau}z^{-1}}\tag{6}$$

Comparing the denominator of $$(6)$$ with the denominator of the discrete-time transfer function of an EWMA filter

$$H(z)=\frac{\alpha}{1-(1-\alpha)z^{-1}}\tag{7}$$

results in the given formula. Note, however, that this is only an approximation. Especially for cut-off frequencies close to Nyquist, the error of formula $$(4)$$ becomes relatively large.

• Hey Matt, thanks for your help. Your formula is correct, but I also found the relation: $$\alpha = -e^{\frac{-T}{\tau}}\,.$$ And now I am wondering how to get from yours to mine... Jan 17 '16 at 10:25
• @Slev1n: I've updated my answer to explain where that approximation comes from. Note that it is not exact, unlike the formula in my answer. Jan 17 '16 at 13:43

This answer addresses the OP's original question by a mathematically rigorous deduction. In deference to the earlier answer, the notation adheres to it as much as necessary and in particular we denote the cut-off frequency of the low pass filter by $$\Omega_c$$ ($$=\frac{1}{\tau}$$ in the OP and previous answer), the sampling time by $$\Delta t$$ ($$=T$$ in the OP and previous answer). In what follows, the variable of time is denoted in the subscript.

The impulse invariant discrete formulation of the ideal low pass filter is obtained from the solution to the first order linear differential equation of the scalar (one dimensional) differential equation corresponding to the Laplace transform of the filter $$H(s) := \frac{Y(s)}{U(s)} := \frac{\Omega_c}{s + \Omega_c}$$ for all $$0 < \Omega_c$$, as (see equation (19) of these lecture notes) $$y_{t+\Delta t} = \rm{e}^{-\Omega_c (t+\Delta t-t)} y_{t} + \int_t^{t+\Delta t} \rm{e}^{-\Omega_c((t+\Delta t)-\tau)} \; \Omega_c u_{\tau} \; d\tau \\= \rm{e}^{-\Omega_c \Delta t}y_{t} + \rm{e}^{-\Omega_c (t+\Delta t)} \int_t^{t+\Delta t} \rm{e}^{ \Omega_c\tau }\; \Omega_c u_{\tau} \; d\tau \\\stackrel{\Delta t \rightarrow 0}{=} \rm{e}^{-\Omega_c \Delta t}y_{t} + \rm{e}^{-\Omega_c (t+\Delta t)} \; \Omega_c u_{t} \;\int_t^{t+\Delta t} \rm{e}^{ \Omega_c\tau }\; d\tau \\{=} \rm{e}^{-\Omega_c \Delta t}y_{t} + \frac{\rm{e}^{-\Omega_c (t+\Delta t)}}{\Omega_c} \; \Omega_c u_{t} \; (\rm{e}^{ \Omega_c({t+\Delta t}) } - \rm{e}^{ \Omega_c t }) \\{=} \rm{e}^{-\Omega_c \Delta t} y_{t} + u_{t} (1 - \rm{e}^{ -\Omega_c \Delta t }).$$ on applying the limit as $$\Delta t \rightarrow 0$$ for the input impulse $$u_t$$ at the time instant $$t$$. Denoting $$0 < \alpha := 1 - \rm{e}^{ -\Omega_c \Delta t } < 1$$ we recover the standard exponential moving average filter (exponential smoothing) formulation of the low pass filter expressed in discrete time formulation as $$y_n = \alpha u_{n-1} + (1 - \alpha) y_{n-1}$$.

Indeed, the above derivation illustrates the manipulation by which the impulse invariant (and in this case also equal to the matched Z-transform) Z-transform of the s-domain Laplace transform $$H$$ is obtained.

As noted in the previous answer, the impulse invariant transformation of the ideal or s-domain analog low pass filter to the z-transform would lead to increasing errors as the frequency approaches the Nyquist frequency. The relevant quote from the wiki addressing the impulse invariant transformation is as follows.

Note that aliasing will occur, including aliasing below the Nyquist frequency to the extent that the continuous-time filter's response is nonzero above that frequency. The bilinear transform is an alternative to impulse invariance that uses a different mapping that maps the continuous-time system's frequency response, out to infinite frequency, into the range of frequencies up to the Nyquist frequency in the discrete-time case, as opposed to mapping frequencies linearly with circular overlap as impulse invariance does.

More specifically, the bilinear transform maps s-domain frequency response features of the desired filter to that of the transformed z-domain filter.

The transform preserves stability and maps every point of the frequency response of the continuous-time filter, $$H_{a}(j\omega _{a})}$$ to a corresponding point in the frequency response of the discrete-time filter, $$H_{d}(e^{j\omega _{d}T})}$$ although to a somewhat different frequency, as shown in the Frequency warping section below. This means that for every feature that one sees in the frequency response of the analog filter, there is a corresponding feature, with identical gain and phase shift, in the frequency response of the digital filter but, perhaps, at a somewhat different frequency. This is barely noticeable at low frequencies but is quite evident at frequencies close to the Nyquist frequency.