Google Search

Wednesday, December 7, 2011

DSP PROGRAM To design FIR filters using windows technique


AIM: - To design FIR filters using windows technique

PROGRAM: -
%Program for the design of FIR low pass, high pass, band pass, band stop using
%rectangular window
clc;
clear all;
close all;
rp=input('enter the passband ripple');
rs=input('enter the stopband ripple');
fp=input('enter the passband freq');
fs=input('enter the stopband freq');
f=input('enter the sampling freq');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n1=n+1;
if (rem(n,2)~=0)
    n1=n;
    n=n-1;
end
y=boxcar(n1);
%low pass filter
b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1);
plot(o/pi,m);
ylabel('Gain in db-->');
xlabel('(a) Normalised frequency-->');
%high pass filter
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2);
plot(o/pi,m);
ylabel('Gain in db-->');
xlabel('(b) Normalised frequency-->');
%band pass filter
wn=[wp ws];
b=fir1(n,wn,y);
[h,o]=freqz(b,1,256);
                              m=20*log10(abs(h));
subplot(2,2,3);
plot(o/pi,m);
ylabel('Gain in db-->');
xlabel('(c) Normalised frequency-->');
%band stop filter
b=fir1(n,wn,'stop',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4);
plot(o/pi,m);
ylabel('Gain in db-->');
xlabel('(d) Normalised frequency-->');

Output: -

enter the passband ripple0.04
enter the stopband ripple0.02
enter the passband freq1500
enter the stopband freq2000
enter the sampling freq9000






















0 comments:

Post a Comment