<< Chapter < Page Chapter >> Page >
This module is part of the collection, A First Course in Electrical and Computer Engineering . The LaTeX source files for this collection were created using an optical character recognition technology, and because of this process there may be more errors than usual. Please contact us if you discover any errors.

Suppose we try to extend our method for computing finite moving averages to infinite moving averages of the form

x n = k = 0 w k u n - k = w 0 u n + w 1 u n - 1 + + w 1000 u n - 1000 +

In general, this moving average would require infinite memory for the weighting coefficients w 0 , w 1 , ... and for the inputs u n , u n - 1 , ... . Furthermore, the hardware for multiplying w k u n - k would have to be infinitely fast to compute the infinite moving average in finite time. All of this is clearly fanciful and implausible (not to mention impossible). But what if the weights take the exponential form

w k = 0 , k < 0 w 0 a k , k 0 ?

Does any simplification result? There is hope because the weighting sequence obeys the recursion

w k = 0 , k < 0 w 0 , k = 0 a w k - 1 k 1 .

This recursion may be rewritten as follows, for k 1 :

w k - a w k - 1 = 0 , k 1 .

Let's now manipulate the infinite moving average and use the recursion for the weights to see what happens. You must follow every step:

x n = k = 0 w k u n - k = k = 1 w k u n - k + w 0 u n = k = 1 a w k - 1 u n - k + w 0 u n = a m = 0 w m u n - 1 - m + w 0 u n = a x n - 1 + w 0 u n .

This result is fundamentally important because it says that the output of the infinite exponential moving average may be computed by scaling the previous output x n - 1 by the constant a , scaling the new input u n by w 0 , and adding. Only three memory locations must be allocated: one for w 0 , one for a , and one for x n - 1 . Only two multiplies must be implemented: one for a x n - 1 and one for w 0 u n . A diagram of the recursion is given in Figure 1 . In this recursion, the old value of the exponential moving average, x n - 1 , is scaled by a and added to w 0 u n to produce the new exponential moving average x n . This new value is stored in memory, where it becomes x n - 1 in the next step of the recursion, and so on.

This diagram is a series of arrows and figures. On the far left there is the expression U_n with an arrow pointing to the right. This arrow ends and above the point of this arrow is the expression W_0. Another arrow proceeds to the right of the previous arrows points. This arrow ends at a circle containing a plus. A line extends to the right of the cirle and above this line is the expression X_n This line ends at a rectangle containg the word memory. Another line extends to the right ending in an arrow point pointing at the expression X_(n-1). Halfway along this last line and another line extends down perpendicularly and then turns at a right angle to the left. This line has an arrow point halfway along its path and about the arrow point is the expression alpha. The line continues after this arrow point and has another right angle so the that the arrow now points up and ends at the circle containing the plus. This diagram is a series of arrows and figures. On the far left there is the expression U_n with an arrow pointing to the right. This arrow ends and above the point of this arrow is the expression W_0. Another arrow proceeds to the right of the previous arrows points. This arrow ends at a circle containing a plus. A line extends to the right of the cirle and above this line is the expression X_n This line ends at a rectangle containg the word memory. Another line extends to the right ending in an arrow point pointing at the expression X_(n-1). Halfway along this last line and another line extends down perpendicularly and then turns at a right angle to the left. This line has an arrow point halfway along its path and about the arrow point is the expression alpha. The line continues after this arrow point and has another right angle so the that the arrow now points up and ends at the circle containing the plus.
Recursive Implementation of an Exponential Moving Average

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, A first course in electrical and computer engineering. OpenStax CNX. Sep 14, 2009 Download for free at http://cnx.org/content/col10685/1.2
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'A first course in electrical and computer engineering' conversation and receive update notifications?

Ask