# Comparison of Analog IIR Lowpass Filters

Design a fifth-order analog Butterworth lowpass filter with a cutoff frequency of 2 GHz. Multiply by $2\pi$ to convert the frequency to radians per second. Compute the frequency response of the filter at 4096 points.

```n = 5; wc = 2*pi*2e9; w = 2*pi*1e9*logspace(-2,1,4096)'; [zb,pb,kb] = butter(n,wc,"s"); [bb,ab] = zp2tf(zb,pb,kb); [hb,wb] = freqs(bb,ab,w); gdb = -diff(unwrap(angle(hb)))./diff(wb);```

Design a fifth-order Chebyshev Type I filter with the same edge frequency and 3 dB of passband ripple. Compute its frequency response.

```[z1,p1,k1] = cheby1(n,3,wc,"s"); [b1,a1] = zp2tf(z1,p1,k1); [h1,w1] = freqs(b1,a1,w); gd1 = -diff(unwrap(angle(h1)))./diff(w1);```

Design a fifth-order Chebyshev Type II filter with the same edge frequency and 30 dB of stopband attenuation. Compute its frequency response.

```[z2,p2,k2] = cheby2(n,30,wc,"s"); [b2,a2] = zp2tf(z2,p2,k2); [h2,w2] = freqs(b2,a2,w); gd2 = -diff(unwrap(angle(h2)))./diff(w2);```

Design a fifth-order elliptic filter with the same edge frequency, 3 dB of passband ripple, and 30 dB of stopband attenuation. Compute its frequency response.

```[ze,pe,ke] = ellip(n,3,30,wc,"s"); [be,ae] = zp2tf(ze,pe,ke); [he,we] = freqs(be,ae,w); gde = -diff(unwrap(angle(he)))./diff(we);```

Design a fifth-order Bessel filter with the same edge frequency. Compute its frequency response.

```[zf,pf,kf] = besself(n,wc); [bf,af] = zp2tf(zf,pf,kf); [hf,wf] = freqs(bf,af,w); gdf = -diff(unwrap(angle(hf)))./diff(wf);```

Plot the attenuation in decibels. Express the frequency in gigahertz. Compare the filters.

```fGHz = [wb w1 w2 we wf]/(2e9*pi); plot(fGHz,mag2db(abs([hb h1 h2 he hf]))) axis([0 5 -45 5]) grid on xlabel("Frequency (GHz)") ylabel("Attenuation (dB)") legend(["butter" "cheby1" "cheby2" "ellip" "besself"])```

Plot the group delay in samples. Express the frequency in gigahertz and the group delay in nanoseconds. Compare the filters.

```gdns = [gdb gd1 gd2 gde gdf]*1e9; gdns(gdns<0) = NaN; loglog(fGHz(2:end,:),gdns) grid on xlabel("Frequency (GHz)") ylabel("Group delay (ns)") legend(["butter" "cheby1" "cheby2" "ellip" "besself"])```

The Butterworth and Chebyshev Type II filters have flat passbands and wide transition bands. The Chebyshev Type I and elliptic filters roll off faster but have passband ripple. The frequency input to the Chebyshev Type II design function sets the beginning of the stopband rather than the end of the passband. The Bessel filter has approximately constant group delay along the passband.