LAB ASSIGNMENT 10
A RAVI TEJA
22EC01045
Course title
DIGITAL SIGNAL PROCESSING
LAB
LAB ASSIGNMENT 10
1. a) Implement the equation of Analog Butterworth Low Pass Filter Approximation and
observe the effect of order N on the magnitude response.
b) Plot the poles of the filter for different values of order N.
c) Plot the curves for the Bilinear Transformation and it's inverse so as to compensate the
frequency warping effect.
Code:
%Question 1a
syms N;
w=0:0.01:pi;
wc=pi/2;
H=1./(sqrt(1+power(w/wc,2*N))); %Butterworth filter
H1=subs(H,1);
H2=subs(H,2);
H3=subs(H,3);
H4=subs(H,4);
plot(w,abs(H1))
hold on
plot(w,abs(H2))
hold on
plot(w,abs(H3))
hold on
plot(w,abs(H4))
title("Butterworth filter LPF approximation")
xlabel("w")
legend("N=1","N=2","N=3","N=4")
hold off
%1b
[n1,d1]=butter(1,pi/4,"low");
[n2,d2]=butter(2,pi/4,"low");
[n3,d3]=butter(3,pi/4,"low");
[n4,d4]=butter(4,pi/4,"low");
[z1,p1]=tf2zp(n1,d1);
[z2,p2]=tf2zp(n2,d2);
[z3,p3]=tf2zp(n3,d3);
[z4,p4]=tf2zp(n4,d4);
figure
zplane(z1,p1)
title("N=1")
figure
zplane(z2,p2)
title("N=2")
figure
zplane(z3,p3)
title("N=3")
figure
zplane(z4,p4)
title("N=4")
%1c
W=-pi:0.01:pi;
T=0.5;
%Bilinear transformation
DSP LAB ASSIGNMENT 10 PAGE 2
z=(1+exp(-1j*W*T/2))./(1-exp(-1j*W*T/2));
figure
plot(W/pi,abs(z))
title("Magnitude response of bilinear transformation")
xlabel("Normalized frequency")
ylabel("|H(z)|")
%Inverse bilinear transformation
figure
s=(2/T).*(1-z)./(1+z);
plot(W/pi,abs(s))
title("Magnitude response of inverse bilinear transformation")
xlabel("Normalized frequency")
ylabel("|H(s)|")
Output:
1a.
1b.
DSP LAB ASSIGNMENT 10 PAGE 3
1c.
2. a) Design and realize the IIR LP filter with the specifications as discussed in the class.
b) Generate two sinusoids one within passband and other out of passband, add them and pass
through the filter as designed in part a). Plot the input and output signals and verify whether the
desired specifications are satisfied or not.
Code:
%2a
fs=20000;
fpass=1000;
fstop=5000;
rp=1;
rs=40;
wp=2*pi*fpass/fs;
ws=2*pi*fstop/fs;
%Normalizing frequency
wpn=wp/10;
wsn=ws/10;
[n,wn]=buttord(wpn,wsn,rp,rs);
[z,p,k]=butter(n,wn);
[num,den]=zp2tf(z,p,k);
disp(tf(num,den));
%2b
DSP LAB ASSIGNMENT 10 PAGE 4
t=0:20/fs:1;
x1=sin(2*pi*3*t);
x2=sin(2*pi*8*t);
x=x1+x2;
y=filter(num,den,x);
figure
subplot(2,1,1)
plot(t,x)
xlabel("t")
ylabel("x(t)")
subplot(2,1,2)
plot(t,y)
xlabel("t")
ylabel("y(t)")
Output:
tf with properties:
Numerator: {[3.2691e-05 1.3076e-04 1.9615e-04 1.3076e-04 3.2691e-05]}
Denominator: {[1 -3.5848 4.8385 -2.9129 0.6597]}
Variable: 's'
IODelay: [0]
InputDelay: [0]
OutputDelay: [0]
InputName: {''}
InputUnit: {''}
InputGroup: [1x1 struct]
OutputName: {''}
OutputUnit: {''}
OutputGroup: [1x1 struct]
Notes: [0x1 string]
UserData: []
Name: ''
Ts: [0]
TimeUnit: 'seconds'
SamplingGrid: [1x1 struct]
DSP LAB ASSIGNMENT 10 PAGE 5
DSP LAB ASSIGNMENT 10 PAGE 6