# Generalizing exponential moving average to n samples

Assume that we have a moving average like this:

$E_t = a*S_{t-1}+(1-a)*E_{t-1}$

where $E$ would be an estimate we are interested in, and $S$ is a sample we take at each point in time.

Now, if we knew say three samples (e.g. at $t = 0,1,2$ and currently $t = 3$), we could get the current $E$ by calculating $E$ at each point in time and plugging that into the next one, like this:

$E_1 = a*S_0 + (1-a)*E_0$

$E_2 = a*S_1 + (1-a)*E_1$

$E_3 = a*S_2 + (1-a)*E_2$

Now, I would like to understand, how would I generalize this to $n$ samples? So that we would not need to do everything step by step like that.

$$E_n = (1-a)^n E_0 +a \sum_{i=1}^n (1-a)^{n-i}S_i$$