100% found this document useful (1 vote)
221 views

To Design and Implement An FIR Filter For Given Specifications

The document describes three methods for designing and implementing FIR filters. Method 1 designs a lowpass FIR filter with given cutoff frequency and order using a Hamming window. Method 2 designs a lowpass FIR filter with user specified order, sampling frequency, and passband edge frequency using a Hamming window. Method 3 designs an FIR filter where the user specifies the passband, stopband frequencies, and sampling frequency.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
221 views

To Design and Implement An FIR Filter For Given Specifications

The document describes three methods for designing and implementing FIR filters. Method 1 designs a lowpass FIR filter with given cutoff frequency and order using a Hamming window. Method 2 designs a lowpass FIR filter with user specified order, sampling frequency, and passband edge frequency using a Hamming window. Method 3 designs an FIR filter where the user specifies the passband, stopband frequencies, and sampling frequency.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

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

Program 1: Design and implementation of FIR filter

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

% Design of FIR Low pass filter using Hamming window sequence


clc;
clear all;
close all;
fpb= input('Enter passband edge frequency in Hz=');
fsb= input('Enter stopband edge frequency in Hz=');
fsp= input('Enter sampling frequency in Hz=');
%Calculate transition band ‘tb’ and order ‘N’ of the filter
wpb=2*pi*fpb/fsp; %conversion to radians

3
wsb=2*pi*fsb/fsp;
tb=wsb-wpb; %transition width
N=ceil(6.6*pi/tb) %order calculation(rounded off)

N = 34

wc=(wsb+wpb)/2; % cut-off frequency


%compute the normalized cut off frequency
wc=wc/pi;
%calculate & plot the window sequence
subplot(1,2,1)
hw=hamming(N+1);
stem(hw);
title('Hamming window sequence');
%find h(n)
h=fir1(N,wc,hamming(N+1));
%plot the frequency response
subplot(1,2,2)
[m,w]=freqz(h,1,128);
mag=20*log10(abs(m));
plot(fsp*w/(2*pi),mag); %conversion to frequency
title('FIR low pass filter frequency response');
grid;

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.

% BPF FIR filter implementation using Bartlett window sequence


close all;
clear all;
clc;
N=31;
Fs=8000; % sampling frequency
fc1=2000; %cut-off frequencies
fc2=3000;
Wc1=2*fc1/Fs; %Normalizing
Wc2=2*fc2/Fs;
Wc=[Wc1 Wc2];
if(rem(N,2)==0) %adjustment of the order
M=N+1;
else
M=N;
N=N-1;
end
b =fir1(N,Wc,'bandpass',bartlett(N+1));
[h,w]=freqz(b); %returns the N-point frequency response vector h and
%N point frequency vector w in rad/sample
rw = bartlett(N+1); % Bartlett window sequence
subplot(3,1,1);
stem(rw);
xlabel('n');
ylabel('amplitude');
title('Bartlett window sequence');
grid on;
subplot(3,1,2);
freq=w*Fs/(2*pi); % conversion to Hz 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);
plot(w,angle(h));
xlabel('Frequency');
ylabel('phase');
title('phase response');
grid on;

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

You might also like