# Filter: IIR Filter

How IIR Filter coefficients formula derived? for LPF, HPF, BPF, BSF there are coefficients formula for a0, a1, a2, b0, b1.

How it came? I would like to know the derivation for all those coeffs w.r.t LPF, HPF, BPF, BSF.

For ex, $$b_0 = \frac12(1 - \cos(\omega_0))$$ for LPF how it came?

Is it possible to get those details?

There are many ways to arrive at filter coefficients, depending on your specs. But from your question I assume that you're talking about basic second-order building blocks (biquads). Also here there are several possibilities, but one standard approach - and that's probably the one you're after - is to start with the second-order transfer function of an analog filter (low pass, high pass, etc.), and then use the bilinear transform to transform the filter to a corresponding discrete-time filter.

For a low pass filter, the steps are

1. start with the transfer function of a normalized second-order continuous-time low pass filter: $$H(s)=\frac{1}{s^2+\sqrt{2}s+1}\tag{1}$$
2. use the bilinear transform $$s=k\frac{z-1}{z+1}\tag{2}$$ to obtain the discrete-time transfer function

\begin{align}H_d(z)&=H\left(k\frac{z-1}{z+1}\right)\\&=\frac{1}{k^2\left(\frac{z-1}{z+1}\right)^2+\sqrt{2}k\frac{z-1}{z+1}+1}\\&=\frac{z^2+2z+1}{(k^2+\sqrt{2}k+1)z^2+2(1-k^2)z+k^2-\sqrt{2}+1}\\&=\frac{1}{k^2+\sqrt{2}k+1}\cdot\frac{z^2+2z+1}{z^2+\frac{2(1-k^2)}{k^2+\sqrt{2}k+1}+\frac{k^2-\sqrt{2}k+1}{k^2+\sqrt{2}k+1}}\tag{3}\end{align}

1. choose the constant $$k$$ depending on the desired cut-off frequency of the discrete-time filter. If $$\omega_0$$ is the desired normalized $$3$$ dB cut-off frequency of the discrete-time filter, i.e., $$\omega_0=2\pi f_0/f_s$$ where $$f_s$$ is the sampling frequency, then $$k$$ must be chosen as $$k=\frac{1}{\tan(\omega_0/2)}\tag{4}$$

Eqs $$(3)$$ and $$(4)$$ completely specify the desired discrete-time filter.

Note that the coefficients in Eq. $$(3)$$ can also be written in terms of $$\sin(\omega_0)$$ and $$\cos(\omega_0)$$. This is the form that you find for instance in Robert Bristow-Johnson's audio EQ-cookbook. In order to rewrite $$(3)$$ in that form, note that $$k$$ can be written as

$$k=\frac{1+\cos(\omega_0)}{\sin(\omega_0)}\tag{5}$$

and $$k^2$$ can be written as

$$k^2=\frac{1+\cos(\omega_0)}{1-\cos(\omega_0)}\tag{6}$$

Plugging $$(5)$$ and $$(6)$$ into $$(3)$$ and using a bit of algebra will give you the transfer function of a discrete-time low pass biquad with normalized cut-off frequency $$\omega_0$$ in the following form:

$$H_d(z)=g\frac{z^2+2z+1}{z^2+a_1z+a_2}$$

with

\begin{align}g&=\frac12\frac{1-\cos(\omega_0)}{1+\sin(\omega_0)/\sqrt{2}}\\a_1&=-\frac{2\cos(\omega_0)}{1+\sin(\omega_0)/\sqrt{2}}\\a_2&=\frac{1-\sin(\omega_0)/\sqrt{2}}{1+\sin(\omega_0)/\sqrt{2}}\end{align}

These formulae and the ones for biquads with other characteristics (high pass, band pass, etc.) can be found in Robert Bristow-Johnson's audio EQ-cookbook. The derivations for the other filter types are very similar to the one for the low pass filter shown here.

• That should be "robert bristow-johnson" :-) But I'll let it pass. – Peter K. Apr 13 '20 at 14:21
• @PeterK.: Oh yeah, for some reason I can never remember his name :) – Matt L. Apr 13 '20 at 14:24
• @ksi: That's exactly what I tried to explain in my answer. You'll have to sit down yourself and use the formulae I've shown you. Have you actually tried replacing $s$ in $H(s)$ by $k(z-1)/(z+1)$? Once you've done that you just need to replace the constant $k$ (and $k^2$) by the expressions given in my answer, and you'll arrive at exactly the same formulae for the filter coefficients as I did. If you really arrive at a different result, please add the steps to your question and we can try to figure out where you went wrong. – Matt L. Apr 13 '20 at 15:22
• @ksi: I've added a few steps to get you started. – Matt L. Apr 13 '20 at 16:22
• @ksi: Mind the normalization. The $a_1$ given at the end of my answer is not equal to $2(1-k^2)$ but it is $2(1-k^2)/(k^2+\sqrt{2}k+1)$. Check again Eq. $(3)$, where I've added another step (to normalize $a_0$ to $1$). – Matt L. Apr 14 '20 at 11:36