Sei sulla pagina 1di 12

Digital Signal Processing Lab Manual Experiment No.

5
Experiment No. 5
FIR and IIR Filters Design
In this experiment, you will study the different methods of designing the Finite Impulse
Response (FIR), and Infinite Impulse Response (IIR) Filters.

Introduction:
Filters are a basic component of all signal processing and telecommunication system. A filter
is a device or process that removes some unwanted components or features from a signal.
Filtering is a class of signal processing used to complete or partial suppression of some
aspects of the signal. Most often, this means to remove some frequencies and not others in
order to suppress the interfacing signals and reduce the background noise.

Types of Filters:
In signal processing, the filters can be of four types, i.e. Lowpass Filters, Highpass Filter,
Bandpass Filters, and Bandstop Filters.

Lowpass Filters: An ideal Lowpass filter is the one that allows to pass all frequency
components of a signal below a designated cutoff frequency c, and rejects to pass all
frequency components of a signal above c.
Its frequency response satisfies:

1,
H LP (e j )
0,

0 c

Highpass Filters: An ideal Highpass filter is the one that allows to pass all frequency
components of a signal above a designated cutoff frequency c, and rejects to pass all
frequency components of a signal below c.
Its frequency response satisfies:

0,
H HP (e j )
1,

15

0 c

Digital Signal Processing Lab Manual Experiment No. 5


Bandpass Filters: An ideal Bandpass filter is the one that allows to pass all frequency
components of a signal within a certain range, and rejects to pass all frequency components
of a signal outside of that range.
Its frequency response satisfies:

1,
H BP (e j )
0,

L H
Otherwise

Bandstop Filters: An ideal Bandstop filter is the one that rejects to pass all frequency
components of a signal within a certain range, and allows to pass all frequency components
of a signal outside of that range.
Its frequency response satisfies:

0,
H BS (e j )
1,

L H
Otherwise

Finite Impulse Response (FIR) Filters:


A Finite Impulse Response (FIR) filter is the one filters whose impulse reponse is of finite
duration. The FIR filters do not have the feedback, due to which they are also known as NonRecursive filters. The general difference equation for a FIR filter is:
M 1

y (n) bk x(n k )
k 0

Where "y(n)" is the filter output at discrete time instrances "n", "bk" is the k-th feedforward
tap, or the filter coefficient, and "x(n k)" is the filter input delayed by "k" samples. The ""
denotes summation from k = 0 to k = M -1, where "M" is the number of the feedforward
taps in the FIR filter. Note that the FIR filter output depends only on the previous "M"
inputs. This feature is why the impulse response for a FIR fitler is finite.

Why FIR Filters:


There are many reasons why FIR filters are very attractive for digital filter design. Some of
them are:

15

Simple robust way of obtaining digital fitlers

Inherently stable when implemented non recursively

Free of limit cycles when implemented non recursively

Digital Signal Processing Lab Manual Experiment No. 5

Easy to attain linear phase

Simple extensions to multirate and adaptice fitlers

Relatively straight-forward to obtain designs to match custom magnitude responses

Some vendors and specilized hardware only support FIR

Low sensitivity to quantization effects compared to many IIR filters

FIR filters have some drawbacks however. The most important is that they can be
computationally expensive to implement. Another is that they have a long transient response.
It is commonly thought that IIR fitlers must be used when computational power is at the
premium. This is certainly true is some case. However, in many cases, the use of multistage
or multirate techniques can yield FIR implementations that can compete (and even surpass)
IIR implementations while retaining the nice charachteristics of FIR filters such as linearphase, stability, and robutness to quantization effects. However, these efficient multistage or
multirate designs tend to have very large transient responses, so depending on the
requirements of the filter, IIR design may still be the way to go.

15

Digital Signal Processing Lab Manual Experiment No. 5


FIR Lowpass Filter Using fir1() Function:
%Program:
EXP5_FIR_Lowpass
%A MATLAB program to design FIR Lowpass Filter using MATLAB
%function fir1().
clf;
clear all;
close all;

%Clear all figures


%Clear all variables
%Close all figures

N = 512;
O = 64;
%Define the order of the filter
fc = input('Enter the cutoff frequency');
fs = input('Enter the sampling frequency');
Wc=2*fc/fs;
%Normalizing the frequencies
b=fir1(O,Wc,'low');
%Calculation of filter coefficients
freqz(b,1,N,fs);
%Plotting the filter response
TITLE('Magnitude and Phase Response of FIR Lowpass Filter');
The Output is:
Enter the cutoff frequency1200
Enter the sampling frequency3000
Magnitude and Phase Response of FIR Lowpass Filter

Magnitude (dB)

50
0
-50
-100
-150

500

1000

1500

1000

1500

Frequency (Hz)

Phase (degrees)

-2000

-4000

-6000

500
Frequency (Hz)

15

Digital Signal Processing Lab Manual Experiment No. 5


FIR Highpass Filter Using fir1() Function:
%Program:
EXP5_FIR_Highpass
%A MATLAB program to design FIR Highpass Filter using MATLAB
%function fir1().
clf;
clear all;
close all;

%Clear all figures


%Clear all variables
%Close all figures

N = 512;
O = 64;
%Define the order of the filter
fc = input('Enter the cutoff frequency');
fs = input('Enter the sampling frequency');
Wc=2*fc/fs;
%Normalizing the frequencies
b=fir1(O,Wc,'high');
%Calculation of filter coefficients
freqz(b,1,N,fs);
%Plotting the filter response
TITLE('Magnitude and Phase Response of FIR Highpass Filter');
The Output is:
Enter the cutoff frequency1000
Enter the sampling frequency3000
Magnitude and Phase Response of FIR Highpass Filter

Magnitude (dB)

50
0
-50
-100
-150

500

1000

1500

1000

1500

Frequency (Hz)

Phase (degrees)

1000
0
-1000
-2000
-3000

500
Frequency (Hz)

11

Digital Signal Processing Lab Manual Experiment No. 5


FIR Bandpass Filter Using fir1() Function:
%Program:
EXP5_FIR_Bandpass
%A MATLAB program to design FIR Bandpass Filter using MATLAB
%function fir1().
clf;
clear all;
close all;

%Clear all figures


%Clear all variables
%Close all figures

N = 512;
O = 64;

%Define the order of the filter

fn = input('Enter the passband range of frequencies');


fs = input('Enter the sampling frequency');
Wn=2*fn/fs;
%Normalizing the frequencies
b=fir1(O,Wn);
%Calculation of filter coefficients
freqz(b,1,N,fs);
%Plotting the filter response
TITLE('Magnitude and Phase Response of Bandpass Filter');
The Output is:
Enter the lower passband range of frequencies[300 600]
Enter the sampling frequency1500
Magnitude and Phase Response of Bandpass Filter

Magnitude (dB)

50
0
-50
-100
-150

100

200

300
400
Frequency (Hz)

500

600

700

100

200

300
400
Frequency (Hz)

500

600

700

Phase (degrees)

1000
0
-1000
-2000
-3000

15

Digital Signal Processing Lab Manual Experiment No. 5


FIR Bandstop Filter Using fir1() Function:
%Program:
EXP5_FIR_Bandstop
%A MATLAB program to design FIR Bandstop Filter using MATLAB
%function fir1().
clf;
clear all;
close all;

%Clear all figures


%Clear all variables
%Close all figures

N = 512;
O = 64;

%Define the order of the filter

fn = input('Enter the stopband range of frequencies');


fs = input('Enter the sampling frequency');
Wn=2*fn/fs;
%Normalizing the frequencies
b=fir1(O,Wn,'stop');
%Calculation of filter coefficients
freqz(b,1,N,fs);
%Plotting the filter response
TITLE('Magnitude and Phase response');
The Output is:
Enter the stopband range of frequencies[500 1000]
Enter the sampling frequency3000
Magnitude and Phase response

Magnitude (dB)

50

-50

-100

500

1000

1500

1000

1500

Frequency (Hz)

Phase (degrees)

-2000

-4000

-6000

500
Frequency (Hz)

15

Digital Signal Processing Lab Manual Experiment No. 5


Infinite Impulse Response (IIR) Filters:
Another type of filter is the Infinite Impulse Response (IIR) filter and the Impulse Response
of an IIR filter is of infinite duration. The IIR filters have the feedback, due to which they are
also known as Recursive filters. The general difference for an IIR filter is:
N 1

M 1

k 1

k 0

y (n) ak y (n k ) bk x(n k )
Where "ak" is the k-th feedback tap. The left "" denoted the summation from k =1 to k =N-1,
"N" is the number of the feedback taps in the IIR filter. The right "" denotes the summation
from k = 0 to k = M 1, where "M" is the number of feedforward taps.

Why IIR Filters:


IIR filters are usaully used when computational resources are at a premium. However, stable,
causal IIR fitlers cannot have perfectly linear phase, so that IIR filters tend to be avoided
when linearity of phase is a requirement. Also, computational savings that are comparable to
using IIR fitlers can be achieved for certain design paratmeters by using mulitstage or
multirate FIR filter designs. These designs have the advantage of having linear-phase
capability, robustness to quantization, stability, and good pipeline-ability.
Another important reason to use IIR filters is their relatively small group delay compared to
FIR fitlers. This results in a shorter transient response to imput stimuli. Even if we are able to
match or surpass the implementation cost of an IIR filter by using multirate or multistage FIR
designs, the transient response of such FIR designs tends to be much larger than that of a
comparable IIR design. However, minimum-phase FIR design can have group delays that are
comparable or even lower than IIR fitlers that meet the same specifications.

15

Digital Signal Processing Lab Manual Experiment No. 5


IIR Butterworth Lowpass Filter:
%Program:
EXP5_IIR_Butterworth_Lowpass
%A MATLAB program to design IIR Butterworth Lowpass Filter
clf;
clear all;
close all;

%Clear all figures


%Clear all variables
%Close all figures

N = 512;
n = 6;

%Define the order of the filter

fc = input('Enter the cutoff frequency');


fs = input('Enter the sampling frequency');
Wc = 2 * fc / fs;
[b,a]=butter(n,Wc,'low');
freqz(b,a,N,fs);
TITLE('Magnitude and Phase
filter');

%Normalizing the frequencies


%Calculation of filter coefficients
%Plotting the filter response
response of Butterworth IIR Lowpass

The Output is:


Enter the cutoff frequency1200
Enter the sampling frequency3000
Magnitude and Phase Response of Butterworth IIR Lowpass Filter

Magnitude (dB)

-100

-200

-300

500

1000

1500

1000

1500

Frequency (Hz)

Phase (degrees)

-200

-400

-600

500
Frequency (Hz)

15

Digital Signal Processing Lab Manual Experiment No. 5


IIR Chebyshev-Type-1 Lowpass Filter:
%Program:
EXP5_IIR_Chebyshev_Type_1_Lowpass
%A MATLAB program to design IIR Butterworth Lowpass Filter
clf;
clear all;
close all;
N = 512;
n = 6;
R = 0.5;

%Clear all figures


%Clear all variables
%Close all figures
%Define the order of the filter
%Define the Passband peak-to-peak ripple in decibels

fc = input('Enter the cutoff frequency');


fs = input('Enter the sampling frequency');
Wc = 2 * fc / fs;
%Normalizing the frequencies
[b,a]=cheby1(n,rp,Wc,'low'); %Calculating filter coefficients
freqz(b,a,N,fs);
%Plotting the filter response
TITLE('Magnitude and Phase Response of Chebyshev-Type-1 IIR
Lowpass Filter');
The Output is:
Enter the cutoff frequency1200
Enter the sampling frequency3000
Magnitude and Phase Response of Chebyshev-Type-1 IIR Lowpass Filter

Magnitude (dB)

-100

-200

-300

500

1000

1500

1000

1500

Frequency (Hz)

Phase (degrees)

-200

-400

-600

500
Frequency (Hz)

56

Digital Signal Processing Lab Manual Experiment No. 5


IIR Chebyshev-Type-2 Lowpass Filter:
%Program:
EXP5_IIR_Chebyshev_Type_2_Lowpass
%A MATLAB program to design IIR Butterworth Lowpass Filter
clf;
clear all;
close all;

%Clear all figures


%Clear all variables
%Close all figures

N = 512;
n = 6;
R = 20;

%Define the order of the filter


%Stopband ripple in decibles

fc = input('Enter the cutoff frequency');


fs = input('Enter the sampling frequency');
Wc = 2 * fc / fs;
%Normalizing the frequencies
[b,a]=cheby2(n,R,Wc,'low');%Calculation of filter coefficients
freqz(b,a,N,fs);
%Plotting the filter response
TITLE('Magnitude and Phase Response of Chebyshev-Type-2 IIR
Lowpass Filter');
The Output is:
Enter the cutoff frequency1200
Enter the sampling frequency3000
Magnitude and Phase Response of Chebyshev-Type-2 IIR Lowpass Filter

Magnitude (dB)

-20

-40

-60

500

1000

1500

1000

1500

Frequency (Hz)

Phase (degrees)

100
0
-100
-200
-300

500
Frequency (Hz)

55

Digital Signal Processing Lab Manual Experiment No. 5


Exercises
5.1.

Write a MATLAB program to design a Highpass IIR filter using Butterworth,


Chebychev Type_1, and Chebychev Type_2 methods. Use your own values. Compare
the Magnitude and Phase Response of the three by ploting them on the same plot.

5.2.

Write a MATLAB program to design a Bandpass IIR filter using Butterworth,


Chebychev Type_1, and Chebychev Type_2 methods. Use your own values. Compare
the Magnitude and Phase Response of the three by ploting them on the same plot.

5.3.

Write a MATLAB program to design a Highstop IIR filter using Butterworth,


Chebychev Type_1, and Chebychev Type_2 methods. Use your own values. Compare
the Magnitude and Phase Response of the three by ploting them on the same plot.

55

Potrebbero piacerti anche