What Is a Moving Average System?

What Is a Moving Average System?
$\begingroup$

Can someone elaborate on what a moving average system is?

I know that the system is defined as: $$y[n] = \frac{x[n] + x[n-1] + x[n-2]}{3}$$ How would we draw $y[n]$ given that we have a graph with discrete values for $x[n]$? Can someone actually draw a sample discrete time $x[n]$ graph and show how the corresponding $y[n]$ graph is generated?

$\endgroup$
5

3 Answers

$\begingroup$

Let's consider a few terms of the sequence $y$:

$$ y[0] = \frac{x[0]+x[-1]+x[-2]}{3} $$

$$ y[1] = \frac{x[1]+x[0]+x[-1]}{3} $$

$$ y[2] = \frac{x[2]+x[1]+x[0]}{3} $$

Notice how the values of $y$ are always an average of three values. Also, notice how the indices of $x$ "shift" to the right in the expressions, and the next value gets shifted in. This is as if we have a longer sequence, $\{x[-2],x[-1],x[0],x[1],x[2]\}$, and we have a window of three consecutive values of the sequence, and the window shifts over one place to the right for each term in the $y$ sequence. $$\{\color{red}{x[-2],x[-1],x[0]},x[1],x[2]\}$$ $$\{x[-2],\color{red}{x[-1],x[0],x[1]},x[2]\}$$ $$\{x[-2],x[-1],\color{red}{x[0],x[1],x[2]}\}$$

This is sometimes called a sliding-window average as well because of this property.

As for a concrete example, let's consider the sequence $$ x[n] = n^2/10, \;\; n\geq 0 \\ x[n] = 0, \;\; n<0 $$ This is plotted below.

Now, if you do the calculations, you average the first three points, then the second three points, then the third three points, etc. I leave the calculations out, but the result it as follows:

The corresponding numerical values are given in the table below.

n   x       y
-2  0       0
-1  0       0.0333
0   0       0.1667
1   0.1     0.4667
2   0.4     0.9667
3   0.9     1.6667
4   1.6     2.5667
5   2.5     3.6667
6   3.6     4.9667
7   4.9     6.4667
8   6.4     8.1667
9   8.1     10.0667
10  10      12.1667
$\endgroup$
2
$\begingroup$

There is an efficient way to compute these moving averages.

Consider the $k$-long moving average $y(n) =\frac1{k}\sum_{j=0}^{k-1} x(n-j) $. Once you have a particular $y(n)$, then

$\begin{array}\\ y(n+1)-y(n) &=\frac1{k}\sum_{j=0}^{k-1} x(n+1-j)-\frac1{k}\sum_{j=0}^{k-1} x(n-j)\\ &=\frac1{k}\left(\sum_{j=0}^{k-1} x(n+1-j)-\sum_{j=0}^{k-1} x(n-j)\right)\\ &=\frac1{k}\left(\sum_{j=-1}^{k-2} x(n-j)-\sum_{j=0}^{k-1} x(n-j)\right)\\ &=\frac1{k}\left(x(n+1)+\sum_{j=0}^{k-2} x(n-j) -(\sum_{j=0}^{k-2} x(n-j)+x(n-k+1)\right)\\ &=\frac1{k}\left(x(n+1)-x(n-k+1)\right)\\ \end{array} $

$\endgroup$
$\begingroup$

You need to convolve your data $\mathbf{x}$ with the impluse response of the corresponding FIR filter $\mathbf{h}$. You can learn the details from here.

$\endgroup$
5

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Sarah Jenkins
Author

Sarah Jenkins

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.