# What is the effective alpha of 2 cascaded EWMA IIR filters?

Considering simple 1st order exponentially weighed moving average (EWMA) filters of form

$$y[n] = \alpha x[n] + (1-\alpha) y[n-1]$$

what is the effective alpha of 2 cascaded EWMA IIR filters?

Maybe I'm asking the wrong question, but not having a lot of luck Googling for the answer

• This question doesn't really make sense. If you cascade two filters like those you described, then you've effect ivory implemented a second-order IIR filter. Therefore, it doesn't fit the parameterized model that you described anymore. – Jason R Oct 29 '15 at 2:01
• I've seen EWMA filters described as a computationally cheap approximation to a true boxcar moving average FIR filter where the EWMA alpha corresponds to the inverse of the weighting of the boxcar filter i.e. the number of data points the averaging is being performed over. So I guess what I'm trying to ask is when I cascade 2 EWMA filters together, how many data points am I now averaging over? – Richard Lang Oct 29 '15 at 4:33
• The question arises as I'm working with an API that exposes data that has already been "lightly" filtered with an EWMA filter. I'm writing an algorithm that requires a more heavily filtered signal, the filter weighting for which I've already determined empirically with Matlab modelling. I was hoping to achieve the desired filtering by cascading another filter on the data provided by the API, rather than hacking the API about to provide an additional function that returned the raw/unfiltered signal. – Richard Lang Oct 29 '15 at 4:33
• If you're using an exponential moving average, you're technically averaging over its entire history. In practical terms, yes, the impulse response of the filter does decay to a negligible value eventually. But it is not a very good approximation to a true boxcar moving filter. They are both lowpass filters, but their frequency responses are quite different. When you cascade two exponential moving averages, you don't really increase its memory at all, unlike using a longer boxcar filter. The cutoff frequency won't change, it will just fall off more sharply. – Jason R Oct 29 '15 at 13:56

It is important to define in what sense two cascaded EWMA filters should be "equivalent" to a single EWMA filter. One possibility would be to define an "effective memory" or "effective averaging window size" and say that the two filters are equivalent if they have that same effective memory.

The second question to be answered is how to define the effective memory length of such a filter. Again we have to make a reasonable choice, and one possibility is to look at the filter's impulse response $h[n]$ and choose the length $N$ such that the sum over the first $N$ coefficients equals a certain percentage of the sum over all coefficients:

$$\frac{\sum_{n=0}^{N-1}h[n]}{\sum_{n=0}^{\infty}h[n]}=r,\quad 0\ll r<1\tag{1}$$

That is, we consider the coefficients with indices greater than $N$ negligible. The impulse response coefficients $h[n]$ are the weights to compute the output signal from the input signal:

$$y[n]=\sum_{k=0}^{\infty}h[k]x[n-k]\tag{2}$$

For the filter given in your question it can be shown that the impulse response is given by

$$h[n]=\alpha(1-\alpha)^n,\quad n\ge 0\tag{3}$$

Furthermore,

$$\sum_{n=0}^{\infty}h[n]=1\tag{4}$$

and

$$\sum_{n=0}^{N-1}h[n]=1-(1-\alpha)^N\tag{5}$$

With $(4)$ and $(5)$, Eq. $(1)$ reduces to

$$1-(1-\alpha)^N=r\tag{6}$$

which, for a given percentage $r$, can be solved for either $\alpha$ or $N$:

\begin{align}\alpha&=1-(1-r)^{1/N}\\ N&=\frac{\log(1-r)}{\log(1-\alpha)}\end{align}\tag{7}

So, e.g., with $r=0.9$ and $\alpha=0.1$, the effective averaging length is $N\approx 22$. Alternatively, for a desired length $N=100$, $\alpha$ must be chosen as $\alpha=0.023$.

The same calculations can be done for the cascade of two such filters, the only problem being that it is not possible to give analytical expressions analogous to Eq. $(7)$. However, the finite sum given in $(5)$ can be easily computed using the filter itself. If you cascade two EWMA filters and use a constant input $x[n]=1$, $n\ge 0$, the output will be the sum $(5)$. The first output sample is the sum for $N=1$, the next one for $N=2$, etc. So by this computation one can figure out the value of $N$ for a given percentage $r$. This value is given by the number of output samples necessary for the output to exceed the given value $r$.

It's time for an example. Let's again choose $r=0.9$, i.e. the effective memory size is define by the number of coefficients which add up to $90\%$ of the total sum of all coefficients. Let the two $\alpha$-values of the cascaded filters be $\alpha_1=0.1$ and $\alpha_2=0.2$. To find out its effective averaging length (at least according to our definition), we feed the filter with a constant input $x[n]=1$ until the output exceeds the value of $r=0.9$. The output is shown in the figure below. The output values are blue, and $r$ is shown by the red line.

The effective averaging length $N$ turns out to be $N=27$. In order to find out which first order averaging filter has the same effective length, we need to compute $\alpha$ from Eq. $(7)$ for $N=27$ and $r=0.9$, which gives $\alpha=0.082$. Hence, in the above defined sense, we can say that two cascaded EWMA filters with $\alpha_1=0.1$ and $\alpha_2=0.2$ are equivalent to a single EWMA filter with $\alpha=0.082$.

Building on @Matt L. 's answer, here's a rule of thumb:

# cascading two IIR (EWMA) filters with halflives ha hb
# --> an IIR with halflife about 1.1 * (ha + hb)
-------------------------------------------
# ha hb   α = .7/h   hboth      approx   dB
-------------------------------------------
7  7  α 0.1  0.1 :  hboth  15  ~  15   [  0 -28 -39 -45 -49 -51 -51]
7 14  α 0.1  0.05:  hboth  23  ~  23   [  0 -34 -45 -51 -55 -57 -57]
7 35  α 0.1  0.02:  hboth  44  ~  46   [  0 -42 -53 -59 -63 -65 -65]
7 70  α 0.1  0.01:  hboth  78  ~  85   [  0 -48 -60 -66 -69 -71 -72]
14 14  α 0.05 0.05:  hboth  32  ~  31   [  0 -40 -52 -58 -61 -63 -64]
14 35  α 0.05 0.02:  hboth  54  ~  54   [  0 -48 -60 -66 -69 -71 -72]
14 70  α 0.05 0.01:  hboth  89  ~  92   [  0 -54 -66 -72 -75 -77 -78]
35 35  α 0.02 0.02:  hboth  82  ~  77   [  0 -56 -68 -74 -77 -79 -80]
35 70  α 0.02 0.01:  hboth 121  ~ 116   [  0 -62 -74 -80 -83 -85 -86]
70 70  α 0.01 0.01:  hboth 166  ~ 154   [  0 -68 -80 -86 -89 -91 -92]


I like to use halflife, the 50 % step response time, to describe 1-pole filters:
$\quad\quad$ halflife $\equiv {0.7 \over \alpha} \ \approx {{ln\, 2} \over {ln\, (1 - \alpha})}$

This is fairly intuitive — a longer halflife uses more of the past, is "stiffer". Also, a 1-pole IIR with halflife $h$ is not far from a straight average of about the last $2 h$ data points:
first-order-iir-approximation-to-a-moving-average-filter .