Saturday 17 September 2011

FIR filter


FIR FILTER USING RECTANGULAR WINDOW
 clc;close all;clear all;
rp=input('enter the passband ripple');
rs=input('enter the stopband ripple');
fp=input('enter the passband ripple');
fs=input('enter the stopband ripple');
f=input('enter the sampling frequency');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rs*rp))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
if(rem(n,2)~=0)
    n=n1;
    n=n-1;
end
y=RECTWIN(n1);
%bandpass filter
wn=[wp ws];
b=fir1(n,wn,y);
[h,o]=freqz(b,1,256);
m=20*log10*(abs(h));
an=angle(h);
subplot(2,1,1);
plot(o/pi,m);
xlabel('normalised freq-->');
ylabel('gain in db-->');
subplot(2,1,2);
plot(0/pi,an);
xlabel('normalised freq-->');
ylabel('phase in radians-->');

0 comments:

Post a Comment