Popular window coefficients.
- hann() - for hanning window
- hamming() - for hamming window
- blackman() - for blackman window
- kaiser() - for kaiser window
% Program to design a FIR filter using windows.
close all;
clear all;
fp=input('Enter the pass band frequency');
fs=input('Enter the stop band frequency');
rp=input(' Enter the pass band attenuation');
rs=input('Enter the stop band attenuation');
f=input(' Enter the sampling frequency');
%Calculating filter order
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n=abs(n);
% Normalizing the frequencies
wp=2*fp/f;
ws=2*fs/f;
wn=(ws+wp)/2;
%Adjusting the filter order. The order of window must be an odd number
%and the order of filter must be one less than that of the window
if (rem(n,2)==0)
m=n+1;
else
m=n;
n=n-1;
end
%Window sequence calculation
w=hann(m);
%Calculation of filter coefficients
b=fir1(n,wn,'low',w);
%Plotting the filter response
freqz(b,1,500,3000);
TITLE('Magnitude and Phase response');
Output:
%output
%Enter the pass band frequency1000
%Enter the stop band frequency1200
%Enter the pass band attenuation.2
%Enter the stop band attenuation45
%Enter the sampling frequency3000
You can change this lowpass filter to high pass filter by changing the option 'low' to
'high' in the fir1() function. The output is shown below.
%output
%Enter the pass band frequency1200
%Enter the stop band frequency1000
%Enter the pass band attenuation.2
%Enter the stop band attenuation45
%Enter the sampling frequency3000
No comments:
Post a Comment