DSP Exp8 B2 Grp3
DSP Exp8 B2 Grp3
Ritu Ann Roy George Rahul Anand Ravi Yadav Rahul Chaudhary
B170106EC B170518EC B170556EC B170912EC
B-Batch B-Batch B-Batch B-Batch
NIT Calicut NIT Calicut NIT Calicut NIT Calicut
I. THEORY
A. Butterworth Filter
D. Bilinear Transformation
A. Question I
B. Question II
C. Question III
D. Question IV
A. Question I
C. Question III
Fig. 2. Low pass butterworth filter using IIT Fig. 5. Phase response of elliptic IIR LPF
Elliptical filter has very sharp cut-off frequency i.e. the roll
off factor is very large
D. Question IV
1 %Exp8_Q1_BLT_Butterworth
2 clc;
3 clear;
4 close all;
5 fsamp = 8000; % sampling frequency
6 fp = 1000; % pass band frequency
7 fs = 2000; % stop band frequency
8 As = 30; % stop band attenuation in dB
9 Ap = 0.5; % pass band attenuation in dB
10 dp=10ˆ(-Ap/20);
11 ds=10ˆ(-As/20);
12 T = 1/fsamp;
Fig. 7. Butterworth LPF output 13 % Digital frequencies
14 wp = (2*pi*fp)/fsamp; 40 for i = 1:N
15 ws = (2*pi*fs)/fsamp; 41 H(Z) =H(Z)+ r_bw(i)*((p_z(i))ˆ(Z));
16 % Analog frequenices 42 end
17 Os = (2/T) * tan(ws/2); 43 end
18 Op = (2/T) * tan(wp/2); 44 figure()
19 %Order 45 freqz(H);
20 N = ceil((0.5*log10(((1/(ds*ds))-1)/ 46 title('Butterworth Filter - IIT');
21 ((1/(dp*dp))-1)))
22 /log10(Os/Op))
23 %cutoff frequency
24 Oc = Op/(1/(dp*dp)-1)ˆ(1/(2*N)); B. Question II
25 syms a b c s z hs;
26 a=1;
27 p=1;
28 for i=1:N/2 1 %Exp8_Q2_cheby
29 b=2*sin((2*i-1)*pi/(2*N)); 2 clc;
30 p = p*poly2sym([a,b*Oc,Oc*Oc]); 3 clear all;
31 end 4 close all;
32 den = sym2poly(p); 5 T = 1;
33 num=OcˆN; 6 fsam=8000; % sampling frequency
34 7 fp = 1000; % pass band frequency
35 syms Hs; 8 fs = 2000; % stop band frequency
36 % transfer function in s-domain 9 As = 30; % stop band attenuation in dB
37 Hs=poly2sym(num,s)/poly2sym(den,s) 10 Ap = 0.5; % pass band attenuation in dB
38 s1=(2*(1-zˆ-1))/(T*(1+zˆ-1)); 11 %Digital Frequencies
39 % using BLT to transform from s to z domain 12 wp = (2*pi*fp)/8000;
40 Hz=subs(Hs,s,s1) 13 ws = (2*pi*fs)/8000;
41 [numd dend]= numden(Hz); 14 %Attenuation
42 freqz(sym2poly(numd),sym2poly(dend)); 15 dp=power(10,-Ap/20);
43 title('Butterworth filter - BLT'); 16 ds=power(10,-As/20);
17 %Analog frequencies
18 Op = wp/T; %pass band edge frequency
19 Os = ws/T; %stop band edge frequency
20 %Order
1 %Exp8_Q1_IIT_Butterworth 21 N=ceil(acosh(sqrt((1/(ds*ds)-1)/
2 clc; 22 (1/(dp*dp)-1)))/acosh(Os/Op))
3 clear; 23 e=sqrt(1/(dp*dp)-1);
4 close all; 24 % cutoff frequency
5 T = 1; 25 Oc=Op*cosh(1/N * acosh(1/e));
6 fp = 1000; % pass band frequency 26 yn=(1/2)*(power((sqrt(1+1/(e*e))+(1/e)),1/N)
7 fs = 2000; % stop band frequency 27 -power((sqrt(1+1/(e*e))+(1/e)),-1/N));
8 As = 30; % stop band attenuation in dB 28 k=1:N/2;
9 Ap = 0.5; % pass band attenuation in dB 29 b=2*yn*sin((2*k-1)*pi/(2*N));
10 %Digital Frequencies 30 c=yn*yn+(cos((2*k-1)*pi/(2*N))
11 wp = (2*pi*fp)/8000; 31 .*cos((2*k-1)*pi/(2*N)));
12 ws = (2*pi*fs)/8000; 32 syms p s h z
13 %Analog frequencies 33 p = s*s+b*Op*s+c*Op*Op;
14 Op = wp/T; %pass band edge frequency 34 deno = prod(p)
15 Os = ws/T; %stop band edge frequency 35 num1 = power(wp,N)*prod(c*dp); %Changed..
16 %Attenuation 36 if(rem(N,2)==1)
17 dp = 10ˆ(-Ap/20); 37 deno = deno*(s+Op*C0);
18 ds = 10ˆ(-As/20); 38 num1 = num1*C0/power(dp,(N-1)/2);
19 %Order 39 end
20 N = ceil((0.5*log10(((1/(ds*ds))-1)/ 40 den1 = sym2poly(deno);
21 ((1/(dp*dp))-1)))/log10(Os/Op)) 41 t=tf(num1,den1,'variable','s');%transfer ...
22 %cutoff frequency function in s-domain
23 Oc = Op/(1/(dp*dp)-1)ˆ(1/(2*N)); 42
24 %We get N = 7, which is odd 43 [r p k]=residue(num1,den1);%partial fraction
25 poles = zeros(1,N); 44 discrete=0;
26 for i = 1:N 45 for k=1:length(r)
27 poles(i) = Oc*exp( (1i*pi*(N + 2*i ... 46 discrete=discrete+(z*r(k))/(z-exp(p(k)));
-1))/(2*N)); 47 end
28 end 48 [num ,den] = numden(discrete);
29 z = [] ; % No zeros since butterworth filter 49 num = sym2poly(num);
30 k = (Oc)ˆN; 50 den = sym2poly(den);
31 [b a] = zp2tf(z,poles,k); 51 % transfer function in z-domain
32 %To get partial fraction terms 52 H=tf(num,den,-1,'variable','z');
33 [r_bw, p_bw, k_bw] = residue(b,a); 53 w=0:100:100000;
34 % Now to get the s- pk form to 1-eˆpkTzˆ-1 ... 54 figure()
form: 55 freqz(num,den); % frequency ...
35 for i = 1:N response in z-domain
36 p_z(i) = exp(p_bw(i)); 56 title('Magnitude and Phase Response of ...
37 end Chebyshev Filter');
38 H = zeros(1,100);
39 for Z = 1:100
C. Question III
1 %Exp8_Q3_IIR_LPF
2 clc
3 clearvars
4 p_gain=0.9440;
5 s_gain=0.03162
6 p_band=800
7 s_band=1000
8 fs=8000
9 wp=2*pi*p_band/fs
10 ws=2*pi*s_band/fs
11 p_gain_db=-20*log10(p_gain)
12 s_gain_db=-20*log10(s_gain)
13 [b,a] = ellip(7, p_gain_db, s_gain_db, wp);
14 fvtool(b,a);
D. Question IV
1 %Exp8_Q4_SIGNAL FILTERING
2
3 t = 0:1e-5:10/500;
4 xt = 0:1/8000:10/500;
5 xs1 = sin(2*pi*500*xt);
6 xs2 = sin(2*pi*3000*xt);
7 xs = xs1+xs2;
8 figure
9 ns = length(xs);
10 f = (-ns/2:ns/2-1)*(8000/ns);
11 plot(f,fftshift(abs(fft(xs))));
12 title('FFT of IP');
13 figure
14 y=filter(b2,a2,xs);
15 pow = fftshift(abs(fft(y))).ˆ2/ns;
16 plot(f,pow);
17 title('Lowpass filter OP');
V. RESULT
A. Question I
A low pass butterworth filter is designed and implemented
using BLT and IIT with the given specifications and the
magnitude and phase spectrum is plotted.
B. Question II
A low pass chebychev filter is designed and implemented
using IIT with the given specifications and the magnitude and
phase spectrum is plotted.
C. Question III
An elliptic IIR low pass filter with the given specifications
is implemented and the gain response is plotted.
D. Question IV
Signals with different frequencies are generated in passband
and stopband and filtered using these filters and the results are
plotted and verified.