To Design and Implement An FIR Filter For Given Specifications
To Design and Implement An FIR Filter For Given Specifications
To Design and Implement An FIR Filter For Given Specifications
Theory:
Finite Impulse Response (FIR) Filter: The FIR filters are of non-recursive type, whereby the present output
sample is depending on the present input sample and previous input samples. The transfer function of a FIR
causal filter is given by,
H(z)=
Where h(n) is the impulse response of the filter. The Fourier transform of h(n) is,
H( )=
Method 1
Generate filter coefficients for the given order & cutoff say N=33, fc=150Hz, %fs=1000 Hz, obtain the frequency
response of a low pass filter using Hamming window
clc;
clear all;
close all;
ws1= input('Enter sampling frequency in Hz=');
h=fir1(33, 150/(ws1/2),hamming(34));
%plot the frequency response
[m,w]=freqz(h,1,128);
mag=20*log10(abs(m));
plot(ws1*w/(2*pi),mag);
title('FIR filter frequency response');
grid;
1
Method 2:
Given the order N=34, sampling frequency=2000Hz, passband edge %frequency=200Hz obtain the frequency
response of an FIR LPF using Hamming window
close all;
clear all;
clc;
N=34;
Fs=2000;
fp=200;
wc=2*pi*fp/Fs; %conversion to radians
if(rem(N,2)==0) %adjustment of the order
M=N+1;
else
M=N;
N=N-1;
end
Wc=wc/pi; % normalizing between 0and 1
b = fir1(N,Wc,hamming(N+1)); % computes the filter coefficients
[h,w]=freqz(b); % digital filter frequency response
rw=hamming(N+1); % plot hamming window sequence
subplot(3,1,1);
stem(rw);
xlabel('n');
ylabel('amplitude');
title('Hamming window sequence');
2
grid on;
subplot(3,1,2);
freq=w*Fs/(2*pi); % conversion to frequency from radians
m=20*log10(abs(h));
plot(freq,m);
xlabel('Frequency');
ylabel('magnitude in dB');
title('magnitude response');
grid on;
subplot(3,1,3); % phase angle plot
plot(w,angle(h));
xlabel('Frequency');
ylabel('phase');
title('phase response');
Method 3:
User input data to be given: passband frequency, stopband frequency and sampling frequency
3
wsb=2*pi*fsb/fsp;
tb=wsb-wpb; %transition width
N=ceil(6.6*pi/tb) %order calculation(rounded off)
N = 34
Method 1:
4
Design a Bandpass FIR filter using Bartlett window with cutoff frequencies as 2000Hz and 3000Hz, sampling
frequency as 8000Hz and order N=31.
5
Method 2:
Design a bandpass FIR filter using Hamming window with the following specifications. rp = 3dB, rs = 25dB, fp =
1500Hz ≤f ≤ 3000Hz, fs = 0 ≤ f ≤ 800Hz & 3400 ≤ f ≤ ∞, Fs = 8000Hz.
clear all;
close all;
clc;
rp = 3;
rs = 25;
fp1 = 1500; %passband edge frequencies
fp2 = 3000;
fs1 = 800; % stopband edge frequencies
fs2 = 3400;
Fs = 8000; % sampling frequency
% frequencies in radians
wp1=2*pi*fp1/Fs;
wp2=2*pi*fp2/Fs;
ws1=2*pi*fs1/Fs;
ws2=2*pi*fs2/Fs;
tb = min((wp1-ws1),(ws2-wp2)); %transition width
wc1=(wp1+ws1)/2;
wc2=(wp2+ws2)/2;
wc = [wc1 wc2];
Wc = [wc1/pi wc2/pi];
N=ceil(6.6*pi/tb)-1; %computation of orderto adjust the order
if(rem(N,2)==0)
6
M=N+1;
else
M = N;
N=N-1;
end
b =fir1(N,Wc,'bandpass',hamming(N+1)); %filter coefficients
[h,w]=freqz(b);
hw = hamming(N+1); % hamming window sequence
subplot(311);
stem(hw);
xlabel('n');
ylabel('amplitude');
title('hamming window sequence');
grid on;
subplot(312);
freq=w*Fs/(2*pi); % conversion to frequency from radians
m=20*log10(abs(h));
plot(freq,m); %magnitude plot
xlabel('Frequency');
ylabel('magnitude in dB');
title('magnitude response');
grid on;
subplot(313);
plot(w,angle(h)); % phase plot
xlabel('Frequency');
ylabel('phase');
title('phase response');
grid on;
7
Inference:
FIR filter of given specification is designed and implemented