# What is a moving average system?

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?

-
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? – J. M. Sep 23 '11 at 1:22
this is for a discrete time signal.... I am sure this is correct... – rrazd Sep 23 '11 at 1:23
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. – J. M. Sep 23 '11 at 1:31
@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 window – oldrinb Sep 9 at 20:02
@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. – J. M. Oct 6 at 12:53

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

-

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.

-
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. – Arkamis Jan 9 at 19:55
@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. – Seyhmus Güngören Jan 10 at 1:26
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. – Alonso Delfín Jun 29 at 21:25
@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. – Seyhmus Güngören Jun 29 at 21:55
The review was divided. It's more than a link-only answer, but it could profit from being expanded. – Daniel Fischer Jun 29 at 22:12