Experiment No. 6
Experiment No. 6
6
1. Program:
8
0.7072
The order and cut-off frequency for Chebyshev-1 are
4
0.6283
The order and cut-off frequency for Elliptic are
3
Magnitude in db
Magnitude in db
Magnitude in dB
0.6283
Frequency Response-Butterworth
200
0
-200
4
5
6
7
Frequency in rad/s
Frequency Response-Chebyshev
10
10
10
0
-100
-200
4
5
6
7
Frequency in rad/s
Frequency Response-Elliptic
0
-50
-100
2. Program:
4
5
6
Frequency in rad/s
subplot(412), plot(t,yb);
title('T ime domain plot of Butterworth f i l t e r ed) ; s igna l '
subplot(413), plot(t,yc);
title('T ime domain plot of Chebyshev f i l t e r ed ) signa
;
l'
subplot(414), plot(t,ye);
title('T ime domain plot of El l i p t i c f i l t e r ed
) ; signa l '
xlabel(' t ime- - - - - )-;- >'
% Get spectrum and plot
N = 512;
w = [0:N/2 - 1]*(Fs /N%defin
);
ing f requency vector for plot t i ng
X = fft(x,N);
Yb = fft(yb,N);
Yc = fft(yc,N);
Ye = fft(ye,N);
figure(3);
subplot(411), plot(w,abs(X(1:N/2)));
title('Spect rum of input signa
); l '
subplot(412), plot(w,abs(Yb(1:N/2)));
title('Spect rum of Butterworth f i l t e r ed ) ;signa l '
subplot(413), plot(w,abs(Yc(1:N/2)));
title('Spect rum of Chebyshev f i l t e r ed signa
);
l'
subplot(414), plot(w,abs(Ye(1:N/2)));
title('Spect rum of El l i p t i c f i l t e r ed) ; signa l '
xlabel('F requency in Hz'
);
Output:
For Butterworth, the order and cut off frequency in Hz are
4
28.4574 31.5617
For Chebyshev the order and cut-off frequency in Hz are
3
29
31
31
10
20
30
40
50
60
70
80
70
80
70
80
Magnitude in dB
10
20
30
40
50
60
10
20
30
40
50
Frequency in Hz
60
0.05
0.1
0.15
0.2
0.25
0.3
0.35
0.4
Time domain plot of Butterworth filtered signal
0.45
0.5
0.05
0.1
0.15
0.2
0.25
0.3
0.35
0.4
Time domain plot of Chebyshev filtered signal
0.45
0.5
0.05
0.1
0.45
0.5
0.05
0.1
0.45
0.5
2
0
-2
1
0
-1
0.15
0.2
0.25
0.3
0.35
0.4
Time domain plot of Elliptic filtered signal
1
0
-1
0.15
0.2
0.25
0.3
time------->
0.35
0.4
10
20
30
40
50
60
Spectrum of Butterworth filtered signal
70
80
10
20
30
40
50
60
Spectrum of Chebyshev filtered signal
70
80
10
20
70
80
10
20
70
80
20
10
0
10
5
0
30
40
50
60
Spectrum of Elliptic filtered signal
20
10
0
30
40
50
Frequency in Hz
60
3. Program:
clc;
clear al l;
close al l;
d = [1 1]%Numerator
;
polynomial in s of analog f i l t e r
c = [1 5 6]
%Denominator
;
polynomial in s of analog f i l t e r
T = 0.1;
%Sampling t ime
[r,pa,k] = residue(d,c);
disp('Po les of analog f i)l;t e r '
disp(pa');
pd = exp(pa*T);
[b,a] = residuez(r,pd,k);
disp('Numerator polynomial in z^(- 1) of dig i ta
) ;l f i l t e r '
disp(b);
disp('Denominator polynomial in z^(- 1) of dig i ta
) ;l f i l t e r '
disp(a);
% Impulse response & magnitude response
[hd,n] = impz(b,a);
subplot(211),stem(n*T,hd), hold on;
plot(n*T,hd,' r )' , t i t l 'Impulse
e(
responses');
xlabel('Time in seconds');
ylabel('Ampl i tude)';
h = legend('D ig i t a l Fi l,'Analog
ter '
filter','Best');
set(h,'Interpreter','none')
[Hd,fd] = freqz(b,a,1/T);
[Ha,fa] = freqs(d,c,1/T);
subplot(212), plot(fd,abs(Hd));
hold on, plot(fa,abs(Ha),'r');
title('Frequency responses');
xlabel('Frequency in Hz');
ylabel('Magnitude');
h = legend('Digital Filter','Analog filter','Best');
set(h,'Interpreter','none');
Output:
Poles of analog filter
-3.0000 -2.0000
Numerator polynomial in z^(-1) of digital filter
1.0000 -0.8966
Denominator polynomial in z^(-1) of digital filter
1.0000 -1.5595
0.6065
Impulse responses
Amplitude
1
Digital Filter
Analog filter
0.5
0
-0.5
0.5
1.5
2
2.5
3
Time in seconds
Frequency responses
3.5
4.5
Magnitude
3
Digital Filter
Analog filter
2
1
0
4
5
6
Frequency in Hz
4. Program:
10
figure(1);
subplot(211), plot(wbd/pi,20*log10(abs(Hbd))),grid on;
ylabel('Magni tude in dB'
);
xlabel('F requency in pi uni
) ; ts '
subplot(212),plot(wbd/pi,angle(Hbd)/pi),grid on;
xlabel('F requency in pi uni
) ; ts '
ylabel('p i uni ts
); '
% Chebyshev type-1
[Nc1,wcc1] = cheb1ord(wa_p,wa_s,rp,rs,' s ') ;
[bc1_s,ac1_s] = cheby1(Nc1,rp,wcc1,' s ') ;
disp('For Chebyshev- 1, the order and cut of f f requency
),
are '
disp( Nc1),disp(wcc1);
[Hc1,wc1] = f reqs(bc1_s ,ac1_s
%)f;req . response
[bc1_z,ac1_z] = impinvar(bc1_s,ac1_s,1/T);
[Hc1d,wc1d] = f reqz (bc1_z ,ac1_z
%)Digi
;
ta l f req . response
figure(2);
subplot(211), plot(wc1d/pi,20*log10(abs(Hc1d))),grid on;
ylabel('Magni tude in dB'
);
xlabel('F requency in pi uni
) ; ts '
subplot(212),plot(wc1d/pi,angle(Hc1d)/pi),grid on;
ylabel('p i uni ts
); '
xlabel('F requency in pi uni
) ; ts '
% Chebyshev type-2
[Nc2,wcc2] = cheb2ord(wa_p,wa_s,rp,rs,' s ') ;
[bc2_s,ac2_s] = cheby2(Nc2,rs,wcc2,' s ') ;
disp('For Chebyshev- 2, the order and cut of f f requency
),
disp( Nc2),disp(wcc2);
[Hc2,wc2] = f reqs(bc2_s ,ac2_s
%)f;req . response
[bc2_z,ac2_z] = impinvar(bc2_s,ac2_s,1/T);
[Hc2d,wc2d] = f reqz (bc2_z ,ac2_z
%)Digi
;
ta l f req . response
are '
figure(3);
subplot(211), plot(wc2d/pi,20*log10(abs(Hc2d))),grid on;
ylabel('Magni tude in dB'
);
xlabel('F requency in pi uni
) ; ts '
subplot(212),plot(wc2d/pi,angle(Hc2d)/pi),grid on;
ylabel('p i uni ts
); '
xlabel('F requency in pi uni
) ; ts '
% Elliptic
[Ne,wce] = ellipord(wa_p,wa_s,rp,rs,' s ') ;
[be_s,ae_s] = ellip(Ne,rp,rs,wce,' s ') ;
disp('For El l i p t i c , the order and cut of f f requency
),
are '
disp( Ne),disp(wce);
[He,we] = f reqs (be_s ,ae_s
%) f; req . response
[be_z,ae_z] = impinvar(be_s,ae_s,1/T);
[Hed,wed] = f reqz(be_z ,ae_z
%) Digi
;
ta l f req . response
figure(4);
subplot(211), plot(wed/pi,20*log10(abs(Hed))),grid on;
ylabel('Magni tude in dB'
);
xlabel('F requency in pi uni
) ; ts '
subplot(212),plot(wed/pi,angle(Hed)/pi),grid on;
ylabel('p i uni ts
); '
xlabel('F requency in pi uni
) ; ts '
Output:
For Butterworth, the order and cut off frequency are
6
0.7087
For Chebyshev-1, the order and cut off frequency are
4
0.6283
For Chebyshev-2, the order and cut off frequency are
4
0.8236
For Elliptic, the order and cut off frequency are
3
0.6283
Butterworth
Magnitude in dB
0
-20
-40
-60
-80
0.1
0.2
0.3
0.4
0.5
0.6
Frequency in pi units
0.7
0.8
0.9
0.1
0.2
0.3
0.4
0.5
0.6
Frequency in pi units
0.7
0.8
0.9
pi units
0.5
0
-0.5
-1
Chebyshev-1
Magnitude in dB
50
0
-50
-100
0.1
0.2
0.3
0.4
0.5
0.6
Frequency in pi units
0.7
0.8
0.9
0.1
0.2
0.3
0.4
0.5
0.6
Frequency in pi units
0.7
0.8
0.9
pi units
0.5
0
-0.5
-1
Chebyshev-2
Magnitude in dB
5
0
-5
-10
-15
0.1
0.2
0.3
0.4
0.5
0.6
Frequency in pi units
0.7
0.8
0.9
0.1
0.2
0.3
0.4
0.5
0.6
Frequency in pi units
0.7
0.8
0.9
pi units
0.5
0
-0.5
-1
Elliptic
Magnitude in dB
10
0
-10
-20
-30
0.1
0.2
0.3
0.4
0.5
0.6
Frequency in pi units
0.7
0.8
0.9
0.1
0.2
0.3
0.4
0.5
0.6
Frequency in pi units
0.7
0.8
0.9
pi units
0.5
0
-0.5
-1
5. Program:
clc;
clear al l;
close al l;
d = [1 1]%Numerator
;
polynomial in s of analog f i l t e r
c = [1 5 6]
%Denominator
;
polynomial in s of analog f i l t e r
T = 1;%Sampling t ime
[b,a] = bilinear(d,c,1/T);
disp('D ig i t a l f i l t e r numerator )coef
;
fs '
disp(b);
disp('D ig i t a l f i l t e r denominator )coef
;
fs '
disp(a);
Output:
Digital filter numerator coeffs
0.1500
0.1000 -0.0500
0.2000 -0.0000
6. Program:
disp( Nb),disp(wcb);
[Hb,wb] = f reqs(bb_s ,ab_s
%) ;Analog f req . response
[bb_z,ab_z] = bilinear(bb_s,ab_s,1/T);
[Hbd,wbd] = f reqz(bb_z ,ab_z
%) ;Dig i ta l f req . response
figure(1);
subplot(211), plot(wbd/pi,20*log10(abs(Hbd))),grid on;
ylabel('Magni tude in dB'
);
xlabel('F requency in pi uni
) ;t s '
title('But te rwor th) ;'
subplot(212),plot(wbd/pi,angle(Hbd)/pi),grid on;
xlabel('F requency in pi uni
) ;t s '
ylabel('p i uni ts
); '
% Chebyshev type-1
[Nc1,wcc1] = cheb1ord(wa_p,wa_s,rp,rs,'s ') ;
[bc1_s,ac1_s] = cheby1(Nc1,rp,wcc1,'s ') ;
disp('For Chebyshev- 1, the order and cut of f f requency
),
are '
disp( Nc1),disp(wcc1);
[Hc1,wc1] = f reqs(bc1_s ,ac1_s
%)f;req . response
[bc1_z,ac1_z] = bilinear(bc1_s,ac1_s,1/T);
[Hc1d,wc1d] = f reqz(bc1_z ,ac1_z
%)Dig
; i ta l f req . response
figure(2);
subplot(211), plot(wc1d/pi,20*log10(abs(Hc1d))),grid on;
ylabel('Magni tude in dB'
);
xlabel('F requency in pi uni
) ;t s '
title('Chebyshev- 1'
);
subplot(212),plot(wc1d/pi,angle(Hc1d)/pi),grid on;
ylabel('p i uni ts
); '
xlabel('F requency in pi uni
) ;t s '
% Chebyshev type-2
[Nc2,wcc2] = cheb2ord(wa_p,wa_s,rp,rs,'s ') ;
[bc2_s,ac2_s] = cheby2(Nc2,rs,wcc2,'s ') ;
disp('For Chebyshev- 2, the order and cut of f f requency
),
are '
disp( Nc2),disp(wcc2);
[Hc2,wc2] = f reqs(bc2_s ,ac2_s
%)f;req . response
[bc2_z,ac2_z] = bilinear(bc2_s,ac2_s,1/T);
f req . response
figure(3);
subplot(211), plot(wc2d/pi,20*log10(abs(Hc2d))),grid on;
ylabel('Magni tude in dB'
);
xlabel('F requency in pi uni
) ;t s '
title('Chebyshev- 2'
);
subplot(212),plot(wc2d/pi,angle(Hc2d)/pi),grid on;
ylabel('p i uni ts
); '
xlabel('F requency in pi uni
) ;t s '
% Elliptic
[Ne,wce] = ellipord(wa_p,wa_s,rp,rs,'s ') ;
[be_s,ae_s] = ellip(Ne,rp,rs,wce,'s ') ;
disp('For El l i p t i c , the order and cut of f f requency
),
are '
disp( Ne),disp(wce);
[He,we] = f reqs(be_s ,ae_s
%) f; req . response
[be_z,ae_z] = bilinear(be_s,ae_s,1/T);
[Hed,wed] = f reqz(be_z ,ae_z
%) Dig
; i ta l f req . response
figure(4);
subplot(211), plot(wed/pi,20*log10(abs(Hed))),grid on;
ylabel('Magni tude in dB'
);
xlabel('F requency in pi uni
) ;t s '
title('E l l i p t )i c
;'
subplot(212),plot(wed/pi,angle(Hed)/pi),grid on;
ylabel('p i uni ts
); '
xlabel('F requency in pi uni
) ;t s '
Output:
For Butterworth, the order and cut off frequency are
6
0.7087
For Chebyshev-1, the order and cut off frequency are
4
0.6283
200
0
-200
-400
0.1
0.2
0.3
0.4
0.5
0.6
Frequency in pi units
0.7
0.8
0.9
0.1
0.2
0.3
0.4
0.5
0.6
Frequency in pi units
0.7
0.8
0.9
pi units
0.5
0
-0.5
-1
Chebyshev-1
Magnitude in dB
0
-100
-200
-300
0.1
0.2
0.3
0.4
0.5
0.6
Frequency in pi units
0.7
0.8
0.9
0.1
0.2
0.3
0.4
0.5
0.6
Frequency in pi units
0.7
0.8
0.9
pi units
0.5
0
-0.5
-1
Chebyshev-2
Magnitude in dB
-50
-100
0.1
0.2
0.3
0.4
0.5
0.6
Frequency in pi units
0.7
0.8
0.9
0.1
0.2
0.3
0.4
0.5
0.6
Frequency in pi units
0.7
0.8
0.9
pi units
0.5
0
-0.5
-1
Elliptic
Magnitude in dB
0
-20
-40
-60
-80
0.1
0.2
0.3
0.4
0.5
0.6
Frequency in pi units
0.7
0.8
0.9
0.1
0.2
0.3
0.4
0.5
0.6
Frequency in pi units
0.7
0.8
0.9
pi units
0.5
0
-0.5
-1
7. Program:
15
31.7742
Impulse invariance
Bilinear
Magnitude in dB
100
0
-50
-100
0.5
Frequency in pi units
0
-100
-200
-300
0.5
0.5
pi units
pi units
Magnitude in dB
50
0
-0.5
-1
0.5
Frequency in pi units
0.5
Frequency in pi units
0
-0.5
0.5
Frequency in pi units
-1
8. Program:
200
400
600
800
1000
1200
1400
1600
Bilinear
0
-200
-400
0.5
1.5
2.5
3.5
4.5
3.5
4.5
Impulse invariant
58
56
54
0.5
1.5
2.5