With weight vector I mean the vector with weights that you have to multiply the observations in the window that slides over your data with so if you add those products together it returns the value of the EMA on the right side of the window.

For a linear weighted moving average the formula for finding the weight vector is: (1:n)/sum(1:n) (in R code). This series of length n adds up to 1. For n=10 it will be


the numbers 1 to 10 / 55, with 55 the sum of the numbers 1 to 10.

How do you calculate the weight vector for an exponential moving average (EMA) of length n?

Wikipedia tells me:

if n is the length of the window, then alpha<-2/(n+1) and i<-1:n so EmaWeightVector<-((alpha*(1-alpha)^(1-i)))

Is this correct?

Even though the EMA is not really confined to a window with a start and an end, shouldn't the weights add up to 1 just like with the LWMA?

  • 2
    $\begingroup$ An exponential moving average is a single-pole IIR filter. That is, its impulse response is infinitely long, so there is no finite-length weight vector that will exactly match. However, you can approximate the EMA filter to any desired precision by approximating it with a long-enough FIR filter (i.e. the weight vector that you're talking about). $\endgroup$ – Jason R Dec 18 '12 at 21:16
  • $\begingroup$ Thanks Jason, any pointers of how to approximate the EMA filter to any desired precision by approximating it with a long-enough FIR filter? There's a perl script on en.wikipedia.org/wiki/… that made the image of the EMA weight vector, but I don't understand it: if they set the number of weights to 15 why are there 20 red bars instead of 15? $\endgroup$ – MisterH Dec 19 '12 at 22:40
  • $\begingroup$ There are many moving average algorithms. THe time weighting response correlates directly to the desired bandwidth or frequency response of the skirts or neighbouring trends. Cauchy, Gaussian, Hamming, Hanning, Welsh, Blackmann and Blackmann-Harris are a few different distribution functions that come to mind each with different curves designed for special functions. and yes the peak can be normalized to 1 but may not be by default since it is the intergral or area under the curve that is constant $\endgroup$ – Tony Stewart Sunnyskyguy EE75 Dec 20 '12 at 8:02
  • $\begingroup$ They give a perl script to describe how they made the image on en.wikipedia.org/wiki/…, but my problem is that if I translate it to R, the weights add up to 5,.. while they should approximately add up to 1. Could someone translate this into R please? $\endgroup$ – MisterH Dec 22 '12 at 22:54

ok the solution was: (in R)


Here the weights do add up to 1.


This will get you close to a closed form solution...

The weight at each vector is: $$\frac{(1-L)L^t}{1-L^T}$$


  • $L$ is your smoothing constant; $(1-L)$ is often referred to as alpha
  • $t$ is your time vector
  • $T$ your last $t+1$

This doesn't exist anywhere else on the internet, so I had to invent it. It may therefore result in slightly different weights, but it works.

  • $\begingroup$ Hey, welcome to DSP and thank you for contributing. I don't really understand this area perfectly, so I can not upvote your answer since I can't judge its quality. I improved your formatting a bit though, and if you could look at the formatting guide for your next answer, that would be great and would make your answers even better. $\endgroup$ – penelope Jan 29 '14 at 20:30

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.