0
$\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?

  • 0
    Huh, wait. The form I'm accustomed to goes like $\dfrac{x_{n-1}+x_n+x_{n+1}}{3}$. The form you gave is the one usually used for endpoints... could you check your source again?2011-09-23
  • 0
    this is for a discrete time signal.... I am sure this is correct...2011-09-23
  • 2
    Anyway... you're already aware of the "sliding window" analogy, right? Say you have the sequence $(x_1,x_2,x_3,x_4,x_5,x_6,x_7)$. The first pass replaces $x_3$ with the mean of $x_1,x_2,x_3$. Then, you shift by one place, replacing $x_4$ with the mean of $x_2,x_3,x_4$, and so on, up until you're replacing $x_7$ with the mean of $x_5,x_6,x_7$. Note that the group of points being taken always has overlap with the previous one.2011-09-23
  • 0
    @Guesswhoitis. the OP is a causal filter, yours is not. the way to see how this works is to consider a sliding window of 3 samples and at each point, the output $y[n]$ is the mean of the previous 3 input samples $x[n],x[n-1],x[n-2]$ in the window2015-09-09
  • 0
    @oldrinb, that's why I provided the second comment; I know that there are a number of moving averages; I just mentioned the one I'm used to.2015-10-06

3 Answers 3

2

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. x[n]

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: enter image description here

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
0

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} $

-1

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.

  • 2
    This answer would be better if the relevant source material were summarized, rather than using a non-permanent link to the top level of a 1700-word Wiki page. Alternatively, this is well-suited as a comment.2015-01-09
  • 1
    @Arkamis I would write definitely more if the question would not be asked 3 years ago. I can write alot and it is a loss of time if the OP is already away. It is therefore better to spend less time at the beginning and if the OP is still alive then he/she will definitely contact you for details.2015-01-10
  • 0
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes.2015-06-29
  • 1
    @AlonsoDelfín yes more explanation can be given if the OP has interest in it.. No interest basically no answer but still I gave an answer.. Next step will be to delete it, if more requests will arise.2015-06-29
  • 1
    The review was divided. It's more than a link-only answer, but it could profit from being expanded.2015-06-29