Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Post History

66%
+2 −0
Q&A Moving average that uses less memory?

I'm adding this as a corollary to Olin's post, in case an exact formula for attenuation is needed. That basic IIR is derived from the exponential moving average, and its impulse response is: $$h[n]...

posted 4y ago by a concerned citizen‭  ·  edited 4y ago by Mithrandir24601‭

Answer
#2: Post edited by user avatar Mithrandir24601‭ · 2020-10-25T09:34:13Z (about 4 years ago)
Added lines to mathjax
  • I'm adding this as a corollary to Olin's post, in case an exact formula for attenuation is needed.
  • That basic IIR is derived from the [exponential moving average](https://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average), and its impulse response is:
  • $$h[n]=\alpha x[n]+(1-\alpha)x[n-1]$$
  • which translates into this transfer function:
  • $$H(z)=\frac{\alpha}{1-(1-\alpha)z^{-1}}$$
  • This can be used to determine analytically the attenuation at a particular frequency, by simply substituting \$z^{-1}=\text{e}^{-j\Omega}\$:
  • $$
  • H(j\Omega)=\frac{\alpha}{1-(1-\alpha)\text{e}^{-j\Omega}} \\
  • |H(j\Omega)|=\frac{\alpha}{\sqrt{2(\alpha-1)(\cos(\Omega)-1)+\alpha^2)}}\tag{1}
  • $$
  • The -3 dB point can also be calculated from \$(1)\$:
  • $$|H(\Omega)|^2=\frac12=\frac{\alpha^2}{2(\alpha-1)(\cos(\Omega)-1)+\alpha^2}\quad\Rightarrow \\
  • 2(\alpha-1)(\cos(\Omega)-1)+\alpha^2=2\alpha^2\quad\Rightarrow \\
  • \cos(\Omega)-1=\frac{\alpha^2}{2(\alpha-1)}\quad\Rightarrow \\
  • \Omega=$$
  • This can be easily tested with any simulator. As an example, for \$\alpha=0.4\$, the attenuation at \$0.37\frac{f_s}{2}\$ and the -3 dB point are:
  • $$
  • |H(0.37\pi)|=\frac{0.4}{\sqrt(2(0.4-1)(\cos(0.37\pi)-1)+0.4^2)}=0.4255746548210215 \\
  • f=\frac{1}{\pi}\arccos\left(\frac{0.4^2}{2(0.4-1)}+1 ight)=0.1662579714811903
  • $$
  • ![test](https://electrical.codidact.com/uploads/KdKz4sE9Raohy2oLM55198F9)
  • (where I used a normalized [0...Nyquist])
  • I'm adding this as a corollary to Olin's post, in case an exact formula for attenuation is needed.
  • That basic IIR is derived from the [exponential moving average](https://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average), and its impulse response is:
  • $$h[n]=\alpha x[n]+(1-\alpha)x[n-1]$$
  • which translates into this transfer function:
  • $$H(z)=\frac{\alpha}{1-(1-\alpha)z^{-1}}$$
  • This can be used to determine analytically the attenuation at a particular frequency, by simply substituting \$z^{-1}=\text{e}^{-j\Omega}\$:
  • \begin{align*}
  • H(j\Omega)=\frac{\alpha}{1-(1-\alpha)\text{e}^{-j\Omega}} \\\ |H(j\Omega)|=\frac{\alpha}{\sqrt{2(\alpha-1)(\cos(\Omega)-1)+\alpha^2)}}\tag{1}
  • \end{align*}
  • The -3 dB point can also be calculated from \$(1)\$:
  • \begin{align*}|H(\Omega)|^2=\frac12=\frac{\alpha^2}{2(\alpha-1)(\cos(\Omega)-1)+\alpha^2}\quad\Rightarrow \\\ 2(\alpha-1)(\cos(\Omega)-1)+\alpha^2=2\alpha^2\quad\Rightarrow \\\ \cos(\Omega)-1=\frac{\alpha^2}{2(\alpha-1)}\quad\Rightarrow \\\ \Omega=\arccos\left(1+\frac{\alpha^2}{2(\alpha-1)}\right)\end{align*}
  • This can be easily tested with any simulator. As an example, for \$\alpha=0.4\$, the attenuation at \$0.37\frac{f_s}{2}\$ and the -3 dB point are:
  • \begin{align*}
  • |H(0.37\pi)|=\frac{0.4}{\sqrt(2(0.4-1)(\cos(0.37\pi)-1)+0.4^2)}=0.4255746548210215 \\\ f=\frac{1}{\pi}\arccos\left(\frac{0.4^2}{2(0.4-1)}+1 ight)=0.1662579714811903
  • \end{align*}
  • ![test](https://electrical.codidact.com/uploads/KdKz4sE9Raohy2oLM55198F9)
  • (where I used a normalized [0...Nyquist])
#1: Initial revision by user avatar a concerned citizen‭ · 2020-10-23T10:20:33Z (about 4 years ago)
I'm adding this as a corollary to Olin's post, in case an exact formula for attenuation is needed.

That basic IIR is derived from the [exponential moving average](https://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average), and its impulse response is:

$$h[n]=\alpha x[n]+(1-\alpha)x[n-1]$$

which translates into this transfer function:

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

This can be used to determine analytically the attenuation at a particular frequency, by simply substituting \$z^{-1}=\text{e}^{-j\Omega}\$:

$$
H(j\Omega)=\frac{\alpha}{1-(1-\alpha)\text{e}^{-j\Omega}} \\
|H(j\Omega)|=\frac{\alpha}{\sqrt{2(\alpha-1)(\cos(\Omega)-1)+\alpha^2)}}\tag{1}
$$

The -3 dB point can also be calculated from \$(1)\$:

$$|H(\Omega)|^2=\frac12=\frac{\alpha^2}{2(\alpha-1)(\cos(\Omega)-1)+\alpha^2}\quad\Rightarrow \\
2(\alpha-1)(\cos(\Omega)-1)+\alpha^2=2\alpha^2\quad\Rightarrow \\
\cos(\Omega)-1=\frac{\alpha^2}{2(\alpha-1)}\quad\Rightarrow \\
\Omega=$$

This can be easily tested with any simulator. As an example, for \$\alpha=0.4\$, the attenuation at \$0.37\frac{f_s}{2}\$ and the -3 dB point are:

$$
|H(0.37\pi)|=\frac{0.4}{\sqrt(2(0.4-1)(\cos(0.37\pi)-1)+0.4^2)}=0.4255746548210215 \\
f=\frac{1}{\pi}\arccos\left(\frac{0.4^2}{2(0.4-1)}+1\right)=0.1662579714811903
$$

![test](https://electrical.codidact.com/uploads/KdKz4sE9Raohy2oLM55198F9)

(where I used a normalized [0...Nyquist])