DEPT.
OF ECE, MRCET DSP LAB MANUAL
CONTENTS
[Link] Experiment Name Page No.
PART A - LIST OF EXPERIMENTS USING MATLAB
Introduction to MATLAB
1. To find DFT / IDFT of given DT signal 4
2. Program to obtain Linear Convolution of two finite length sequences 8
3. Program for Computing auto correlation 12
4. To find frequency response of a given system(transfer function/
difference equation) 15
5. Implementation of FFT of given sequence 18
6. Determination of Power Spectrum of a given signal. 21
7. Implementation of LP FIR filter for a given sequence 24
8. Implementation of HP FIR filter for a given sequence 30
9. Implementation of LP IIR filter for a given sequence 32
10. Implementation of HP IIR filter for a given sequence 37
11. Generation of Sinusoidal signal through filtering 41
12. Generation of DTMF signals 44
13. Implementation of Decimation Process 49
14. Implementation of Interpolation Process 52
15. Implementation of I/D sampling rate converters 55
16. Impulse Response of First Order and Second Order Systems 59
PART B - LIST OF EXPERIMENTS USING DSP PROCESSOR
Architecture and Instruction Set of DSPCHIP- TMS320C5515
Introduction to Code Composer Studio
1. Computation of N- Point DFT of a Given Sequence 71
2. Implementation of FFT of Given Sequence 75
3. Power Spectrum 81
4. Implementation of LP FIR Filter for Given Sequence &
Implementation of HP FIR Filter for Given Sequence 84
5. Implementation of LP IIR Filter for Given Sequence &
Implementation of HP IIR Filter for Given Sequence 94
6. Generation of Sinusoidal Signal Through Filtering 101
7. Generation of DTMF Signals 103
8. Implementation of Decimation Process 105
9. Implementation of Interpolation Process 107
10. Impulse Response of First Order and Second Order Systems 110
11. Audio Applications 114
12. Noise removal: Add noise above 3kHz and then remove ; Interference
Suppression using 400 Hz Tone 123
-1-
DEPT. OF ECE, MRCET DSP LAB MANUAL
PART A - LIST OF EXPERIMENTS USING MATLAB
INTRODUCTION TO MATLAB
MATLAB (MATrix LABoratory):
MATLAB is a software package for high-performance language for technical
computing. It integrates computation, visualization, and programming in an easy-to-use
environment where problems and solutions are expressed in familiar mathematical
notation. Typical uses include the following
Math and computation
Algorithm development
Data acquisition
Modeling, simulation, and prototyping
Data analysis, exploration, and visualization
Scientific and engineering graphics
Application development, including graphical user interface building
The name MATLAB stands for matrix laboratory. MATLAB was originally written
to provide easy access to matrix software developed by the LINPACK and EISPACK
projects. Today, MATLAB engines incorporate the LAPACK and BLAS libraries,
embedding the state of the art in software for matrix computation.
MATLAB has evolved over a period of years with input from many users. In
university environments, it is the standard instructional tool for introductory and
advanced courses in mathematics, engineering, and science. In industry, MATLAB is the
tool of choice for high-productivity research, development, and analysis.
MATLAB features a family of add-on application-specific solutions called
toolboxes. Very important to most users of MATLAB, toolboxes allow learning and
applying specialized technology. Toolboxes are comprehensive collections of MATLAB
functions (M-files) that extend the MATLAB environment to solve particular classes of
problems. Areas in which toolboxes are available include Image processing, signal
processing, control systems, neural networks, fuzzy logic, wavelets, simulation, and many
others.
-2-
DEPT. OF ECE, MRCET DSP LAB MANUAL
The main features of MATLAB
1. Advance algorithm for high performance numerical computation ,especially in the
Field matrix algebra
2. A large collection of predefined mathematical functions and the ability to define
one’s own functions.
3. Two-and three dimensional graphics for plotting and displaying data
4. A complete online help system
5. Powerful, matrix or vector oriented high level programming language for individual
applications.
6. Toolboxes available for solving advanced problems in several application areas
-3-
DEPT. OF ECE, MRCET DSP LAB MANUAL
[Link]: 1
TO FIND DFT / IDFT OF GIVEN DT SIGNAL
AIM: To find Discrete Fourier Transform and Inverse Discrete Fourier Transform of
given digital signal.
Software: MATLAB
THEORY:
Basic equation to find the DFT of a sequence is given below.
Basic equation to find the IDFT of a sequence is given below.
Algorithm:
Step I: Get the input sequence.
Step II: Find the DFT of the input sequence using direct equation of DFT.
Step III: Find the IDFT using the direct equation.
Step IV: Plot DFT and IDFT of the given sequence using matlab command stem.
Step V: Display the above outputs.
-4-
DEPT. OF ECE, MRCET DSP LAB MANUAL
Flow chart:
PROGRAM:
clc;
close all;
clear all;
xn=input('Enter the sequence x(n)'); %Get the sequence from user
ln=length(xn); %find the length of the sequence
xk=zeros(1,ln); %initialize an array of same size as that of input sequence
ixk=zeros(1,ln); %initialize an array of same size as that of input sequence
%DFT of the sequence
%-----------------------------------------------------
for k=0:ln-1
for n=0:ln-1
xk(k+1)=xk(k+1)+(xn(n+1)*exp((i)*2*pi*k*n/ln));
end
end
%------------------------------------------------------
%Plotting input sequence
%-----------------------------------------------------
t=0:ln-1;
subplot(221);
stem(t,xn);
ylabel ('Amplitude');
xlabel ('Time Index');
title('Input Sequence');
%---------------------------------------------------------------
-5-
DEPT. OF ECE, MRCET DSP LAB MANUAL
magnitude=abs(xk); % Find the magnitudes of individual DFT points
% plot the magnitude response
%------------------------------------------------------------
t=0:ln-1;
subplot(222);
stem(t,magnitude);
ylabel ('Amplitude');
xlabel ('K');
title('Magnitude Response');
%------------------------------------------------------------
phase=angle(xk); % Find the phases of individual DFT points % plot the magnitude
sequence
%------------------------------------------------------------
t=0:ln-1;
subplot(223);
stem(t,phase);
ylabel ('Phase');
xlabel ('K');
title ('Phase Response');
%------------------------------------------------------------
%IDFT of the sequence
%------------------------------------------------------------
for n=0:ln-1
for k=0:ln-1
ixk(n+1)=ixk(n+1)+(xk(k+1)*exp(i*2*pi*k*n/ln));
end
end
ixk=ixk./ln;
%------------------------------------------------------------
%code block to plot the input sequence
%------------------------------------------------------------
t=0:ln-1;
subplot(224);
stem(t,ixk);
ylabel ('Amplitude');
xlabel ('Time Index');
title ('IDFT sequence');
%------------------------------------------------------
Output:
Xn=[1 2 3 4 5]
Xk = 15,-2.50+3.44i,-2.50+0.81i,-2.49-0.81i,-2.49-3.44i
-6-
DEPT. OF ECE, MRCET DSP LAB MANUAL
Output Waveforms:
RESULT:
VIVA QUESTIONS:
1. Define signal, Give Examples for 1-D, 2-D, 3-D signals.
2. Define transform. What is the need for transform?
3. Differentiate Fourier transform and discrete Fourier transform.
4. Differentiate DFT and DTFT
5. Explain mathematical formula for calculation of DFT.
6. Explain mathematical formula for calculation of IDFT.
7. How to calculate FT for 1-D signal?
8. What is meant by magnitude plot, phase plot, power spectrum?
9. Explain the applications of DFT.
10. What are separable transforms?
Exercise:
1. Find 8-point DFT of the sequence x (n) = [1 2 3 4 4 3 2 1]
-7-
DEPT. OF ECE, MRCET DSP LAB MANUAL
[Link]: 2
LINEAR CONVOLUTION OF TWO SEQUENCES
AIM: To obtain Linear Convolution of two finite length sequences
Software: MATLAB
THEORY:
Convolution is a mathematical operation used to express the relation between
input and output of an LTI system. It relates input, output and impulse response of an
LTI system as
y(n)=x(n)∗h(n)
Where y (n) = output of LTI
x (n) = input of LTI
h (n) = impulse response of LTI
Discrete Convolution
y(n)=x(n)∗h(n)
By using convolution we can find zero state response of the system.
Algorithm:
Step I: Give input sequence x[n].
Step II: Give impulse response sequence h(n)
Step III: Find the convolution y[n] using the matlab command conv.
Step IV: Plot x[n],h[n],y[n].
-8-
DEPT. OF ECE, MRCET DSP LAB MANUAL
PROGRAM:
clc;
clear all;
close all;
x1=input('Enter the first sequence x1(n) = ');
x2=input('Enter the second sequence x2(n) = ');
L=length(x1);
M=length(x2);
N=L+M-1;
yn=conv(x1,x2);
disp(‘The values of yn are= ‘);
disp(yn);
n1=0:L-1;
subplot(311);
stem(n1,x1);
grid on;
xlabel('n1--->');
ylabel('amplitude--->');
title('First sequence');
n2=0:M-1;
subplot(312);
stem(n2,x2);
grid on;
xlabel('n2--->');
ylabel('amplitude--->');
-9-
DEPT. OF ECE, MRCET DSP LAB MANUAL
title('Second sequence');
n3=0:N-1;
subplot(313);
stem(n3,yn);
grid on;
xlabel('n3--->');
ylabel('amplitude--->');
title('Convolved output');
Output:
Enter the first sequence x1(n) = [1 2 3 4 5]
Enter the second sequence x2(n) = [5 8 3 5 4 6]
The values of yn are=
5 18 34 55 80 81 59 59 44 30
OUTPUT WAVEFORMS:
RESULT:
- 10 -
DEPT. OF ECE, MRCET DSP LAB MANUAL
VIVA QUESTIONS:
1. Explain the significance of convolution.
2. Define linear convolution.
3. Why linear convolution is called as a periodic convolution?
4. Why zero padding is used in linear convolution?
5. What are the four steps to find linear convolution?
6. What is the length of the resultant sequence in linear convolution?
7. How linear convolution will be used in calculation of LTI system response?
8. List few applications of linear convolution in LTI system design.
9. Give the properties of linear convolution.
10. How the linear convolution will be used to calculate the DFT of a signal?
Exercise:
1. Find the linear convolution of x(n)=[7 5 4 0] and h(n)=[0 3 6 2 9]
- 11 -
DEPT. OF ECE, MRCET DSP LAB MANUAL
[Link]: 3
AUTO CORRELATION
AIM: To compute auto correlation between two sequences
SOFTWARE: MATLAB
THEORY:
Auto Correlation Function
Auto correlation function is a measure of similarity between a signal & its time
delayed version. It is represented with R(k).
The auto correlation function of x(n) is given by
R11(k)=R(k)=
Algorithm:
Step I : Give input sequence x[n].
Step II : Give impulse response sequence h (n)
Step III: Find auto correlation using the matlab command xcorr.
Step IV: Plot x[n], h[n], z[n].
Step V: Display the results
- 12 -
DEPT. OF ECE, MRCET DSP LAB MANUAL
Flow Chart:
PROGRAM:
clc;
close all;
clear all;
% two input sequences
x=input('enter input sequence')
subplot(1,2,1);
stem(x);
xlabel('n');
ylabel('x(n)');
title('input sequence');
% auto correlation of input sequence
z=xcorr(x,x);
disp(‘The values of z are = ‘);disp(z);
subplot(1,2,2);
stem(z);
xlabel('n');
ylabel('z(n)');
title('auto correlation of input sequence');
Output:
enter input sequence [1 2 3 4]
- 13 -
DEPT. OF ECE, MRCET DSP LAB MANUAL
z = [3.99, 11, 20, 30, 20, 11, 3.99]
Output Wave forms:
RESULT:
VIVA QUESTIONS:
1. Write mathematical formula to find auto correlation?
2. Define auto correlation?
3. Define correlation
4. Difference between Auto correlation and convolution?
5. Difference between Auto correlation and cross correlation?
6. Write mathematical formula to find cross correlation?
7. What is the length of the resultant sequence of auto correlation?
8. List few applications of correlation.
9. Give the properties of auto correlation.
10. Define cross correlation?
Exercise:
1. Find the auto correlation function of ramp sequence for 0≤n≤6.
- 14 -
DEPT. OF ECE, MRCET DSP LAB MANUAL
[Link]: 4
TO FIND FREQUENCY RESPONSE OF A GIVEN SYSTEM GIVEN
IN (TRANSFER FUNCTION/ DIFFERENTIAL EQUATION FORM)
AIM: To find frequency response of a given system in differential equation form.
Software: MATLAB
THEORY:
Systems respond differently to inputs of different frequencies. Some systems may
amplify components of certain frequencies, and attenuate components of other
frequencies. The way that the system output is related to the system input for different
frequencies is called the frequency response of the system.
Since the frequency response is a complex function, we can convert it to polar
notation in the complex plane. This will give us a magnitude and an angle. We call the
angle the phase.
Amplitude Response:
For each frequency, the magnitude represents the system's tendency to amplify or
attenuate the input signal.
Phase Response:
The phase represents the system's tendency to modify the phase of the input sinusoids.
The phase response, or its derivative the group delay, tells us how the system delays the
input signal as a function of frequency.
Given Difference equation is
Algorithm:
Step I : Give numerator coefficients of the given transfer function or difference
equation.
Step II : Give denominator coefficients of the given transfer function or difference
equation
Step III : Pass these coefficients to matlab command freqz to find frequency response.
Step IV : Find magnitude and phase response using matlab commands abs and angle.
Step V : Plot magnitude and phase response.
- 15 -
DEPT. OF ECE, MRCET DSP LAB MANUAL
Flow Chart:
PROGRAM:
%MATLAB program to plot the frequency response (magnitude and phase response)of
agiven difference equation.
clc;
clear all;
b=input('Enter the numerator coefficients:');
a=input('Enter the denominator coefficients:');
[h,w]=freqz(b,a);
subplot(2,1,1);
plot(w/pi,abs(h));
grid;
xlabel('Normalised Frequency');
ylabel('Magnitude in dB');
title('Magnitude Response');
subplot(2,1,2);
plot(w/pi,angle(h));
grid;
xlabel('Normalised Frequency');
ylabel('phase in radians');
title('Phase Response');
- 16 -
DEPT. OF ECE, MRCET DSP LAB MANUAL
Output:
Enter the numerator coefficients: [1]
Enter the denominator coefficients: [1 -1/6 -1/6]
Output Waveforms:
RESULT:
VIVA QUESTIONS:
1. Define Frequency response?
2. Define magnitude response?
3. Define Phase response?
4. Define transfer function.
5. State the significance of difference equations.
6. What are the classifications of system based on unit sample response?
7. What is zero input response?
8. Define impulse response?
9. Define System.
10. Write mathematical formula to find response of any given system.
Exercise:
1. Find the frequency response of the system described by the difference equation
y(n)-3/4 y(n-1)+1/8y(n-3)=x(n)+2x(n-1).
- 17 -
DEPT. OF ECE, MRCET DSP LAB MANUAL
[Link]: 5
TO FIND THE FFT OF A GIVEN SEQUENCE
AIM: To find the FFT of a given sequence
Software: MATLAB
THEORY:
DFT of a sequence
N 1
X k x[n]e j 2 / N kn
n 0
Where N= Length of sequence.
K= Frequency Coefficient.
n = Samples in time domain.
FFT: -Fast Fourier transform.
There are two methods.
1. Decimation in time (DIT ) FFT.
2. Decimation in Frequency (DIF) FFT.
Why we need FFT?
The no of multiplications in DFT = N2.
The no of Additions in DFT = N (N-1).
For FFT.
The no of multiplication = N/2 log 2N.
The no of additions = N log2 N.
Algorithm:
Step I : Give input sequence x[n].
Step II : Find the length of the input sequence using length command.
Step III : Find FFT and IFFT using matlab commands fft and ifft.
Step IV : Plot magnitude and phase response
Step V : Display the results
- 18 -
DEPT. OF ECE, MRCET DSP LAB MANUAL
Flow Chart:
PROGRAM:
clc;
clear all;
close all;
x=input('Enter the sequence : ')
N=length(x)
xK=fft(x,N)
xn=ifft(xK)
n=0:N-1;
subplot (2,2,1);
stem(n,x);
xlabel('n---->');
ylabel('amplitude');
title('input sequence');
subplot (2,2,2);
stem(n,abs(xK));
xlabel('n---->');
ylabel('magnitude');
title('magnitude response');
subplot (2,2,3);
stem(n,angle(xK));
xlabel('n---->');
ylabel('phase');
title('Phase responce');
subplot (2,2,4);
stem(n,xn);
xlabel('n---->');
ylabel('amplitude');
- 19 -
DEPT. OF ECE, MRCET DSP LAB MANUAL
title('IFFT');
Output:
Enter the sequence: [1 2 3 4 5]
x= 1 2 3 4 5
N= 5
xK = 15.0000, -2.5000 + 3.4410i, -2.5000 + 0.8123i , -2.5000 - 0.8123i, -2.5000 - 3.4410i
xn = 1 2 3 4 5
Output Waveform:
RESULT:
VIVA QUESTIONS:
1. Define transform. What is the need for transform?
2. Differentiate Fourier transform and discrete Fourier transform.
3. Differentiate DFT and DTFT.
4. What are the advantages of FFT over DFT?
5. Differentiate DITFFT and DIFFFT algorithms.
6. What is meant by radix?
7. What is meant by twiddle factor and give its properties?
8. How FFT is useful to represent a signal?
9. Compare FFT and DFT with respect to number of calculation required?
10. How the original signal is reconstructed from the FFT of a signal?
Exercise:
1. Find 8-point DFT of sequence x(n)=[1 2 1 2 3 4 4 3] using FFT algorithm.
- 20 -
DEPT. OF ECE, MRCET DSP LAB MANUAL
[Link]: 6
DETERMINATION OF POWER SPECTRUM OF A GIVEN SIGNAL
AIM: Determination of Power Spectrum of a given signal.
Software: MATLAB
THEORY:
The power spectrum describes the distribution of signal power over a frequency
spectrum. The most common way of generating a power spectrum is by using a discrete
Fourier transform, but other techniques such as the maximum entropy method can also be
used. The power spectrum can also be defined as the Fourier transform of auto correlation
function.
Algorithm:
Step I : Give input sequence x
Step II : Give sampling frequency, input frequency and length of the spectrum.
Step III : Find power spectrum of input sequence using matlab command spectrum.
Step IV : Plot power spectrum using specplot.
Flow Chart:
- 21 -
DEPT. OF ECE, MRCET DSP LAB MANUAL
PROGRAM:
Clc;
clear all;
close all;
N=1024;
fs=8000;
f=input('enter the frequency[1 to 5000]:');
n=0:N-1;
x=sin(2*pi*(f/fs)*n)
pxx=spectrum(x,N);
specplot(pxx,fs);
grid on
xlabel('freq(hz)');
ylabel('magnitude(db)');
title('power spectrum of x(n)');
INPUT:
Enter the frequency [1 to 5000]: 3000
Output Waveform:
- 22 -
DEPT. OF ECE, MRCET DSP LAB MANUAL
RESULT:
VIVA QUESTIONS:
1. Define power signal.
2. Define energy signal.
3. Define power spectral density of a signal.
4. How the energy of a signal can be calculated?
5. Explain difference between energy spectral density and power spectral density.
6. Explain the PSD plot.
7. What is the importance of PSD?
8. What are the applications of PSD?
9. Explain MATLAB function randn(size(n)).
10. What is the need to represent the signal in frequency domain?
Exercise:
1. Find power spectrum of the signal x(n)=cos(2*pi*50*n)
- 23 -
DEPT. OF ECE, MRCET DSP LAB MANUAL
EXP. NO: 7
IMPLEMENTATION OF LP FIR FILTER
AIM: To implement LP FIR filter for a given sequence.
Software: MATLAB
THEORY:
FIR filters are digital filters with finite impulse response. They are also known
as non-recursive digital filters as they do not have the feedback.
An FIR filter has two important advantages over an IIR design:
Firstly, there is no feedback loop in the structure of an FIR filter. Due to not
having a feedback loop, an FIR filter is inherently stable. Meanwhile, for an IIR
filter, we need to check the stability.
Secondly, an FIR filter can provide a linear-phase response. As a matter of fact,
a linear-phase response is the main advantage of an FIR filter over an IIR
design otherwise, for the same filtering specifications; an IIR filter will lead to
a lower order.
FIR FILTER DESIGN
An FIR filter is designed by finding the coefficients and filter order that meet
certain specifications, which can be in the time-domain (e.g. a matched filter) and/or the
frequency domain (most common). Matched filters perform a cross-correlation between
the input signal and a known pulse-shape. The FIR convolution is a cross-correlation
between the input signal and a time-reversed copy of the impulse-response. Therefore, the
matched-filter's impulse response is "designed" by sampling the known pulse-shape and
using those samples in reverse order as the coefficients of the filter.
When a particular frequency response is desired, several different design methods are
common:
1. Window design method
2. Frequency Sampling method
3. Weighted least squares design
WINDOW DESIGN METHOD
In the window design method, one first designs an ideal IIR filter and then
truncates the infinite impulse response by multiplying it with a finite length window
function. The result is a finite impulse response filter whose frequency response is
modified from that of the IIR filter.
- 24 -
DEPT. OF ECE, MRCET DSP LAB MANUAL
Window Transition Width Min. Stop band Matlab
Name Approximate Exact values Attenuation Command
4 1 . 8
Rectangular 21db B = FIR1(N,Wn,boxcar)
M M
8 6.1
Bartlett 25db B = FIR1(N,Wn,bartlett)
M M
8 6 .2
Hanning 44db B = FIR1(N,Wn,hanning)
M M
8 6 .6
Hamming 53db B= FIR1(N,Wn,hamming)
M M
12 11
Blackman 74db B = FIR1(N,Wn,blackman)
M M
Algorithm:
Step I : Enter the pass band frequency (fp) and stop band frequency (fq).
Step II : Get the sampling frequency (fs), length of window (n).
Step III : Calculate the cut off frequency, fn
Step IV : Use boxcar, hamming, blackman Commands to design window.
Step V : Design filter by using above parameters.
Step VI : Find frequency response of the filter using matlab command freqz.
Step VII : Plot the magnitude response and phase response of the filter.
- 25 -
DEPT. OF ECE, MRCET DSP LAB MANUAL
Flow Chart:
PROGRAM:
clc;
clear all;
close all;
n=20;
fp=200;
fq=300;
fs=1000;
fn=2*fp/fs;
window=blackman(n+1);
b=fir1(n,fn,window);
[H W]=freqz(b,1,128);
subplot(2,1,1);
plot(W/pi,abs(H));
title('magnitude response of lpf');
ylabel('gain in db-------->');
xlabel('normalized frequency------>');
- 26 -
DEPT. OF ECE, MRCET DSP LAB MANUAL
subplot(2,1,2);
plot(W/pi,angle(H));
title('phase response of lpf');
ylabel('angle-------->');
xlabel('normalized frequency------>');
Output Wave forms:
RESULT:
- 27 -
DEPT. OF ECE, MRCET DSP LAB MANUAL
VIVA QUESTIONS:
1. Define filter.
2. What are the different types of filters?
3. Why are FIR filters generally preferred over IIR filters in multirate (decimating
and interpolating) systems/
4. Difference between IIR and FIR filters?
5. Differentiate ideal filter and practical filter responses.
6. What is the filter specifications required to design the analog filters?
7. What is meant by frequency response of filter?
8. What is meant by magnitude response?
9. What is meant by phase response?
10. Difference between FIR low pass filter and high pass filter.
Exercise:
1. Design LP FIR filter using Bartlett and hamming window.
- 28 -
DEPT. OF ECE, MRCET DSP LAB MANUAL
EXP. NO: 8
IMPLEMENTATION OF HP FIR FILTER
AIM: To implement HP FIR filter for a given sequence.
Software: MATLAB
Algorithm:
Step I : Enter the pass band frequency (fp) and stop band frequency (fq).
Step II : Get the sampling frequency (fs), length of window (n).
Step III : Calculate cut off frequency
Step IV : Use boxcar, hamming, Blackman Commands to design window.
Step V : Design filter by using above parameters.
Step VI : Find frequency response of the filter using matlab command freqz.
Step VII : Plot the magnitude response and phase response of the filter.
Flow Chart:
- 29 -
DEPT. OF ECE, MRCET DSP LAB MANUAL
PROGRAM:
clc;
clear all;
close all;
n=20;
fp=300;
fq=200;
fs=1000;
fn=2*fp/fs;
window=blackman(n+1);
b=fir1(n,fn,'high',window);
[H W]=freqz(b,1,128);
subplot(2,1,1);
plot(W/pi,abs(H));
title('mag res of lpf');
ylabel('gain in db-------->');
xlabel('normalized frequency------>');
subplot(2,1,2);
plot(W/pi,angle(H));
title('phase res of lpf');
ylabel('angle-------->');
xlabel('normalized frequency------>');
- 30 -
DEPT. OF ECE, MRCET DSP LAB MANUAL
Output Waveforms:
RESULT:
VIVA QUESTIONS:
1. What is a filter?
2. Differentiate analog filter and digital filter.
3. Define FIR filter.
4. What are the differences between recursive and non recursive systems?
5. List a few Applications of FIR filters.
6. Explain advantages of FIR filters over IIR filters.
7. Explain limitations of FIR filters.
8. What are the different methods to design FIR filters?
9. Explain different window functions.
10. Differentiate rectangular, triangular and Kaiser Windows.
Exercise:
1. Design HP FIR filter using Rectangular and hanning Window.
- 31 -
DEPT. OF ECE, MRCET DSP LAB MANUAL
EXP. NO: 9
IMPLEMENTATION OF LP IIR FILTER
AIM: To implement LP IIR filter for a given sequence.
Software: MATLAB
THEORY:
IIR filters are digital filters with infinite impulse response. Unlike FIR filters, they
have the feedback (a recursive part of a filter) and are known as recursive digital filters
therefore.
For this reason IIR filters have much better frequency response than FIR filters of
the same order. Unlike FIR filters, their phase characteristic is not linear which can cause
a problem to the systems which need phase linearity. For this reason, it is not preferable
to use IIR filters in digital signal processing when the phase is of the essence. Otherwise,
when the linear phase characteristic is not important, the use of IIR filters is an excellent
solution.
There is one problem known as a potential instability that is typical of IIR filters only.
FIR filters do not have such a problem as they do not have the feedback. For this reason,
it is always necessary to check after the design process whether the resulting IIR filter is
stable or not.
IIR FILTER DESIGN
For the given specifications to Design a digital IIR filter, first we need to design
analog filter (Butterworth or chebyshev). The resultant analog filter is transformed to
digital filter by using either “Bilinear transformation or Impulse Invariant
transformation”.
- 32 -
DEPT. OF ECE, MRCET DSP LAB MANUAL
Algorithm:
Step I : Enter the pass band ripple (rp) and stop band ripple (rs).
Step II : Enter the pass band frequency (wp) and stop band frequency (ws).
Step III : Get the sampling frequency (fs).
Step IV : Calculate normalized pass band frequency, and normalized stop band
frequency w1 and w2 respectively. w1 = 2 * wp /fs w2 = 2 * ws /fs
Step V : Make use of the following function to calculate order of filter
Butterworth filter order
[n,wn]=buttord(w1,w2,rp,rs )
Chebyshev filter order
[n,wn]=cheb1ord(w1,w2,rp,rs)
Step VI : Design an nth order digital low pass Butterworth or Chebyshev filter
using the following statements.
Butterworth filter
[b, a]=butter (n, wn)
Chebyshev filter
[b,a]=cheby1 (n, 0.5, wn)
Step VII : Find the digital frequency response of the filter by using ‘freqz( )’
function
Step VIII : Calculate the magnitude of the frequency response in decibels (dB)
mag=20*log10 (abs (H))
Step IX : Plot the magnitude response [magnitude in dB Vs normalized frequency]
Step X : Calculate the phase response using angle (H)
Step XI : Plot the phase response [phase in radians Vs normalized frequency (Hz)].
- 33 -
DEPT. OF ECE, MRCET DSP LAB MANUAL
Flow Chart:
PROGRAM:
clc;
clear all;
close all;
disp('enter the IIR filter design specifications');
rp=input('enter the passband ripple:');
rs=input('enter the stopband ripple:');
wp=input('enter the passband freq:');
ws=input('enter the stopband freq:');
fs=input('enter the sampling freq:');
w1=2*wp/fs;w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs,'s');
disp('Frequency response of IIR LPF is:');
- 34 -
DEPT. OF ECE, MRCET DSP LAB MANUAL
[b,a]=butter(n,wn,'low','s');
w=0:.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
an=angle(h);
figure,subplot(2,1,1);plot(om/pi,m);
title('magnitude response of IIR filter is:');
xlabel('(a) Normalized freq. -->');
ylabel('Gain in dB-->');
subplot(2,1,2);plot(om/pi,an);
title('phase response of IIR filter is:');
xlabel('(b) Normalized freq. -->');
ylabel('Phase in radians-->');
INPUT:
enter the IIR filter design specifications
enter the passband ripple:15
enter the stopband ripple:60
enter the passband freq:1500
enter the stopband freq:3000
enter the sampling freq:7000
- 35 -
DEPT. OF ECE, MRCET DSP LAB MANUAL
Output waveforms:
RESULT:
VIVA QUESTIONS:
1. List some advantages of digital filters over analog filters.
2. Write some differences between FIR and IIR filters.
3. What are the different methods to design IIR filters?
4. Why IIR filters are not reliable?
5. What are different applications of IIR filters?
6. What are advantages of IIR filters?
7. What are disadvantages of IIR filters?
8. Differentiate Butterworth and Chebyshev approximations.
9. What is meant by impulse response?
10. Difference between IIR low pass and High pass filters.
Exercise:
1. Design low pass IIR filter using Chebyshev filter.
- 36 -