EXP8: IIR FILTER DESIGN
AIM: Design following IIR Digital Filters using i) Butterworth and ii) Chebyshev designs:
(a) LPF (b) HPF (c) BPF (d) BSF
1. Butterworth
a. LPF
PROGRAM:
clc;
clear all;
rp=input('enter passband ripple');
rs=input('enter stopband ripple');
wp=input('enter passband frequency');
ws=input('enter stopband frequency');
fs=input('enter sampling frequency');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs);
[b,a]=butter(n,wn);
w=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);
ylabel('gainin db');grid;
xlabel('normalised frequency');
subplot(2,1,2);
plot(om/pi,an);
ylabel('phase in radians');grid;
xlabel('normalisedfrequency');
b.HPF
PROGRAM:
clc;
clear all;
rp=input('enter passband ripple');
rs=input('enter stopband ripple');
wp=input('enter passband frequency');
ws=input('enter stopband frequency');
fs=input('enter sampling frequency');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs);
[b,a]=butter(n,wn,'high');
w=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);
ylabel('gain in db');grid;
xlabel('normalised frequency');
subplot(2,1,2);
plot(om/pi,an);
ylabel('phase in radians');grid;
xlabel('normalisedfrequency');
c.BPF
PROGRAM:
clc;
close all;
clear all;
alphap=2;
alphas=20;
ws=[0.1,0.5];
wp=[0.2,0.4];
[n,wn]=buttord(wp,ws,alphap,alphas);
[b,a]=butter(n,wn);
w=0:0.01:pi;
[h,ph]=freqz(b,a,w);
m=20*log(abs(h));
an=angle(h);
subplot(2,1,1);plot(ph/pi,m);grid;
ylabel('Gain in dB');xlabel('normalised frequency')
title('Magnitude response of Butterworth Band Pass Filter');
subplot(2,1,2);plot(ph/pi,an);grid;
ylabel('Phase in radians');xlabel('normalised frequency')
title('Phase response of Butterworth Band Pass Filter');
d. BSF
PROGRAM:
clc;
close all;
clear all;
alphap=2;
alphas=20;
ws=[0.2,0.4];
wp=[0.1,0.5];
[n,wn]=buttord(wp,ws,alphap,alphas);
[b,a]=butter(n,wn,'stop');
w=0:0.01:pi;
[h,ph]=freqz(b,a,w);
m=20*log(abs(h));
an=angle(h);
subplot(2,1,1);plot(ph/pi,m);grid;
ylabel('Gain in dB');xlabel('normalised frequency')
title('Magnitude response of Butterworth Band Reject Filter');
subplot(2,1,2);plot(ph/pi,an);grid;
ylabel('Phase in radians');xlabel('normalised frequency')
title('Phase response of Butterworth Band Reject Filter');
TO DESIGN A CHEBYSHEV-1 LOW PASS FILTER:-
PROGRAM:-
clc;
close all;
clear all;
alphap=1;
alphas=15;
wp=0.2;
ws=0.3;
[n,wn]=cheb1ord(wp,ws,alphap,alphas);
[b,a]=cheby1(n,alphap,wn);
w=0:0.01:pi;
[h,ph]=freqz(b,a,w);
m=20*log(abs(h));
an=angle(h);
subplot(2,1,1);plot(ph/pi,m);grid;
ylabel('Gain in dB');xlabel('normalised frequency')
title('Magnitude response of IIR Chebshev-1 Low Pass Filter');
subplot(2,1,2);plot(ph/pi,an);grid;
ylabel('Phase in radians');xlabel('normalised frequency')
title('Phase response of Chebyshev-1 Low Pass Filter');
TO DESIGN A CHEBYSHEV TYPE 1 HIGH PASS FILTER:-
clc;
clear all;
close all;
alphap=0.4;
alphas=30;
wp=0.4;
ws=0.8;
[n,wn]=cheb1ord(wp,ws,alphap,alphas);
[b,a]=cheby1(n,alphap,wn,'high');
w=0:0.01:pi;
[h,ph]=freqz(b,a,w);
m=20*log(abs(h));
an=angle(h);
subplot(2,1,1);
plot(ph/pi,m);grid
ylabel('Gain in dB');xlabel('normalised frequency')
title('Magnitude response of CHEBYSHEV I High Pass Filter ');
subplot(2,1,2);
plot(ph/pi,an);grid
ylabel('Phase in radians');xlabel('normalised frequency')
title('Phase response of CHEBYSHEV I High Pass Filter');
TO DESIGN A CHEBYSHEV-1 BAND PASS FILTER: -
PROGRAM:-
clc;
close all;
clear all;
alphap=2;
alphas=20;
ws=[0.1,0.5];
wp=[0.2,0.4];
[n,wn]=cheb1ord(wp,ws,alphap,alphas);
[b,a]=cheby1(n,alphap,wn);
w=0:0.01:pi;
[h,ph]=freqz(b,a,w);
m=20*log(abs(h));
an=angle(h);
subplot(2,1,1);plot(ph/pi,m);grid;
ylabel('Gain in dB');xlabel('normalised frequency')
title('Magnitude response of Chebyshev-1 Band Pass Filter');
subplot(2,1,2);plot(ph/pi,an);grid;
ylabel('Phase in radians');xlabel('normalised frequency')
title('Phase response of Chebyshev-1 Band Pass Filter');
TO DESIGN A CHEBYSHEV-2 BAND REJECT FILTER:-
PROGRAM:-
clc;
close all;
clear all;
alphap=2;
alphas=20;
ws=[0.2,0.4];
wp=[0.1,0.5];
[n,wn]=cheb2ord(wp,ws,alphap,alphas);
[b,a]=cheby2(n,alphas,wn,'stop');
w=0:0.01:pi;
[h,ph]=freqz(b,a,w);
m=20*log(abs(h));
an=angle(h);
subplot(2,1,1);plot(ph/pi,m);grid;
ylabel('Gain in dB');xlabel('normalised frequency')
title('Magnitude response of Chebyshev-2 Band Reject Filter');
subplot(2,1,2);plot(ph/pi,an);grid;
ylabel('Phase in radians');xlabel('normalised frequency')
title('Phase response of Chebyshev-2 Band Reject Filter');