a.
Design of FIR filter using Rectangular Windows.
% Rectangular Window
clc;
clear all;
rp=input(‘enter the pass band ripple’);
rs= input(‘enter the stop band ripple’);
fp=input(‘enter the pass band frequency’);
fs= input(‘enter the stop band frequency’);
f= input(‘enter the sampling frequency’);
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
n1=n+1;
disp(‘window length:’);
disp(n1);
if(rem(n,2)~=2);
n1=n;
n=n-1;
end
y=boxcar(n1);
disp(‘window coeff’);
disp(y’);
%Lowpass filter
b=fir1(n,wp,y);
[h,omega]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(3,2,1);
plot(omega/pi,m);
xlabel(‘normalized frequency----->’);
ylabel(‘gain in db------>’);
title(‘lowpass filter’);
%Highpass filter
b=fir1(n,wp,’high’,y);
[h,omega]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(3,2,2);
plot(omega/pi,m);
xlabel(‘normalized frequency----->’);
ylabel(‘gain in db------>’);
title(‘highpass filter’);
%Bandpass filter
wn=[wp ws];
b=fir1(n,wp,y);
[h,omega]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(3,2,3);
plot(omega/pi,m);
xlabel(‘normalized frequency----->’);
ylabel(‘gain in db------>’);
title(‘bandpass filter’);
%Bandstop filter
wn=[wp ws];
b=fir1(n,wp,’stop’,y);
[h,omega]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(3,2,4);
plot(omega/pi,m);
xlabel(‘normalized frequency----->’);
ylabel(‘gain in db------>’);
title(‘bandstop filter’);
subplot(3,2,5);
stem(y’);
xlabel(‘n1----->’);
ylabel(‘y(n)------>’);
title(‘rectangular window’);
output :
enter Passband ripple=.02
enter Stopband ripple=.04
enter Passband freq=1500
enter Stopband freq=2000
enter Sampling freq=9000
b.
Design of FIR filter using Hamming Windows.
clc;
clear all;
rp=input(‘enter the pass band ripple’);
rs= input(‘enter the stop band ripple’);
fp=input(‘enter the pass band frequency’);
fs= input(‘enter the stop band frequency’);
f= input(‘enter the sampling frequency’);
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
n1=n+1;
disp(‘window length:’);
disp(n1);
if(rem(n,2)~=2);
n1=n;
n=n-1;
end
y=hamming(n1);
disp(‘window coeff’);
disp(y’);
%Lowpass filter
b=fir1(n,wp,y);
[h,omega]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(3,2,1);
plot(omega/pi,m);
xlabel(‘normalized frequency----->’);
ylabel(‘gain in db------>’);
title(‘lowpass filter’);
%Highpass filter
b=fir1(n,wp,’high’,y);
[h,omega]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(3,2,2);
plot(omega/pi,m);
xlabel(‘normalized frequency----->’);
ylabel(‘gain in db------>’);
title(‘highpass filter’);
%Bandpass filter
wn=[wp ws];
b=fir1(n,wp,y);
[h,omega]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(3,2,3);
plot(omega/pi,m);
xlabel(‘normalized frequency----->’);
ylabel(‘gain in db------>’);
title(‘bandpass filter’);
%Bandstop filter
wn=[wp ws];
b=fir1(n,wp,’stop’,y);
[h,omega]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(3,2,4);
plot(omega/pi,m);
xlabel(‘normalized frequency----->’);
ylabel(‘gain in db------>’);
title(‘bandstop filter’);
subplot(3,2,5);
stem(y’);
xlabel(‘n1----->’);
ylabel(‘y(n)------>’);
title(‘hamming window’);
output :
enter Passband ripple=.02
enter Stopband ripple=.04
enter Passband freq=1500
enter Stopband freq=2000
enter Sampling freq=9000
c.
Design of FIR filter using Hanning Windows.
clc;
clear all;
rp=input(‘enter the pass band ripple’);
rs= input(‘enter the stop band ripple’);
fp=input(‘enter the pass band frequency’);
fs= input(‘enter the stop band frequency’);
f= input(‘enter the sampling frequency’);
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
n1=n+1;
disp(‘window length:’);
disp(n1);
if(rem(n,2)~=2);
n1=n;
n=n-1;
end
y=hanning(n1);
disp(‘window coeff’);
disp(y’);
%Lowpass filter
b=fir1(n,wp,y);
[h,omega]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(3,2,1);
plot(omega/pi,m);
xlabel(‘normalized frequency----->’);
ylabel(‘gain in db------>’);
title(‘lowpass filter’);
%Highpass filter
b=fir1(n,wp,’high’,y);
[h,omega]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(3,2,2);
plot(omega/pi,m);
xlabel(‘normalized frequency----->’);
ylabel(‘gain in db------>’);
title(‘highpass filter’);
%Bandpass filter
wn=[wp ws];
b=fir1(n,wp,y);
[h,omega]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(3,2,3);
plot(omega/pi,m);
xlabel(‘normalized frequency----->’);
ylabel(‘gain in db------>’);
title(‘bandpass filter’);
%Bandstop filter
wn=[wp ws];
b=fir1(n,wp,’stop’,y);
[h,omega]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(3,2,4);
plot(omega/pi,m);
xlabel(‘normalized frequency----->’);
ylabel(‘gain in db------>’);
title(‘bandstop filter’);
subplot(3,2,5);
stem(y’);
xlabel(‘n1----->’);
ylabel(‘y(n)------>’);
title(‘hanning window’);
output :
enter Passband ripple=.02
enter Stopband ripple=.04
enter Passband freq=1500
enter Stopband freq=2000
enter Sampling freq=9000
d.
Design of FIR filter using Kaiser Windows.
% Rectangular Window
clc;
clear all;
rp=input(‘enter the pass band ripple’);
rs= input(‘enter the stop band ripple’);
fp=input(‘enter the pass band frequency’);
fs= input(‘enter the stop band frequency’);
f= input(‘enter the sampling frequency’);
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
n1=n+1;
disp(‘window length:’);
disp(n1);
if(rem(n,2)~=2);
n1=n;
n=n-1;
end
y=boxcar(n1);
disp(‘window coeff’);
disp(y’);
%Lowpass filter
b=fir1(n,wp,y);
[h,omega]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(3,2,1);
plot(omega/pi,m);
xlabel(‘normalized frequency----->’);
ylabel(‘gain in db------>’);
title(‘lowpass filter’);
%Highpass filter
b=fir1(n,wp,’high’,y);
[h,omega]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(3,2,2);
plot(omega/pi,m);
xlabel(‘normalized frequency----->’);
ylabel(‘gain in db------>’);
title(‘highpass filter’);
%Bandpass filter
wn=[wp ws];
b=fir1(n,wp,y);
[h,omega]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(3,2,3);
plot(omega/pi,m);
xlabel(‘normalized frequency----->’);
ylabel(‘gain in db------>’);
title(‘bandpass filter’);
%Bandstop filter
wn=[wp ws];
b=fir1(n,wp,’stop’,y);
[h,omega]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(3,2,4);
plot(omega/pi,m);
xlabel(‘normalized frequency----->’);
ylabel(‘gain in db------>’);
title(‘bandstop filter’);
subplot(3,2,5);
stem(y’);
xlabel(‘n1----->’);
ylabel(‘y(n)------>’);
title(‘kaiser window’);
output :
enter Passband ripple=.02
enter Stopband ripple=.04
enter Passband freq=1500
enter Stopband freq=2000
enter Sampling freq=9000
e.
Design of FIR filter using Blackman Windows.
% Rectangular Window
clc;
clear all;
rp=input(‘enter the pass band ripple’);
rs= input(‘enter the stop band ripple’);
fp=input(‘enter the pass band frequency’);
fs= input(‘enter the stop band frequency’);
f= input(‘enter the sampling frequency’);
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
n1=n+1;
disp(‘window length:’);
disp(n1);
if(rem(n,2)~=2);
n1=n;
n=n-1;
end
y=blackman(n1);
disp(‘window coeff’);
disp(y’);
%Lowpass filter
b=fir1(n,wp,y);
[h,omega]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(3,2,1);
plot(omega/pi,m);
xlabel(‘normalized frequency----->’);
ylabel(‘gain in db------>’);
title(‘lowpass filter’);
%Highpass filter
b=fir1(n,wp,’high’,y);
[h,omega]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(3,2,2);
plot(omega/pi,m);
xlabel(‘normalized frequency----->’);
ylabel(‘gain in db------>’);
title(‘highpass filter’);
%Bandpass filter
wn=[wp ws];
b=fir1(n,wp,y);
[h,omega]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(3,2,3);
plot(omega/pi,m);
xlabel(‘normalized frequency----->’);
ylabel(‘gain in db------>’);
title(‘bandpass filter’);
%Bandstop filter
wn=[wp ws];
b=fir1(n,wp,’stop’,y);
[h,omega]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(3,2,4);
plot(omega/pi,m);
xlabel(‘normalized frequency----->’);
ylabel(‘gain in db------>’);
title(‘bandstop filter’);
subplot(3,2,5);
stem(y’);
xlabel(‘n1----->’);
ylabel(‘y(n)------>’);
title(‘blackman window’);
output :
enter Passband ripple=.02
enter Stopband ripple=.04
enter Passband freq=1500
enter Stopband freq=2000
enter Sampling freq=9000