# Single-pole IIR low-pass filter - which is the correct formula for the decay coefficient?

A single-pole IIR low-pass filter can be defined in discrete time as y += a * (x - y), where y is the output sample, x is the input sample and a is the decay coefficient.

However, the definition of a varies. On Wikipedia, it's defined as 2πfc/(2πfc+1) (where fc is the cutoff frequency).

But here, a is defined as follows: 1 - e^-2πfc.

Their graphs look similar, but which one is more accurate?

The blue graph is the Wikipedia formula, the green is the second one, fc is the x-axis. • Possible duplicate of Exponential weighted moving average time constant Dec 12 '18 at 9:04
• I disagree. There are two conflicting formulas given, but the question you linked covers how one of them can be derived. Edit: However, there's a note that the formulas are only an approximation, which might imply that both of those are usable.
– Mark
Dec 12 '18 at 9:07
• See my answer below, both are indeed approximations derived from the corresponding analog filter, and only one of them is useful, provided that the cut-off frequency is much smaller than Nyquist. Dec 12 '18 at 12:17

The given single-pole IIR filter is also called exponentially weighted moving average (EWMA) filter, and it is defined by the following difference equation:

$$y[n]=\alpha x[n]+(1-\alpha)y[n-1],\qquad 0<\alpha<1\tag{1}$$

Its transfer function is

$$H(z)=\frac{\alpha}{1-(1-\alpha)z^{-1}}\tag{2}$$

The exact formula for the required value of $$\alpha$$ that results in a desired $$3\;\textrm{dB}$$ cut-off frequency $$\omega_c$$ was derived in this answer:

$$\alpha=-y+\sqrt{y^2+2y},\qquad y=1-\cos(\omega_c)\tag{3}$$

Even though it should be easy enough to compute $$\alpha$$ from $$(3)$$, there are several approximative formulas floating around the internet. One of them is

$$\alpha\approx 1-e^{-\omega_c}\tag{4}$$

In this answer I've explained how this formula is derived (namely, via the impulse invariant transformation of the corresponding continuous-time low pass filter). This answer compares the approximation $$(4)$$ with the exact formula, and it is shown that $$(4)$$ is only useful for relatively small cut-off frequencies (of course, small compared to the sampling frequency).

In the wikipedia link given in the question, there is yet another approximative formula:

$$\alpha\approx\frac{\omega_c}{1+\omega_c}\tag{5}$$

[Note that in all formulas of this answer $$\omega_c$$ is normalized by the sampling frequency.] This approximation is also derived from discretizing the corresponding analog transfer function, this time not via the impulse invariant method, but by replacing the derivative by a backward difference:

$$\frac{dy(t)}{dt}{\huge |}_{t=nT}\approx\frac{y(nT)-y((n-1)T)}{T}\tag{6}$$

This is equivalent to replacing $$s$$ by $$(1-z^{-1})/T$$ in the continuous-time transfer function

$$H(s)=\frac{1}{1+s\tau}\tag{7}$$

which results in

$$H(z)=\frac{1}{1+(1-z^{-1})\tau/T}=\frac{\frac{1}{1+\tau/T}}{1-\frac{\tau/T}{1+\tau/T}z^{-1}}\tag{8}$$

Comparing $$(8)$$ to $$(2)$$ we see that

$$\alpha=\frac{1}{1+\tau/T}\tag{9}$$

Since the (continuous-time) $$3\;\textrm{dB}$$ cut-off frequency is $$\Omega_c=1/\tau$$, we obtain from $$(9)$$

$$\alpha=\frac{\Omega_cT}{1+\Omega_cT}\tag{10}$$

Equating the discrete-time cut-off frequency $$\omega_c$$ with $$\Omega_cT$$ in $$(10)$$ gives the approximation $$(5)$$.

The figure below shows the actually achieved cut-off frequency for a given desired cut-off frequency for the two approximations $$(4)$$ and $$(5)$$. Clearly, both approximations become useless for larger cut-off frequencies, and I would suggest that approximation $$(5)$$ is generally useless. • How about this approximation (sorry, just in coefficient format ): x = 1.0/(fs*T); % fs in Hz, T in μs a0 = 1.0; a1 = -(1 + x + 0.5 * x^2); % Taylor approx b0 = a0 + a1; % gain b1 = 0.0; Mar 26 '19 at 21:18
• @MattL. Do you know the source of these approximations which are "floating around the internet"? Is there a paper or textbook which covers these? I imagine they may be useful because they may be simpler to implement in hardware? Jul 14 '20 at 4:21
• @Ralph: I don't know the original source of those approximations. I also don't think that they are very useful. Eq. (4) is not very easy to implement, and Eq. (5) is such a bad approximation that it is useless in most situations. Jul 17 '20 at 21:52
• it's not that the alpha-from-tau formula is an approximation, it's that the relationship between $\tau$ and $w_c$ is an approximation. If we define the time constant $\tau$ as the time it takes for the filter's step function to converge to within $\frac 1 e$, then the given formula $\alpha = 1 - e^{-\frac 1 \tau}$ is exact. This is often a useful definition of $\tau$ in a moving-average context, where you're more concerned with convergence time than frequency response. Oct 1 '20 at 14:51
• In your final cutoff graph, does 1 correspond to 2pi (normalized frequency) or pi (Nyquist)? Mar 18 at 0:51

Matt L.’s exact answer in equation (3) is correct. But here is a simpler “exact” solution:

𝛼 = 2𝑦 / ( 𝑦 + 1 ), 𝑦 = tan( 𝜔𝑐 / 2 ) (11)

This is computationally more robust. Eq (3) could lead to small errors depending on the resolution of your floating-point math.