Vous êtes sur la page 1sur 27

Experiment-6

Aim: To design a Butterworth low pass filter for the following


specifications:
Pass band attenuations = 4db, Stop band Attenuations = 30db
Pass band frequency = 400Hz, Stopband frequency = 800Hz
Sampling frequency = 2000Hz

Program:

clc
clear all

%enter lowpass filer parameters

Ap=input(' enter the value of passband attenuation ');


As=input(' enter the value of stopband attenuation ');
Wp=input(' enter the value of passband frequency ');
Ws=input(' enter the value of stopband frequency ');
Fs=input(' enter the value of sampling frequency ');

%digital frequencies in rad/sec

Wdp=2*pi*Wp;
Wds=2*pi*Ws;

%convert digital frequencies into analog frequencies

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);

%normalised cutoff frequencies

Wn=(Wdp)/(2*pi*Fs);

%frequency response of the filter

[b,a]=butter(N,Wn,'low');
freqz(b,a);

Result :

enter the value of passband attenuation 4


enter the value of stopband attenuation 30
enter the value of passband frequency 400
enter the value of stopband frequency 800
enter the value of sampling frequency 2000

Conclusion:

By performing this practical we conclude that using butter we can verify low
pass filter for any given filter parameter.
Experiment-7

Aim: To design a butterworth Band pass filter for the following


specifications:
Pass band attenucation= 2db, Stop band attenu.=20db
Pass band frequency Wp=[0.2*pi to 0.4*pi]rad/sec
Stop band frequency=[0.1*pi to 0.5*pi] rad/sec
Sampling frequency=2000 Hz

Program:

clc
clear all

%enter filter paramaters

Ap=input('enter the value of passband attenuation ');


As=input('enter the value of stopband attenuation ');
Wpl=input('enter the value of lower passband frequncy in rad/sec ');
Wph=input('enter the value of upper passband frequncy in rad/sec ');
Wsl=input('enter the value of lower stopband frequncy in rad/sec ');
Wsh=input('enter the value of upper stopband frequncy in rad/sec ');
Fs=input('enter the value of sampling fequency in Hz ');

%convert digital frequencies into analog frequencies

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));

%find filter order

e=(10^(.1*Ap)-1);
n=(log((10^(.1*As)-1)/e)/(2*log(Vs)));
n1=ceil(n);
N=n1/2;

%find filter cutoff frequency

Wn=[Wpl/pi,Wph/pi];

%frequency response of the filter

[b,a]=butter(N,Wn,'bandpass');
freqz(b,a);

Result:

enter the value of passband attenuation 2


enter the value of stopband attenuation 20
enter the value of lower passband frequncy in rad/sec 0.2*pi
enter the value of upper passband frequncy in rad/sec 0.4*pi
enter the value of lower stopband frequncy in rad/sec 0.1*pi
enter the value of upper stopband frequncy in rad/sec 0.5*pi
enter the value of sampling fequency in Hz 2000

Conclusion:

By performing this practical we can conclude that we get exactly passband


between 0.2*pi and 0.4*pi rad/sec.
Experiment-8

Aim: To design a butterworth Band reject filter for the following


Example.
Pass band attenucation= 2db, Stop band attenu.=20db
Pass band frequency Wp=[0.1*pi to 0.5*pi]rad/sec
Stop band frequency=[0.2*pi to 0.4*pi] rad/sec
Sampling frequency=2000 Hz

Program:

clc
clear all

%enter filter paramaters

Ap=input('enter the value of passband attenuation ');


As=input('enter the value of stopband attenuation ');
Wpl=input('enter the value of lower passband frequncy in rad/sec ');
Wph=input('enter the value of upper passband frequncy in rad/sec ');
Wsl=input('enter the value of lower stopband frequncy in rad/sec ');
Wsh=input('enter the value of upper stopband frequncy in rad/sec ');
Fs=input('enter the value of sampling fequency in Hz ');

%convert digital frequencies into analog frequencies

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;

%find filter cutoff frequency

Wn=[Wsl/pi,Wsh/pi];

%frequency response of the filter

[b,a]=butter(N,Wn,'stop');
freqz(b,a);

Result:

enter the value of passband attenuation 2


enter the value of stopband attenuation 20
enter the value of lower passband frequncy in rad/sec 0.1*pi
enter the value of upper passband frequncy in rad/sec 0.5*pi
enter the value of lower stopband frequncy in rad/sec 0.2*pi
enter the value of upper stopband frequncy in rad/sec 0.4*pi
enter the value of sampling fequency in Hz 2000

Conclusion:

By performing this practical we can conclude that we can eliminate the


frequency between 0.2*pi to 0.4*pi.
Experiment-9

Aim:To design a Chebyshev -I low pass filter for the following


Example
Pass band attenucation= 2db,Stop band 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

%enter filter paramaters

Ap=input(' enter the value of passband attenuation ');


As=input(' enter the value of stopband attenuation ');
Wp=input(' enter the value of passband frequency in rad/sec ');
Ws=input(' enter the value of stopband frequency in rad/sec ');
Fs=input(' enter the value of sampling frequency ');

%convert digital frequencies into analog frequencies

Wap=2*Fs*tan(Wp/(2*Fs));
Was=2*Fs*tan(Ws/(2*Fs));

%low pass prototype

Vs=Was/Wap;

%find filter order

e=10^(0.1*Ap)-1;
n=(acosh(((10^(.1*As)-1)/e)^.5)/acosh(Vs));
N=ceil(n);

%normalised cutoff frequencies

Wn=Wp/pi;

%frequency response of the filter

[b,a]=cheby1(N,Ap,Wn,'low');
freqz(b,a);

Result:

enter the value of passband attenuation 2


enter the value of stopband attenuation 20
enter the value of passband frequency in rad/sec 0.2*pi
enter the value of stopband frequency in rad/sec 0.3*pi
enter the value of sampling frequency 2000

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

%enter filter paramaters

Ap=input(' enter the value of passband attenuation ');


As=input(' enter the value of stopband attenuation ');
Wp=input(' enter the value of passband frequency in rad/sec ');
Ws=input(' enter the value of stopband frequency in rad/sec ');
Fs=input(' enter the value of sampling frequency ');

%convert digital frequencies into analog frequencies

Wap=2*Fs*tan(Wp/(2*Fs));
Was=2*Fs*tan(Ws/(2*Fs));

%lowpass prototype

Vs=Was/Wap;

%find filter order

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;

%frequency response of the filter

[b,a]=cheby2(N,As,Wn,'low');
freqz(b,a);

Result:

enter the value of passband attenuation 2


enter the value of stopband attenuation 20
enter the value of passband frequency in rad/sec 0.2*pi
enter the value of stopband frequency in rad/sec 0.3*pi
enter the value of sampling frequency 2000

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

Aim: Design digital chebyshev-I filter that passes the component


sin(800t) in the signal x(t)=2*sin(100*t)+sin(800t)
+sin(1500t).Highest frequency component in signal is
fm=1500/(2*pi).The sampling frequency should be at least
3000/(2*pi)

Program:

clc
clear all

%enter filter paramaters

Ap=input('enter the value of passband attenuation ');


As=input('enter the value of stopband attenuation ');
Wpl=input('enter the value of lower passband frequncy in rad/sec ');
Wph=input('enter the value of upper passband frequncy in rad/sec ');
Wsl=input('enter the value of lower stopband frequncy in rad/sec ');
Wsh=input('enter the value of upper stopband frequncy in rad/sec ');
Fs=input('enter the value of sampling fequency in rad/sec');

%make W=800 rad/sec as a center frequency

Wp=[Wpl/Fs,Wph/Fs];
Ws=[Wsl/Fs,Wsh/Fs];

%find filter order and normalized cutoff frequency

[n,Wn]=cheb1ord(Wp,Ws,Ap,As);

%frequency response of the filter


[b,a]=cheby1(n,Ap,Wn,'bandpass');
freqz(b,a);
Result:

enter the value of passband attenuation 2


enter the value of stopband attenuation 20
enter the value of lower passband frequncy in rad/sec 799
enter the value of upper passband frequncy in rad/sec 801
enter the value of lower stopband frequncy in rad/sec 100
enter the value of upper stopband frequncy in rad/sec 1500
enter the value of sampling fequency in rad/sec3000

Conclusion:

By performing this practical we can conclude that by designing chebyshev-I


bandpass filter we can pass only 800 rad/sec frequency component.
Experiment-12

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

%enter filter paramaters

Wp=input(' enter the value of passband frequency in rad/sec ');


Ws=input(' enter the value of stopband frequency in rad/sec ');
Fs=input(' enter the value of sampling frequency in rad/sec ');

%make W=8 rad/sec as cutoff frequency

Wn=Wp/(Fs);

%frequency response for third order system

n=3;
[b,a]=butter(n,Wn,'low');
figure(1);
freqz(b,a);

%frequency response for sixth order system

n=6;
[b,a]=butter(n,Wn,'low');
figure(2);
freqz(b,a);
Result:

enter the value of passband frequency in rad/sec 3


enter the value of stopband frequency in rad/sec 8
enter the value of sampling frequency in rad/sec 30

Conclusion:

By performing this practical we can conclude that by designing chebyshev-I


low pass we can eliminate the 8 rad/sec frequency component upto some
limit and we get more roll off factor in case of 6th order filter than the 3rd
order filter.
Experiment-13

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

%calculate cutoff frequency and FIR zeroth coefficient

Wc=0.5*pi;
h0=Wc/pi;

%take no of tap and other filter coefficient

N=25;
for M=1:25,
M1=(M-1)-12;
hn(M)=sin(Wc*M1)/(M1*pi);
end

%plot impulse response

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:

By performing this practical we can conclude that by windowing function


we can plot frequency response for each and every window and we can
compare rolloff factor and passband ripple.
Experiment-14

Aim:To design a FIR lowpass filter using Hamming and Blackman


windows

Program:

clc
clear all

%calculate cutoff frequency and FIR zeroth coefficient

Wc=0.5*pi;
h0=Wc/pi;

%take no of tap and other filter coefficient

N=25;
for M=1:N,
M1=(M-1)-12;
hn(M)=sin(Wc*M1)/(M1*pi);
end

%plot impulse response

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]);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%calculate cutoff frequency and FIR zeroth coefficient

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

%plot impulse response

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:

By performing this practical we can conclude that by windowing function


we can plot frequency response for hamming and Blackman window and
compare their frequency response
Experiment-15

Aim:To plot the frequency response of low pass filter using Kaiser
window for the different value of betta

Program:

clc
clear all

%calculate cutoff frequency and FIR zeroth coefficient

Wc=0.5*pi;
h0=Wc/pi;

%take no of tap and other filter coefficient

N=25;
for M=1:25,
M1=(M-1)-12;
hn(M)=sin(Wc*M1)/(M1*pi);
end

%plot impulse response

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]);

%kaiser window response for B=0.5

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]);

%kaiser window response for B=1

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]);

%kaiser window response for B=2

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:

By performing this practical we can conclude that we get different frequency


response for the different value of betta in case of Kaiser Window.
Experiment-16

Aim:To design FIR low pass filter with cutoff frequency 0.5*pi
using frequency sampling methods

Program:

clc
clear all

N=input('No. of Taps - ');


wc=input('Cutoff freq - ');
M=(N-1)/2;

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:

By performing this practical we can conclude that we get ripple in stopband


and flat passband, so we can design FIR filter using frequency sampling
method.

Vous aimerez peut-être aussi