Program:
clc
clear all
Wdp=2*pi*Wp;
Wds=2*pi*Ws;
Wap=2*Fs*tan(Wdp/(2*Fs));
Was=2*Fs*tan(Wds/(2*Fs));
%lowpass prototype
Vs=Was/Wap;
%filter order
e=10^(0.1*Ap)-1;
n=(log((10^(0.1*As)-1)/e))/(2*(log(Vs)));
N=ceil(n);
Wn=(Wdp)/(2*pi*Fs);
[b,a]=butter(N,Wn,'low');
freqz(b,a);
Result :
Conclusion:
By performing this practical we conclude that using butter we can verify low
pass filter for any given filter parameter.
Experiment-7
Program:
clc
clear all
Waph=2*Fs*tan(Wph/(Fs*2));
Wapl=2*Fs*tan(Wpl/(Fs*2));
Wash=2*Fs*tan(Wsh/(Fs*2));
Wasl=2*Fs*tan(Wsl/(Fs*2));
%bandpass prototype
Vs=((Wash-Wasl)/(Waph-Wapl));
e=(10^(.1*Ap)-1);
n=(log((10^(.1*As)-1)/e)/(2*log(Vs)));
n1=ceil(n);
N=n1/2;
Wn=[Wpl/pi,Wph/pi];
[b,a]=butter(N,Wn,'bandpass');
freqz(b,a);
Result:
Conclusion:
Program:
clc
clear all
Waph=2*Fs*tan(Wph/(Fs*2));
Wapl=2*Fs*tan(Wpl/(Fs*2));
Wash=2*Fs*tan(Wsh/(Fs*2));
Wasl=2*Fs*tan(Wsl/(Fs*2));
%bandstop prototype
Vs=((Waph-Wapl)/(Wash-Wasl));
%find filter order
e=(10^(.1*Ap)-1);
n=(log((10^(.1*As)-1)/e)/(2*log(Vs)));
n1=ceil(n);
N=n1/2;
Wn=[Wsl/pi,Wsh/pi];
[b,a]=butter(N,Wn,'stop');
freqz(b,a);
Result:
Conclusion:
Program:
clc
clear all
Wap=2*Fs*tan(Wp/(2*Fs));
Was=2*Fs*tan(Ws/(2*Fs));
Vs=Was/Wap;
e=10^(0.1*Ap)-1;
n=(acosh(((10^(.1*As)-1)/e)^.5)/acosh(Vs));
N=ceil(n);
Wn=Wp/pi;
[b,a]=cheby1(N,Ap,Wn,'low');
freqz(b,a);
Result:
Conclusion:
By performing this practical we can conclude that we get the ripple in the
passband and flat response in stopband & verify the characteristics of
chebyshev-I type filter.
Experiment-10
Aim: To design a Chebyshev –II low pass filter for the following
Example.
Pass band attenucation= 2db,Stopband attenuation=20db
Pass band frequency Wp=0.2*pi (rad/sec)
Stop band frequency=0.3*pi ( rad/sec )
Sampling frequency=2000 Hz
Program:
clc
clear all
Wap=2*Fs*tan(Wp/(2*Fs));
Was=2*Fs*tan(Ws/(2*Fs));
%lowpass prototype
Vs=Was/Wap;
e=10^(0.1*Ap)-1;
n=(acosh(((10^(.1*As)-1)/e)^.5)/acosh(Vs));
N=ceil(n);
%normalised cutoff frequencies
Wn=Ws/pi;
[b,a]=cheby2(N,As,Wn,'low');
freqz(b,a);
Result:
Conclusion:
By performing this practical we can conclude that we get the ripple in the
stopband and flat response in passband & verify the characteristics of
chebyshev-II type filter.
Experiment-11
Program:
clc
clear all
Wp=[Wpl/Fs,Wph/Fs];
Ws=[Wsl/Fs,Wsh/Fs];
[n,Wn]=cheb1ord(Wp,Ws,Ap,As);
Conclusion:
Aim: Design third and sixth order digital Butterworth filter that
eliminates the component sin(8t). the highest frequency component
in signal fm=8/(2*pi)
Program:
clc
clear all
Wn=Wp/(Fs);
n=3;
[b,a]=butter(n,Wn,'low');
figure(1);
freqz(b,a);
n=6;
[b,a]=butter(n,Wn,'low');
figure(2);
freqz(b,a);
Result:
Conclusion:
Aim: To design the 25-tap low pass filter with cutoff frequency
0.5*pi radians using rectangle and hamming, Blackman, hanning
& Bartlett windowing methods
Program:
clc
clear all
Wc=0.5*pi;
h0=Wc/pi;
N=25;
for M=1:25,
M1=(M-1)-12;
hn(M)=sin(Wc*M1)/(M1*pi);
end
hn(13)=h0;
M1=-12:1:12;
subplot(2,2,1),stem(M1,hn),title('Original impulse response');
M=1:1:25;
subplot(2,2,2),stem(M,hn),title('Shifted impulse response');
[a,f]=freqz(hn)
A=abs(a);
M=20*log(A);
Q=phase(a)*180/pi;
subplot(2,2,3),plot(f,M),title('Magnitude response');
axis([0 3.321 -300 100]);
subplot(2,2,4),plot(f,Q),title('Phase response');
axis([0 3.321 -3000 30]);
%rectangular window
w=window(@rectwin,N);
figure(2);
subplot(2,2,1),stem(w),title('Rectangular window response');
h1=hn.*w';
subplot(2,2,2),stem(h1),title('FIR filter response');
[a,f]=freqz(h1)
A=abs(a);
M=20*log(A);
Q=phase(a)*180/pi;
subplot(2,2,3),plot(f,M),title('Magnitude response');
axis([0 3.321 -300 100]);
subplot(2,2,4),plot(f,Q),title('Phase response');
axis([0 3.321 -3000 30]);
%hamming window
w=window(@hamming,N);
figure(3);
subplot(2,2,1),stem(w),title('Hamming window response');
h2=hn.*w';
subplot(2,2,2),stem(h2),title('FIR filter response');
[a,f]=freqz(h2)
A=abs(a);
M=20*log(A);
Q=phase(a)*180/pi;
subplot(2,2,3),plot(f,M),title('Magnitude response');
axis([0 3.321 -300 100]);
subplot(2,2,4),plot(f,Q),title('Phase response');
axis([0 3.321 -3000 30]);
%blackman window
w=window(@blackman,N);
figure(4);
subplot(2,2,1),stem(w),title('Blackman window response');
h3=hn.*w';
subplot(2,2,2),stem(h3),title('FIR filter response');
[a,f]=freqz(h3)
A=abs(a);
M=20*log(A);
Q=phase(a)*180/pi;
subplot(2,2,3),plot(f,M),title('Magnitude response');
axis([0 3.321 -300 100]);
subplot(2,2,4),plot(f,Q),title('Phase response');
axis([0 3.321 -3000 30]);
%hanning window
w=window(@hann,N);
figure(5);
subplot(2,2,1),stem(w),title('Hanning window response');
h4=hn.*w';
subplot(2,2,2),stem(h4),title('FIR filter response');
[a,f]=freqz(h4)
A=abs(a);
M=20*log(A);
Q=phase(a)*180/pi;
subplot(2,2,3),plot(f,M),title('Magnitude response');
axis([0 3.321 -300 100]);
subplot(2,2,4),plot(f,Q),title('Phase response');
axis([0 3.321 -3000 30]);
%bartlett window
w=window(@bartlett,N);
figure(6);
subplot(2,2,1),stem(w),title('Bartlett window response');
h5=hn.*w';
subplot(2,2,2),stem(h5),title('FIR filter response');
[a,f]=freqz(h5)
A=abs(a);
M=20*log(A);
Q=phase(a)*180/pi;
subplot(2,2,3),plot(f,M),title('Magnitude response');
axis([0 3.321 -300 100]);
subplot(2,2,4),plot(f,Q),title('Phase response');
axis([0 3.321 -3000 30]);
Conclusion:
Program:
clc
clear all
Wc=0.5*pi;
h0=Wc/pi;
N=25;
for M=1:N,
M1=(M-1)-12;
hn(M)=sin(Wc*M1)/(M1*pi);
end
hn(13)=h0;
M1=-12:1:12;
subplot(2,2,1),plot(M1,hn),title('M=25 Original impulse response');
M1=1:1:25;
subplot(2,2,2),stem(M1,hn),title('M=25 Shifted impulse response');
[a,f]=freqz(hn)
A=abs(a);
M=20*log(A);
Q=phase(a)*180/pi;
subplot(2,2,3),plot(f,M),title('M=25 Magnitude response');
axis([0 3.321 -300 100]);
subplot(2,2,4),plot(f,Q),title('M=25 Phase response');
axis([0 3.321 -3000 30]);
%hamming window
w=window(@hamming,N);
figure(2);
subplot(2,2,1),stem(w),title('M=25 Hamming window response');
h2=hn.*w';
subplot(2,2,2),stem(h2),title('M=25 FIR filter response');
[a,f]=freqz(h2)
A=abs(a);
M=20*log(A);
Q=phase(a)*180/pi;
subplot(2,2,3),plot(f,M),title('M=25 Magnitude response');
axis([0 3.321 -300 100]);
subplot(2,2,4),plot(f,Q),title('M=25 Phase response');
axis([0 3.321 -3000 30]);
%blackman window
w=window(@blackman,N);
figure(3);
subplot(2,2,1),stem(w),title('M=25 Blackman window response');
h3=hn.*w';
subplot(2,2,2),stem(h3),title('M=25 FIR filter response');
[a,f]=freqz(h3)
A=abs(a);
M=20*log(A);
Q=phase(a)*180/pi;
subplot(2,2,3),plot(f,M),title('M=25 Magnitude response');
axis([0 3.321 -300 100]);
subplot(2,2,4),plot(f,Q),title('M=25 Phase response');
axis([0 3.321 -3000 30]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Wc=0.5*pi;
h0=Wc/pi;
%take no of tap and other filter coefficient
N=51;
for M=1:N,
M1=(M-1)-25;
hn(M)=sin(Wc*M1)/(M1*pi);
end
hn(26)=h0;
M1=-25:1:25;
figure(4);
subplot(2,2,1),plot(M1,hn),title('M=51 Original impulse response');
M1=1:1:51;
subplot(2,2,2),stem(M1,hn),title('M=51 Shifted impulse response');
[a,f]=freqz(hn);
A=abs(a);
M=20*log(A);
Q=phase(a)*180/pi;
subplot(2,2,3),plot(f,M),title('M=51 Magnitude response');
axis([0 3.321 -300 100]);
subplot(2,2,4),plot(f,Q),title('M=51 Phase response');
axis([0 3.321 -3000 30]);
%hamming window
w=window(@hamming,N);
figure(5);
subplot(2,2,1),stem(w),title('M=51 Hamming window response');
h2=hn.*w';
subplot(2,2,2),stem(h2),title('M=51 FIR filter response');
[a,f]=freqz(h2)
A=abs(a);
M=20*log(A);
Q=phase(a)*180/pi;
subplot(2,2,3),plot(f,M),title('M=51 Magnitude response');
axis([0 3.321 -300 100]);
subplot(2,2,4),plot(f,Q),title('M=51 Phase response');
axis([0 3.321 -3000 30]);
%blackman window
w=window(@blackman,N);
figure(6);
subplot(2,2,1),stem(w),title('M=51 Blackman window response');
h3=hn.*w';
subplot(2,2,2),stem(h3),title('M=51 FIR filter response');
[a,f]=freqz(h3)
A=abs(a);
M=20*log(A);
Q=phase(a)*180/pi;
subplot(2,2,3),plot(f,M),title('M=51 Magnitude response');
axis([0 3.321 -300 100]);
subplot(2,2,4),plot(f,Q),title('M=51 Phase response');
axis([0 3.321 -3000 30]);
Conclusion:
Aim:To plot the frequency response of low pass filter using Kaiser
window for the different value of betta
Program:
clc
clear all
Wc=0.5*pi;
h0=Wc/pi;
N=25;
for M=1:25,
M1=(M-1)-12;
hn(M)=sin(Wc*M1)/(M1*pi);
end
hn(13)=h0;
M1=-12:1:12;
subplot(2,2,1),stem(M1,hn),title('Original impulse response');
M=1:1:25;
subplot(2,2,2),stem(M,hn),title('Shifted impulse response');
[a,f]=freqz(hn)
A=abs(a);
M=20*log(A);
Q=phase(a)*180/pi;
subplot(2,2,3),plot(f,M),title('Magnitude response');
axis([0 3.321 -300 100]);
subplot(2,2,4),plot(f,Q),title('Phase response');
axis([0 3.321 -3000 30]);
w=window(@kaiser,N,0.5);
figure(2);
subplot(2,2,1),stem(w),title('Kaiser window B=0.5 response');
h1=hn.*w';
subplot(2,2,2),stem(h1),title('FIR filter response');
[a,f]=freqz(h1)
A=abs(a);
M=20*log(A);
Q=phase(a)*180/pi;
subplot(2,2,3),plot(f,M),title('Magnitude response');
axis([0 3.321 -300 100]);
subplot(2,2,4),plot(f,Q),title('Phase response');
axis([0 3.321 -3000 30]);
w=window(@kaiser,N,1);
figure(3);
subplot(2,2,1),stem(w),title('Kaiser window B=1 response');
h1=hn.*w';
subplot(2,2,2),stem(h1),title('FIR filter response');
[a,f]=freqz(h1)
A=abs(a);
M=20*log(A);
Q=phase(a)*180/pi;
subplot(2,2,3),plot(f,M),title('Magnitude response');
axis([0 3.321 -300 100]);
subplot(2,2,4),plot(f,Q),title('Phase response');
axis([0 3.321 -3000 30]);
w=window(@kaiser,N,2);
figure(4);
subplot(2,2,1),stem(w),title('Kaiser window B=2 response');
h1=hn.*w';
subplot(2,2,2),stem(h1),title('FIR filter response');
[a,f]=freqz(h1)
A=abs(a);
M=20*log(A);
Q=phase(a)*180/pi;
subplot(2,2,3),plot(f,M),title('Magnitude response');
axis([0 3.321 -300 100]);
subplot(2,2,4),plot(f,Q),title('Phase response');
axis([0 3.321 -3000 30]);
Conclusion:
Aim:To design FIR low pass filter with cutoff frequency 0.5*pi
using frequency sampling methods
Program:
clc
clear all
for K=1:1:M+1
omega(K)=2*pi*(K-1)/N;
if omega(K)<=wc
H(K)=1;
else
H(K)=0;
end
end
for n=1:1:M+1
h1(n)=0;
for K=1:1:M
h1(n)=h1(n)+2*H(K+1)*cos(2*pi*(K)*(n-M-1)/N);
end
h2(n)=(H(1)+h1(n))/N;
end
h3=h2(M:-1:1);
Hn=[h2 h3];
freqz(Hn,1);
Result:
No. of Taps - 25
Cutoff freq - 0.5*pi
Conclusion: