Pages

Friday 26 April 2013

FIR Filters Using Kaiser Window (Matlab 2012a)

Program:

clc;
clear all;
rp = input('Enter the passband ripple = ');
rs = input('Enter the stopband ripple = ');
fp = input('Enter the passband frequency = ');
fs = input('Enter the stopband frequency = ');
f = input('Enter the sampling frequency = ');
beta = input('Enter the beta value = ');
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 = kaiser(n1,beta);
% 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);
title('Magnitude Response of LPF');
ylabel('Gain in dB ---->');
xlabel('Normalised Frequency ---->');
grid on;
% 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);
title('Magnitude Response of HPF');
ylabel('Gain in dB ---->');
xlabel('Normalised Frequency ---->');
grid on;
% 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);
title('Magnitude Response of BPF');
ylabel('Gain in dB ---->');
xlabel('Normalised Frequency ---->');
grid on;
% 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);
title('Magnitude Response of BSF');
ylabel('Gain in dB ---->');
xlabel('Normalised Frequency ---->');
grid on;


Output:

Enter the passband ripple = 0.02
Enter the stopband ripple = 0.01
Enter the passband frequency = 1000
Enter the stopband frequency = 1500
Enter the sampling frequency = 10000
Enter the beta value = 5.8


Waveform:

 

2 comments:

  1. how can we get num = -20*log10(sqrt(rp*rs))-13;
    dem = 14.6*(fs-fp)/f; frm kaiser formula

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete