Tuesday, 4 March 2014

FIR Low Pass Filter using Kaiser Window

Program:

clc;
clear all;
close all;
fp=input('enter passband frequency');
fs=input('enter stopband frequency');
f=input('enter sampling frequency');
rp=input('enter passband ripple');
rs=input('enter stopband ripple');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13.0;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
n1=n+1;
%to make order of filter even
if(rem(n,2)~=0)
 n1=n;
 n=n-1;
end
y=kaiser(n1);
b=fir1(n,wp,y);
[h,w]=freqz(b,1,256);
mag=20*log10(abs(h));
ang=angle(h);
subplot(2,1,1);
plot(w/pi,mag);
xlabel('normalised freq');
ylabel('gain(in db)');
subplot(2,1,2);
plot(w/pi,ang);
title('phase response');
xlabel('normalised frequency');
ylabel('phase angle');

Output:

enter passband frequency1500
enter stopband frequency2000
enter sampling frequency9000
enter passband ripple0.04
enter stopband ripple0.05



FIR Filter HIgh Pass using Kaiser Window

Program:

clc;
clear all;
close all;
fp=input('enter passband frequency');
fs=input('enter stopband frequency');
f=input('enter sampling frequency');
rp=input('enter passband ripple');
rs=input('enter stopband ripple');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13.0;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
n1=n+1;
%to make order of filter even
if(rem(n,2)~=0)
 n1=n;
 n=n-1;
end
y=kaiser(n1);
b=fir1(n,wp,'high',y);
[h,w]=freqz(b,1,256);
mag=20*log10(abs(h));
ang=angle(h);
subplot(2,1,1);
plot(w/pi,mag);
xlabel('normalised freq');
ylabel('gain(in db)');
subplot(2,1,2);
plot(w/pi,ang);
title('phase response');
xlabel('normalised frequency');
ylabel('phase angle');

Output:
enter passband frequency1500
enter stopband frequency2000
enter sampling frequency9000
enter passband ripple0.04
enter stopband ripple0.05


FIR Filter High Pass FIlter Triangular Window

clc;
clear all;
close all;
fp=input('enter passband frequency');
fs=input('enter stopband frequency');
f=input('enter sampling frequency');
rp=input('enter passband ripple');
rs=input('enter stopband ripple');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13.0;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
n1=n+1;
%to make order of filter even
if(rem(n,2)~=0)
 n1=n;
 n=n-1;
end
y=triang(n1);
b=fir1(n,wp,'high',y);
[h,w]=freqz(b,1,256);
mag=20*log10(abs(h));
ang=angle(h);
subplot(2,1,1);
plot(w/pi,mag);
xlabel('normalised freq');
ylabel('gain(in db)');
subplot(2,1,2);
plot(w/pi,ang);
title('phase response');
xlabel('normalised frequency');
ylabel('phase angle');

OUTPUT:
enter passband frequency1500
enter stopband frequency2000
enter sampling frequency9000
enter passband ripple0.04
enter stopband ripple0.05


FIR filter with Triangular Window Low Pass

PROGRAM:
clc;
clear all;
close all;
fp=input('enter passband frequency');
fs=input('enter stopband frequency');
f=input('enter sampling frequency');
rp=input('enter passband ripple');
rs=input('enter stopband ripple');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13.0;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
n1=n+1;
%to make order of filter even
if(rem(n,2)~=0)
 n1=n;
 n=n-1;
end
y=triang(n1);
b=fir1(n,wp,y);
[h,w]=freqz(b,1,256);
mag=20*log10(abs(h));
ang=angle(h);
subplot(2,1,1);
plot(w/pi,mag);
xlabel('normalised freq');
ylabel('gain(in db)');
subplot(2,1,2);
plot(w/pi,ang);
title('phase response');
xlabel('normalised frequency');
ylabel('phase angle');

OUTPUT:

enter passband frequency1500
enter stopband frequency2000
enter sampling frequency9000
enter passband ripple0.05
enter stopband ripple0.04