Tuesday 28 April 2015

digital filters - 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}$.



Answer



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.


enter image description here


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.


No comments:

Post a Comment

readings - Appending 内 to a company name is read ない or うち?

For example, if I say マイクロソフト内のパートナーシップは強いです, is the 内 here read as うち or ない? Answer 「内」 in the form: 「Proper Noun + 内」 is always read 「ない...