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

Comments on Moving average that uses less memory?

Parent

Moving average that uses less memory?

+3
−0

My control system gets a signal representing the plant output, but that signal has a lot of noise on it. The control system goes nuts trying to react to the noise. I need to filter out the noise somehow, but preserve the basic plant response. I heard about a moving average and tried it. It helps, but uses up a lot of memory in my small microcontroller. It also introduces some lag.

Is there a way to get rid of the noise, use less memory, and maybe have less lag too?

History
Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

0 comment threads

Post
+2
−0

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]=\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\right)=0.1662579714811903 \end{align*}

test

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

History
Why does this post require moderator attention?
You might want to add some details to your flag.

1 comment thread

General comments (4 comments)
General comments
a concerned citizen‭ wrote over 3 years ago

The MathJax seems off? \\ doesn't work, and nither does \begin{align} ... end{align}. Are there differences between this and the syntax used in ee.se?

coquelicot‭ wrote over 3 years ago

@concerned citizen. I like your answers. They provide the theoretical part that is hardly given in other answers.

Mithrandir24601‭ wrote over 3 years ago · edited over 3 years ago

Yeah, mathjax is being a bit weird - it works by using \begin{align} ... \end{align}, with \\\ Instead of \\ and no line breaks/new lines in the text editor itself

a concerned citizen‭ wrote over 3 years ago

@coquelicot I know that the practical part is what matters here, but the theoretical part might still help along the way.