delta1 = 0.01;
delta2 = 0.005;
Rp = -20*log10(1-delta1);
Rs = -20*log10(delta2);
Omegap = 0.2*pi;
Omegas = 0.3*pi;
[N,Omegan] = buttord(Omegap/pi,Omegas/pi,Rp,Rs);
[b,a] = butter(3,Omegan);
[H,Omega] = freqz(b,a,2048);
figure(1)
subplot(2,1,1)
plot(Omega/pi,abs(H));
xlabel('Frequency(\Omega/\pi)'), ylabel('|H(e^{j\Omega})|')
ylim([0 1])
xlim([0 1])
subplot(2,1,2)
plot(Omega/pi,20*log(abs(H)));
xlabel('Frequency(\Omega/\pi)'), ylabel('|H(e^{j\Omega})| (dB)')
ylim([-80 5])
xlim([0 1])
figure(2)
subplot(2,1,1)
plot(Omega/pi,abs(H));
xlabel('Frequency(\Omega/\pi)'), ylabel('|H(e^{j\Omega})|')
title('Class example: Butterworth IIR filter passband')
xlim([0 Omegap/pi])
ylim([1-delta1 1+delta1])
subplot(2,1,2)
plot(Omega/pi, abs(H));
xlabel('Frequency(\Omega/\pi)'), ylabel('|H(e^{j\Omega})| (dB)')
title('Class example: Butterworth IIR filter stopband')
xlim([Omegas/pi 1])
ylim([0 delta2])
figure(3)
pzplot(b,a)
axis square
xlabel('Real'); ylabel('Imag');
title('Poles and Zeros of Butterworth IIR filter')