You are on page 1of 79

Digital Signal Processing Lab Manual -- 18ECL57 V semester

DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING


DR.AMBEDKAR INSTITUTE OF TECHNOLOGY
BANGALORE – 560056

DIGITAL SIGNAL PROCESSING


LAB MANUAL
18ECL57
V Semester

2021-2022

NAME OF THE STUDENT :

USN NUMBER :

BATCH :

Prepared By:
Dr. MAHALINGA V MANDI, Professor, Dept of ECE.
NAGARATHNA H S, Assistant Professor, Dept. of ECE.
MANJULA N, Assistant Professor, Dept. of ECE.
SHWETHA N, Assistant Professor, Dept. of ECE.

Dept. of ECE, Dr.AIT


1
Digital Signal Processing Lab Manual -- 18ECL57 V semester

Syllabus
Subject Title: DSP Lab

Sub.Code:18ECL57 No. of Credits:1=0:0:1( L - T – P) No. of Lecture Hours/Week : 02


Exam Duration:03 Hrs CIE+SEE=50+50=100 Total No.of Contact Hours:26

Course Learning Objectives

1 To analyze the sampling process, impulse response, convolution, frequency domain response of
LTI systems
2 To analyze and design of digital IIR and FIR filters
3 To demonstrate the DSP algorithms using Matlab software
4 To demonstrate the DSP algorithms using Code Composer Studio
5 To study DSP algorithms on Virtual Laboratory

PART Syllabus No. of Blooms


Hours Taxonomy Level
Matlab Programs
Introduction to Matlab
1. Impulse response of a given system
2. Linear convolution of two given sequences.
A 3. Circular convolution of two given sequences 18 L1, L2, L3
4. Linear convolution of two sequences using DFT and IDFT.
5. Circular convolution of two given sequences using DFT and
IDFT
6. Design and implementation of FIR filter to meet given
specifications.
7. Design and implementation of IIR Butterworth filter to
meet given specifications.
8. Design and implementation of IIR Chebyshev filter to meet
given specifications

TEXT 1
Hardware programs using TMS320C6713 DSK
1. Linear convolution of two given sequences. 12 L1, L2
B 2. Circular convolution of two given sequences.
3. Computation of N- Point DFT of a given sequence
4. Impulse response of first order system.

TEXT 2
Virtual Laboratory
C 1. Study of Sampling Theorem 09 L1, L2, L3
2. Study of DFT and its inverse
3. Study of FIR low pass and high pass filters
4. Study of IIR low pass and high pass filters
TEXT 1 and Web link 1

Course Outcomes:

CO1 Define and verify the sampling theorem, impulse response, convolution and frequency response
of the system

Dept. of ECE, Dr.AIT


2
Digital Signal Processing Lab Manual -- 18ECL57 V semester
CO2 Understand basic algorithms of DSP
CO3 Design an IIR and FIR digital filter
CO4 Implementation of DSP algorithms using Matlab software and using Code Composer Studio
(CCS) on DSP processor
CO5 Conduction of DSP experiments on virtual laboratory

Course Outcomes Mapping with Programme Outcomes


CO1 PO1, PO2, PO9
CO2 PO1, PO2, PO9
CO3 PO1, PO2, PO3, PO9
CO4 PO1, PO2, PO3, PO5, PO9
CO5 PO1, PO2, PO3, PO5, PO9
Text Books:
1. Brian R. Hunt, Ronald L. Lipsman, Jonathan M. Rosenberg, “A Guide to MATLAB – For beginners and
Experience Users”, Cambridge University Press, 20021
2. B. Ventakaramani and Bhaskar, “Digital Signal Processor”, TMH, 2002.

Web Links:
1. http://vlabs.iitkgp.ernet.in/dsp/index.html#

Dept. of ECE, Dr.AIT


3
Digital Signal Processing Lab Manual -- 18ECL57 V semester

Table of Contents

SL. List of Experiments Page


No. No.

PART-A Matlab programs


1 Impulse response of a given system 10

2 Linear convolution of two given sequences 12

3 Circular convolution of two given sequences 16

4 Linear Convolution of two sequences using DFT and IDFT

5 Circular convolution of two given sequences using DFT and IDFT

6 Design and implementation of FIR filter to meet given


specifications

7 Design and implementation of IIR Butterworth filter to meet given


specifications

8 Design and implementation of IIR Chebyshev filter to meet given


specifications

PART-B Hardware programs using TMS320C6713 DSK


Getting started with Code Composer Studio (CCS)

1 Linear convolution of two given sequences

2 Circular convolution of two given sequences

3 Computation of N – Point DFT of a given sequence

4 Impulse response of first order and second order system

PART-C Virtual Laboratory


1 Study of Sampling Theorem

2 Study of DFT and its inverse

3 Study of FIR low pass and high pass filters

4 Study of IIR low pass and high pass filters

Dept. of ECE, Dr.AIT


4
Digital Signal Processing Lab Manual -- 18ECL57 V semester

Introduction to MATLAB

A. MATLAB [MATrix LABoratory]:


MATLAB is a 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 -
1. Math and computation
2. Algorithm development
3. Data acquisition Modeling, simulation and prototyping
4. Data analysis, exploration and visualization
5. Scientific and engineering graphics
6. Application development, including graphical user interface building
MATLAB is an interactive system whose basic data element is an array that does not require
dimensioning. This allows you to solve many technical computing problems, especially those
with matrix and vector formulations, in a fraction of the time it would take to write a program
in a scalar non interactive language such as C or FORTRAN.
There are also several optional ‘Toolboxes’ available from the developers of MATLAB. These
Toolboxes are collections of functions written for special applications such as Symbolic
Computation, Image Processing, Statistics, Control System Design, Neural Networks, etc.
B. The MATLAB System:
The MATLAB system consists of five main parts:
1. Development Environment: This is the set of tools and facilities that help you use
MATLAB functions and files. Many of these tools are graphical user interfaces. It includes the
MATLAB desktop and Command Window, a command history, an editor and debugger, and
browsers for viewing help, the workspace, files and the search path.
2. MATLAB Mathematical Function Library: This is a vast collection of computational
algorithms ranging from elementary functions like sum, sine, cosine, and complex arithmetic,
to more sophisticated functions like matrix inverse, matrix Eigenvalues, Bessel functions and
fast Fourier transforms.

3. MATLAB Language: This is a high-level matrix/array language with control flow


statements, functions, data structures, input/output, and object-oriented programming

Dept. of ECE, Dr.AIT


5
Digital Signal Processing Lab Manual -- 18ECL57 V semester
features. It allows both "programming in the small" to rapidly create quick and throw-away
programs and "programming in the large" to create complete large and complex application
programs.

4. Graphics: MATLAB has extensive facilities for displaying vectors and matrices as
graphs, as well as annotating and printing these graphs. It includes high-level functions for
two-dimensional and three-dimensional data visualization, image processing, and animation
and presentation graphics. It also includes low-level functions that allow you to fully customize
the appearance of graphics as well as to build complete graphical user interfaces on your
MATLAB applications.

5. MATLAB Application Program Interface (API): This is a library that allows you to
write C and FORTRAN programs that interact with MATLAB. It includes facilities for calling
routines from MATLAB (dynamic linking), calling MATLAB as a computational engine and for
reading and writing MAT-files.

C. MATLAB windows:
In MATLAB there are three basic windows -

1. Command window: This is the main window. It is characterized by the MATLAB command
prompt ‘>>’. When you launch the application program, MATLAB puts you in this window.
All commands, including those for running user-written programs, are typed in this
window at the MATLAB prompt.
Also there are several sub windows, which include -

 Launch Pad: This sub window lists all MATLAB related applications and toolboxes
that are installed on your machine.
 Workspace: This sub window lists all variables that you have generated so far and
shows their type and size.
 Command History: All commands typed on the MATLAB prompt in the command
window get recorded, even across multiple sessions (you worked on Monday, then
on Thursday, and then on next Wednesday, and so on), in this window. You can
select a command from this window with the mouse and execute it in the command
window by double clicking on it.
 Current Directory: This is where all your files from the current directory are listed.
You can do file navigation here.
2. Graphics window: The output of all graphics commands typed in the command window
are flushed to the graphics or Figure window, a separate gray window with (default) white
background color. The user can create as many figure windows as the system memory will
allow.

Dept. of ECE, Dr.AIT


6
Digital Signal Processing Lab Manual -- 18ECL57 V semester
3. Edit window: This is where you write, edit, create and save your own programs in files
called ‘M-files’.

MATLAB Software flow diagram

How to Program?
S1: Click the Icon on the Desktop

Ideal Window

Dept. of ECE, Dr.AIT


7
Digital Signal Processing Lab Manual -- 18ECL57 V semester

S2: Create a New folder, name it and set it as


current directory

Dept. of ECE, Dr.AIT


8
Digital Signal Processing Lab Manual -- 18ECL57 V semester
S3: Create New “.m” file for writing a Matlab code

S4: Enter the code in editor and save it with appropriate name.

Dept. of ECE, Dr.AIT


9
Digital Signal Processing Lab Manual -- 18ECL57 V semester
S5: Run the code in Command window by typing the name of the code.

D. MATLAB FILE TYPES:


MATLAB has three types of files for storing information:

1.M – Files: These are standard ASCII text files, with a .m extension to the filename. There are
two types of these files: script files and function files. All built-in functions in MATLAB are M-
files, most of which reside on your computer in precompiled format.
2.Mat – Files: These are binary data files, with a .mat extension to the filename. Mat – files are
created by MATLAB when you save data with the save command. The data is written in a
special format that only MATLAB can read. Mat – files can be loaded into MATLAB with the
load command.
3. Mex- Files: These are MATLAB – callable FORTRAN and C programs, with a .mex extension
to the filename. Use of these files requires some experience with MATLAB and a lot of patience.

Dept. of ECE, Dr.AIT


10
Digital Signal Processing Lab Manual -- 18ECL57 V semester

Part A

MATLAB Programs

Dept. of ECE, Dr.AIT


11
Digital Signal Processing Lab Manual -- 18ECL57 V semester

EXPERIMENT NO 1: Impulse response of a given system

Aim: To find Impulse Response of a given LTI system.


y[n]-y[n-1]+0.9*y[n-2]=x[n]

Theory:

Fig.2.1 A LTI system

 A discrete time LTI system (also called digital filters) as shown in Fig.2.1 is
represented by
o A linear constant coefficient difference equation, for example,
y[n]  a1 y[n  1]  a 2 y[n  2]  b0 x[n]  b1 x[n  1]  b2 x[n  2];
o A system function H(z) (obtained by applying Z transform to the difference
Y ( z ) b0  b1 z 1  b2 z 2
equation). H ( z )  
X ( z ) 1  a1 z 1  a 2 z  2
o A frequency response function obtained by applying DTFT on the impulse
response h[n] (or by replacing z with ejΩ in H(z)) to get
Y (e j ) b0  b1e  j  b2 e 2 j
H ( e j )  
X (e j ) 1  a1e  j  a 2 e  2 j
 Given the difference equation or H(z), the impulse response of the LTI system is found
using filter or impz MATLAB functions. This is elaborated in experiment no.7 -
Solving a given difference equation. If the difference equation contains past samples of
output, i.e., y[n-1], y[n-2], etc , then its impulse response is of infinite duration (IIR). For
such systems the impulse response is computed for a large value of n, say n=100 (to
approximate n=∞).
 Given only the input sequence x[n] and the output sequence y[n], we can find the
impulse function h[n] by using the inverse operation deconv. (The conv operation
convolves 2 sequences x[n] and h[n] to obtain the output y[n]. for convolution
operation refer experiment no 3: Linear convolution of two given sequences). If both
y[n] and x[n] are finite then the impulse response is finite (FIR).
 The deconvolution operation is valid only if the LTI system is ‘invertible’.

Algorithm :
1. Input the two sequences as x and y.
2. Use deconv to get impulse response h.
3. Plot the sequences.
4. Verify using conv(x,h) to get y back.

Dept. of ECE, Dr.AIT


12
Digital Signal Processing Lab Manual -- 18ECL57 V semester
MATLAB Program:

N=input('Length of impulse response required=');


b=[1]; % x coefficient
a=[1,-1,0.9]; % y coefficients
h=impz(b,a,N); % impulse response
%Plot the Impulse Response sequence
n=0:N-1;
stem(n,h);
title('Impulse Response');
xlabel('n');
ylabel('h(n)');

Fig. 1 Impulse Response

Result:
Length of impulse response required = 10
h=
1.000000000000000
1.000000000000000
0.100000000000000
-0.800000000000000
-0.890000000000000
-0.170000000000000
0.631000000000000
0.784000000000000
0.216100000000000
-0.489500000000000

Dept. of ECE, Dr.AIT


13
Digital Signal Processing Lab Manual -- 18ECL57 V semester

EXPERIMENT NO 2: Linear convolution of two given sequences.

Aim: To obtain convolution of two finite duration sequences.

Theory:
 The output y[n] of a LTI (linear time invariant) system can be obtained by convolving
the input x[n] with the system’s impulse response h[n].
 
 The convolution sum is y[n]  x[n]  h[n]   x[k ]h[n  k ] 
k  
 x[n  k ]h[k ]
k  

 x[n] and h[n] can be both finite or infinite duration sequences.


 Even if one (or both) of the sequences is infinite (say, h[n]  0.9  u[n] ), we can
n

analytically evaluate the convolution formula to get a functional form (closed form
solution) of y[n].
 If both the sequences are of finite duration, then we can use the MATLAB function
‘conv’ to evaluate the convolution sum to obtain the output y[n]. Convolution is
implemented as polynomial multiplication (refer MATLAB help).
 The length of y[n] = xlength + hlength -1.
 The conv function assumes that the two sequences begin at n=0 and is invoked by
y=conv(x,h).
 Even if one of the sequences begin at other values of n, say n=-3,or n=2; then we need
to provide a beginning and end point to y[n] which are ybegin=xbegin+hbegin and
yend=xend+hend respectively.

Algorithm:
1. Input the two sequences as x1, x2
2. Convolve both to get output y.
3. Plot the sequences.

MATLAB Program:
Level 1 Program (both sequences are right sided)
%main part of computation
x =input('Enter the first sequence = ');
h =input('Enter the second sequence = ');
y=conv(x, h);
disp('Linear convolution of x(n) and h(n) is y = ');
disp(y);

%Graphical display part


subplot(2,1,1);
stem(y);
xlabel('Time index n');

Dept. of ECE, Dr.AIT


14
Digital Signal Processing Lab Manual -- 18ECL57 V semester
ylabel('Amplitude');
title('Convolution Output y(n) = ');

subplot(2,2,3);
stem(x);
xlabel('Time Index n');
ylabel('Amplitude');
title('Plot of x(n)');

subplot(2,2,4);
stem(h);
xlabel('Time index n');
ylabel('Amplitude');
title('Plot of h(n)’);
Result

Enter the first sequence= [1 2 3 4]


Enter the second sequence= [1 -1 0 -1]
After execution;
1. 1. 1. 0. - 6. - 3. - 4.
Verification:
Show the manual calculations to find linear convolution of x(n) = [1 2 3 4] and
h(n) = [1 -1 0 -1]

Fig. 2.1 Linear Convolution output

Dept. of ECE, Dr.AIT


15
Digital Signal Processing Lab Manual -- 18ECL57 V semester
Level 2 Program (Two sided sequences)
%main part of computation
x1=[1 2 3 2 1 3 4] %first sequence
n1=-3:3 %time vector of first seq
x2=[ 2 -3 4 -1 0 1] %second seq
n2=-1:4 %time vector of second seq
%add first elements of time vector
ybegin=n1(1)+n2(1);
%add last elements of time vector
yend=n1(length(x1))+n2(length(x2));
ny=[ybegin:yend];
y=conv(x1,x2) ;
disp('linear con of x1 & x2 is y=');
disp(y);

%graphical display with time info


subplot (2,1,1);
stem(ny,y);
xlabel('time index n');
ylabel('amplitude ');
title('convolution output');
subplot(2,2,3);
stem(n1,x1);
xlabel('time index n');
ylabel('amplitude ');
title('plot of x1');
subplot(2,2,4);
stem(n2,x2);
xlabel('time index n');
ylabel('amplitude ');
title('plot of x2');

Dept. of ECE, Dr.AIT


16
Digital Signal Processing Lab Manual -- 18ECL57 V semester

Fig.2.2 For two sided sequences (With time information)

Result
x1 =1 2 3 2 1 3 4
n1 =-3 -2 -1 0 1 2 3
x2 =2 -3 4 -1 0 1
n2 =-1 0 1 2 3 4
linear con of x1 & x2 is y = 2 1 4 2 6 9 3 2 15 -3 3 4

Dept. of ECE, Dr.AIT


17
Digital Signal Processing Lab Manual -- 18ECL57 V semester
EXPERIMENT NO 3: Circular convolution of two given sequences.

Aim: To obtain circular convolution of two finite duration sequences.

Theory:
 As seen in the last experiment, the output y[n] of a LTI (linear time invariant) system
can be obtained by convolving the input x[n] with the system’s impulse response h[n].
 The above linear convolution is generally applied to aperiodic sequences. Whereas
the Circular Convolution is used to study the interaction of two signals that are
periodic.
 
 The linear convolution sum is y[n]  x[n]  h[n]   x[k ]h[n  k ]   x[n  k ]h[k ] . To
k   k  

compute this equation, the linear convolution involves the following operations:
o Folding- fold h[k] to get h[-k] ( for y[0])
o Multiplication – vk[n] = x[k] × h[n-k] (both sequences are multiplied sample by
sample)
o Addition- Sum all the samples of the sequence vk[n] to obtain y[n]
o Shifting – the sequence h[-k] to get h[n-k] for the next n.


 The circular convolution sum is y[n]  x[n] N h[n]   x[k ]h[ n  k N
] where the
k  

where the index n  k N


implies circular shifting operation and  k N
implies
folding the sequence circularly.
 Steps for circular convolution are the same as the usual convolution, except all index
calculations are done "mod N" = "on the wheel".
o Plot f [m] and h [−m] as shown in Fig. 4.1. (use f(m) instead of x(k))
o Multiply the two sequences
o Add to get y[m]
o "Spin" h[−m] n times Anti Clock Wise (counter-clockwise) to get h[n-m].
 x[n] and h[n] can be both finite or infinite duration sequences. If infinite sequences,
they should be periodic, and the N is chosen to be at least equal to the period. If they
are finite sequences N is chosen as >= to max(xlength, hlength). Whereas in linear
convolution N>= xlength+hlength-1.
 Say x[n]  {2,3, 1,1} and N = 5, then the x[-1] and x[-2] samples are plotted at x[N-1] =

x[-4] and x[N-2] =x[-3] places. Now x[n] is entered as x[n]  {1,1,0,2,3} .

Fig. 3.1 Plotting of f(m) and h(-m) for circular convolution

Dept. of ECE, Dr.AIT


18
Digital Signal Processing Lab Manual -- 18ECL57 V semester

Algorithm:
1. Input the two sequences as x and h.
2. Circularly convolve both to get output y.
3. Plot the sequences.

MATLAB Program:

%Circular Convolution Program


x=[1 2 3 4];
h= [1 2 3 4];
N=max(length(x1),length(x2));

%compute the output


for n=0:N-1
y(n+1)=0;
for k=0:N-1
i=mod((n-k),N); %calculation of x index
if i<0
i=i+N;
end %end of ‘if’
y(n+1)=y(n+1)+h(k+1)*x(i+1);
end %end of inner ‘for loop’
end %end of outer ‘for loop’
disp('circular convolution of x1 &x2 is y=');
disp(y);

%plot
n1=0:N-1;
stem(n1,y);
title('Circular convolution output y(n)');

Result:
circular convolution of x1 &x2 is
y= 26 28 26 20
The plot is as shown in Fig. 4.1

Dept. of ECE, Dr.AIT


19
Digital Signal Processing Lab Manual -- 18ECL57 V semester

Fig. 3.2 Circular convolution output

Verification:
Find circular convolution manually for x1(n) = [1 2 3 4] and x2(n) = [4 3 2 1]

Exercise:
1. Find the circular convolution of x(n) = [1 2 3 4] and h(n) = [1 -1 0 -1]

Ans: y(n) = - 5. - 2. - 3. 0.
2. Find the circular convolution of x(n) = [1 2 3 4] and h(n) = [4 3 2 1]

Ans: y(n) = 24. 22. 24. 30.

Dept. of ECE, Dr.AIT


20
Digital Signal Processing Lab Manual -- 18ECL57 V semester

EXPERIMENT NO 4: Linear convolution using DFT and IDFT

Aim: To find linear convolution of x(n) and h(n) using DFT and IDFT

Theory:

Discrete Fourier Transform (DFT) is used for performing frequency analysis of discrete
time signals. DFT gives a discrete frequency domain representation whereas the other
transforms are continuous in frequency domain.
The N point DFT of discrete time signal x[n] is given by the equation
N -1  j 2kn

X (k )   x[n]e N
; k  0,1,2,....N - 1
n 0
Where N is chosen such that N  L , where L=length of x[n].
The inverse DFT allows us to recover the sequence x[n] from the frequency samples.
j 2kn
1 N 1
x[n]   x[n]e N ; n  0,1,2,....N - 1
N k 0
X(k) is a complex number (remember ejw=cosw + jsinw). It has both magnitude and phase
which are plotted versus k. These plots are magnitude and phase spectrum of x[n]. The ‘k’
gives us the frequency information.

Algorithm:
1. Input the two sequences as x1, x2
2. Obtain N-point DFTs (X1, X2) of both the sequences.
3. Multiply both the DFTs (Y=X1×X2).
4. Perform IDFT on Y to get y[n] (the linearly convolved sequence) in time domain.
5. Verify using the ‘conv’ command.
6. Plot the sequences.

MATLAB Program:

x1=[1 2 3 4];
x2=[1 -1 0 -1];
N=length(x1)+length(x2)-1;

% Obtain DFTs
X1=fft(x1,N);
X2=fft(x2,N);

% perform vector multiplication


y=X1.*X2;
%ifft to get y[n]

Dept. of ECE, Dr.AIT


21
Digital Signal Processing Lab Manual -- 18ECL57 V semester
yn=ifft(y,N);
disp('Linear convolution of x1 and x2 is yn=');
disp(yn);

%Verify
disp('Output using conv command');
yv=conv(x1,x2);
disp(yv);

%Plot
stem(yn);
xlabel('Time Index');
ylabel('Amplitude');
title('Linear convolution output y(n)');

Result:

Save and execute the program;


After execution
Linear Convolution using DFT and IDFT = 1. 1. 1. 0. - 6. - 3. - 4.
Verification:
Find linear convolution manually using DFT and IDFT equations for x(n) = [1 2 3 4] and
h(n) = [1 -1 0 -1]

Fig. 4. Linear Convolution using DFT and IDFT

Dept. of ECE, Dr.AIT


22
Digital Signal Processing Lab Manual -- 18ECL57 V semester

Exercise:

1. Find the linear convolution of x(n) = [1 2 3 4] and h(n) = [1 1 1 1] using DFT and IDFT.

Ans: y(n) = 1 3 6 10 9 7 4

2.Find the linear convolution of x(n) = [1 2 3 4] and h(n) = [1 2 3 4] using DFT and IDFT.

Ans: y(n) = 1 4 10 20 25 24 16

Dept. of ECE, Dr.AIT


23
Digital Signal Processing Lab Manual -- 18ECL57 V semester
EXPERIMENT NO 5 :Circular convolution of two given sequences using DFT and
IDFT

Aim: To perform circular convolution of two given sequences x1 & x2 using DFT &
IDFT

Theory:
 By multiplying two N-point DFTs in the frequency domain, we get the circular
convolution in the time domain.
N  DFT
y[n]  x[n]  h[n]   Y (k )  X (k )  H (k )
 Circular Convolution is made identical to linear convolution by choosing the number
of points in DFT as N ≥ xlength + hlength -1.
 For Circular Convolution, N = max (xlength, length).

Algorithm:
1.Input the two sequences as x1, x2
2.Compute N = xlength + hlength -1
(for circular convolution, N=max(xlength + hlength))
3. Obtain N-point DFTs (X1, X2) of both the sequences.
4. Multiply both the DFTs (Y=X1×X2).
5. Perform IDFT on Y to get y[n] (the linearly convolved sequence) in time domain.
6. Verify using the ‘conv’ command.
7. Plot the sequences.

MATLAB Program:

%Circular Convolution Program using DFT


x1=[1 2 3 4];
x2= [1 2 3 4];
N=max(length(x1),length(x2));

%obtain DFTs
X1= fft(x1,N);
X2= fft(x2,N);

%Perform vector multiplication


y= X1.*X2;

%ifft to get y[n]


yn= ifft(y,N);
disp('circular convolution of x1 &x2 is yn=');

Dept. of ECE, Dr.AIT


24
Digital Signal Processing Lab Manual -- 18ECL57 V semester
disp(yn);
%plot
stem(yn);
title('Circular convolution output y(n)');

Result:
circular convolution of x1 &x2 is yn=
26 28 26 20

The output plot is shown in Fig. 5

Fig. 5. Circular Convolution using DFT and IDFT

Exercise:
1. Find the circular convolution of x1(n) = [1 2 3 4] and x2(n) = [1 -1 0 -1] using DFT and
IDFT.

Ans: x3(n) = - 5. - 2. - 3. 0.

2.Find the circular convolution of x1(n) = [1 2 3 4] and x2(n) = [4 3 2 1] using DFT and
IDFT.

Ans: DFT of x1(n) is X1(K) = 10. - 2. + 2.i - 2. - 2. - 2.i


DFT of x2(n) is X2(K) = 10. 2. - 2.i 2. 2. + 2.i
DFT of x3(n) is y = 100. 8.i - 4. - 8.i
Circular convolution yn = 24. 22. 24. 30.

Dept. of ECE, Dr.AIT


25
Digital Signal Processing Lab Manual -- 18ECL57 V semester

EXPERIMENT NO 6: Design and implementation of FIR filter to meet given


specifications

Aim: To design and implement a FIR filter for given specifications.

DESIGNING AN FIR FILTER (using window method):

Method I: Given the order N, cutoff frequency fc, sampling frequency fs and the window.

 Step 1: Compute the digital cut-off frequency Wc (in the range -π < Wc < π, with π
corresponding to fs/2) for fc and fs in Hz. For example let fc=400Hz, fs=8000Hz
Wc = 2*π* fc / fs = 2* π * 400/8000 = 0.1* π radians
For MATLAB the Normalized cut-off frequency is in the range 0 and 1, where 1
corresponds to fs/2 (i.e.,fmax)). Hence to use the MATLAB commands
wc = fc / (fs/2) = 400/(8000/2) = 0.1
Note: if the cut off frequency is in radians then the normalized frequency is computed
as wc = Wc / π
 Step 2: Compute the Impulse Response h(n) of the required FIR filter using the given
Window type and the response type (lowpass, bandpass, etc). For example given a
rectangular window, order N=20, and a high pass response, the coefficients (i.e., h[n]
samples) of the filter are computed using the MATLAB inbuilt command ‘fir1’ as
h =fir1(N, wc , 'high', boxcar(N+1));
Note: In theory we would have calculated h[n]=hd[n]×w[n], where hd[n] is the desired
impulse response (low pass/ high pass,etc given by the sinc function) and w[n] is the
window coefficients. We can also plot the window shape as stem(boxcar(N)).
Plot the frequency response of the designed filter h(n) using the freqz function and observe
the type of response (lowpass / highpass /bandpass).

Method 2:
Given the pass band (wp in radians) and Stop band edge (ws in radians) frequencies, Pass
band ripple Rp and stopband attenuation As.
 Step 1: Select the window depending on the stopband attenuation required. Generally
if As>40 dB, choose Hamming window. (Refer table )
 Step 2: Compute the order N based on the edge frequencies as
Transition bandwidth = tb=ws-wp;
N=ceil (6.6*pi/tb);

Dept. of ECE, Dr.AIT


26
Digital Signal Processing Lab Manual -- 18ECL57 V semester
 Step 3: Compute the digital cut-off frequency Wc as
Wc=(wp+ws)/2
Now compute the normalized frequency in the range 0 to 1 for MATLAB as
wc=Wc/pi;
Note: In step 2 if frequencies are in Hz, then obtain radian frequencies (for computation of tb
and N) as wp=2*pi*fp/fs, ws=2*pi*fstop/fs, where fp, fstop and fs are the passband, stop band
and sampling frequencies in Hz
 Step 4: Compute the Impulse Response h(n) of the required FIR filter using N, selected
window, type of response(low/high,etc) using ‘fir1’ as in step 2 of method 1.

IMPLEMENTATION OF THE FIR FILTER


1. Once the coefficients of the FIR filter h[n] are obtained, the next step is to simulate an
input sequence x[n], say input of 100, 200 & 400 Hz (with sampling frequency of fs),
each of 20/30 points. Choose the frequencies such that they are >, < and = to fc.
2. Convolve input sequence x[n] with Impulse Response, i.e., x (n)*h (n) to obtain the
output of the filter y[n]. We can also use the ‘filter’ command.
3. Infer the working of the filter (low pass/ high pass, etc).
MATLAB IMPLEMENTATION
FIR1 Function
B = FIR1(N,Wn) designs an N'th order lowpass FIR digital filter and returns the filter
coefficients in length N+1 vector B. The cut-off frequency Wn must be between 0 < Wn < 1.0,
with 1.0 corresponding to half the sample rate. The filter B is real and has linear phase, i.e.,
even symmetric coefficients obeying B(k) = B(N+2-k), k = 1,2,...,N+1.
If Wn is a two-element vector, Wn = [W1 W2], FIR1 returns an order N bandpass filter with
passband W1 < W < W2. B = FIR1(N,Wn,'high') designs a highpass filter. B = FIR1(N,Wn,'stop')
is a bandstop filter if Wn = [W1 W2]. If Wn is a multi-element vector, Wn = [W1 W2 W3
W4 W5 ... WN], FIR1 returns an order N multiband filter with bands
0 < W < W1, W1 < W < W2, ..., WN < W < 1.
FREQZ Digital filter frequency response. [H,W] = FREQZ(B,A,N) returns the N-point complex
frequency response vector H and the N-point frequency vector W in radians/sample of the
filter whose numerator and denominator coefficients are in vectors B and A. The frequency
response is evaluated at N points equally spaced around the upper half of the unit circle. If N
isn't specified, it defaults to 512.
For FIR filter enter A=1 and B = h[n] coefficients. Appropriately choose N as 128, 256, etc

Dept. of ECE, Dr.AIT


27
Digital Signal Processing Lab Manual -- 18ECL57 V semester
Table: Commonly used window function characteristics
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

Matlab Program

%Design and implementation of FIR filter Method 1

%Matlab program to plot frequency response of FIR filter using window method

% Method 1 - To Design a Low Pass FIR Filter


N=input('Enter the window length = ');
fc=input('Enter the cut-off frequency = ');
fs=input('Enter the sampling frequency = ');
wc=2*fc/fs;
wh=(hamming(N));
b=fir1(N-1,wc,wh);
[h,omega]=freqz(b,1,256);
mag=20*log10(abs(h));
plot(omega/pi,mag);
grid on;
xlabel('Frequency in radians in terms of pi');
ylabel('Gain in dB');
title('Response of FIR Filter using Hamming Window');
disp('Hamming window coefficients');
disp(wh);
disp('FIR Filter output');
disp(b);
Result:

Dept. of ECE, Dr.AIT


28
Digital Signal Processing Lab Manual -- 18ECL57 V semester

Enter the window length= 27


Enter the cutoff frequency= 100
Enter the sampling frequency= 1000

Hamming Window Coefficients:


wh=
0.080000000000000
0.093366763984016
0.132690228199523
0.195685055841294
0.278690216503668
0.376881751960434
0.484553127082551
0.595446872917449
0.703118248039566
0.801309783496332
0.884314944158707
0.947309771800477
0.986633236015984
1.000000000000000
0.986633236015984
0.947309771800477
0.884314944158707
0.801309783496332
0.703118248039566
0.595446872917449
0.484553127082551
0.376881751960434
0.278690216503668
0.195685055841294
0.132690228199523
0.093366763984016
0.080000000000000

FIR Filter output


Columns 1 through 5
0.001857013100866 0.002347898907031 0.002249712122493 -0.000000000000000
-0.005775105285073

Columns 6 through 10
-0.014216197752006 -0.020888713510276 -0.018508552753882 0.000000000000000
0.037361228367975

Columns 11 through 15
0.088951656982208 0.142932290865991 0.184007885117237 0.199361767674871
0.184007885117237

Columns 16 through 20
0.142932290865991 0.088951656982208 0.037361228367975 0.000000000000000 -
0.018508552753882

Dept. of ECE, Dr.AIT


29
Digital Signal Processing Lab Manual -- 18ECL57 V semester

Columns 21 through 25
-0.020888713510276 -0.014216197752006 -0.005775105285073 -0.000000000000000
0.002249712122493

Columns 26 through 27
0.002347898907031 0.001857013100866

Waveforms:

Fig.6.1 Frequency response of FIR filter

%Method 2:
% Method 2 -To Design a Low Pass FIR Filter
wp=input('Passband frequency = ');
ws=input('Stopband frequency = ');
wt=ws-wp;
N=(8/wt)+1;
N=round(N);
wh=(hamming(N));
b=fir1(N-1,wp,wh);
disp('Impulse response coefficients = ');
disp(b);
freqz(b);
title('Response of FIR filter using Hamming window');

Result:
Save and execute the program;
Passband frequency=0.3
Stopband frequency=0.45

Dept. of ECE, Dr.AIT


30
Digital Signal Processing Lab Manual -- 18ECL57 V semester
-->N
N =
54.
Impulse response coefficients=
Columns 1 through 5
-0.000150596693980 -0.000927369218648 -0.001077027026241 -0.000230929963532
0.001310414732772
Columns 6 through 10
0.002321542745064 0.001352702269338 -0.001703917343871 -0.004627895800660
-0.004096355673902
Columns 11 through 15
0.001109927500011 0.007676138278529 0.009250596565612 0.001945035747221 -
0.010477917130223
Columns 16 through 20
-0.017384563571371 -0.009476717665668 0.011243935576771 0.029108414960694
0.024949233108580
Columns 21 through 25
-0.006677345466557 -0.046785291314340 -0.059104459303807 -0.013696567665346
0.088386377724377
Columns 26 through 30
0.208451836771282 0.289310797857893 0.289310797857893 0.208451836771282
0.088386377724377
Columns 31 through 35
-0.013696567665346 -0.059104459303807 -0.046785291314340 -0.006677345466557
0.024949233108580
Columns 36 through 40
0.029108414960694 0.011243935576771 -0.009476717665668 -0.017384563571371
-0.010477917130223
Columns 41 through 45
0.001945035747221 0.009250596565612 0.007676138278529 0.001109927500011 -
0.004096355673902
Columns 46 through 50
-0.004627895800660 -0.001703917343871 0.001352702269338 0.002321542745064
0.001310414732772
Columns 51 through 54
-0.000230929963532 -0.001077027026241 -0.000927369218648 -0.000150596693980

Dept. of ECE, Dr.AIT


31
Digital Signal Processing Lab Manual -- 18ECL57 V semester

Fig. 6.2. FIR Filter Response


Exercise:
Design a FIR filter to meet the following specifications:
Generate filter coefficients for the given order & cutoff Say N=33, fc=150Hz, fs=1000 Hz,
Hamming window

Ans:

Dept. of ECE, Dr.AIT


32
Digital Signal Processing Lab Manual -- 18ECL57 V semester
EXPERIMENT NO 7. Design and implementation of IIR filter to meet given
specifications

Aim: To find order of LP Butterworth IIR filter and to plot frequency response

Method I:

Given the order N, cutoff frequency fc, sampling frequency fs and the IIR filter type
(butterworth, cheby1, cheby2).
 Step 1: Compute the digital cut-off frequency Wc (in the range -π < Wc < π, with π
corresponding to fs/2) for fc and fs in Hz. For example let fc=400Hz, fs=8000Hz
Wc = 2*π* fc / fs = 2* π * 400/8000 = 0.1* π radians
For MATLAB the Normalized cut-off frequency is in the range 0 and 1, where 1 corresponds
to fs/2 (i.e.,fmax)). Hence to use the MATLAB commands
wc = fc / (fs/2) = 400/(8000/2) = 0.1
Note: if the cut off frequency is in radians then the normalized frequency is computed as
wc = Wc / π
 Step 2: Compute the Impulse Response [b,a] coefficients of the required IIR filter and the
response type (lowpass, bandpass, etc) using the appropriate butter, cheby1, cheby2
command. For example given a butterworth filter, order N=2, and a high pass response, the
coefficients [b,a] of the filter are computed using the MATLAB inbuilt command ‘butter’ as
[b,a] =butter(N, wc , 'high');

Method 2:

Given the pass band (Wp in radians) and Stop band edge (Ws in radians) frequencies,
Pass band ripple Rp and stopband attenuation As.
 Step 1: Since the frequencies are in radians divide by π to obtain normalized
frequencies to get wp=Wp/pi and ws=Ws/pi
If the frequencies are in Hz (note: in this case the sampling frequency should be
given), then obtain normalized frequencies as wp=fp/(fs/2), ws=fstop/(fs/2), where
fp, fstop and fs are the passband, stop band and sampling frequencies in Hz
 Step 2: Compute the order and cut off frequency as
[N, wc] = BUTTORD(wp, ws, Rp, Rs)
 Step 3: Compute the Impulse Response [b,a] coefficients of the required IIR filter and
the response type as [b,a] =butter(N, wc , 'high');

Dept. of ECE, Dr.AIT


33
Digital Signal Processing Lab Manual -- 18ECL57 V semester

IMPLEMENTATION OF THE IIR FILTER

1. Once the coefficients of the IIR filter [b,a] are obtained, the next step is to simulate an
input sequence x[n], say input of 100, 200 & 400 Hz (with sampling frequency of fs),
each of 20/30 points. Choose the frequencies such that they are >, < and = to fc.
2. Filter the input sequence x[n] with Impulse Response, to obtain the output of the filter
y[n] using the ‘filter’ command.
3. Infer the working of the filter (low pass/ high pass, etc).

MATLAB IMPLEMENTATION
BUTTORD Butterworth filter order selection.
[N, Wn] = BUTTORD(Wp, Ws, Rp, Rs) returns the order N of the lowest order digital
Butterworth filter that loses no more than Rp dB in the passband and has at least Rs dB of
attenuation in the stopband. Wp and Ws are the passband and stopband edge frequencies,
normalized from 0 to 1 (where 1 corresponds to pi radians/sample). For example,
Lowpass: Wp = .1, Ws = .2 Highpass: Wp = .2, Ws = .1
Bandpass: Wp = [.2 .7], Ws = [.1 .8] Bandstop: Wp = [.1 .8], Ws = [.2 .7]
BUTTORD also returns Wn, the Butterworth natural frequency (or, the "3 dB frequency") to
use with BUTTER to achieve the specifications.
[N, Wn] = BUTTORD(Wp, Ws, Rp, Rs, 's') does the computation for an analog filter, in which
case Wp and Ws are in radians/second.
When Rp is chosen as 3 dB, the Wn in BUTTER is equal to Wp in BUTTORD.

BUTTER Butterworth digital and analog filter design.


[B,A] = BUTTER(N,Wn) designs an Nth order lowpass digital Butterworth filter and returns
the filter coefficients in length N+1 vectors B (numerator) and A (denominator). The
coefficients are listed in descending powers of z. The cutoff frequency Wn must be 0.0 < Wn <
1.0, with 1.0 corresponding to half the sample rate. If Wn is a two-element vector, Wn = [W1
W2], BUTTER returns an order 2N bandpass filter with passband W1 < W < W2. [B,A] =
BUTTER(N,Wn,'high') designs a highpass filter. [B,A] = BUTTER(N,Wn,'stop') is a bandstop
filter if Wn = [W1 W2].
BUTTER(N,Wn,'s'), BUTTER(N,Wn,'high','s') and BUTTER(N,Wn,'stop','s') design analog
Butterworth filters. In this case, Wn is in [rad/s] and it can be greater than 1.0.

Dept. of ECE, Dr.AIT


34
Digital Signal Processing Lab Manual -- 18ECL57 V semester
Matlab Program (Design & implementation)

%Matlab program to plot frequency response of Butterworth LP IIR filter

f1=input('Enter the Passband frequency f1 = ');


f2=input('Enter the Stopband frequency f2 = ');
fs=input('Enter Sampling frequency fs = ');
k1=input('Enter the Passband attenuation k1 = ');
k2=input('Enter the Stopband attenuation k2 = ');

%Calculation part
w1=2*f1/fs;
w2=2*f2/fs;
[n,wn]=buttord(w1,w2,k1,k2);
[b,a]=butter(n,wn);
freqz(b,a);
grid on;
title('Butterworth Filter Frequency Response');

%Graphical display part


disp('Order of the filter is = ');
disp('n=');disp(n);
disp('wn=');disp(wn);
disp('Numerator coefficients b = ');
disp(b);
disp('Denominator coefficients a = ');
disp(a);

Result:

Enter the Passband frequency f1=1500


Enter the stopband frequency f2=2000
Enter Sampling frequency fs=8000
Enter the Passband attenuation k1=1
Enter the Stopband attenuation k2=15

Order of the filter is=


n=

Dept. of ECE, Dr.AIT


35
Digital Signal Processing Lab Manual -- 18ECL57 V semester
6

wn=
0.410440972699444
Numerator coefficients b=
Columns 1 through 5
0.011653932946109 0.069923597676657 0.174808994191642 0.233078658922190
0.174808994191642

Columns 6 through 7
0.069923597676657 0.011653932946109

Denominator coefficients a=
Columns 1 through 5
1.000000000000000 -1.063463131405513 1.200505288359735 -0.583591594317949
0.231817249706670

Columns 6 through 7
-0.043710924415157 0.004294820623221wn=
0.4104

Fig.7. Frequency of IIR Butterworth Filter

Exercise:
Design an IIR Butterworth LP filter to meet the following specifications:
Pass band edge (Hz) =1000 Hz
Stop band edge (Hz) = 3000 Hz
Pass band attenuation (dB) = - 1
Stop band attenuation (dB) = -15
Sampling rate (Hz) = 10000 Hz

Ans: Order of the filter n = 2,


0.2928932 + 0.5857864z + 0.2928932z2
H(z) = -----------------------------------
0.1715729 + 5.551D-17z + z2

Dept. of ECE, Dr.AIT


36
Digital Signal Processing Lab Manual -- 18ECL57 V semester
EXPERIMENT NO 8. Design and implementation of IIR Chebyshev filter

Aim: To find order of LP Chebyshev IIR filter and to plot frequency response

Chebyshev filters are analog or digital filters having a steeper roll-off and more passband
ripple (type I) or stopband ripple (type II) than Butterworth filters. Chebyshev filters have the
property that they minimize the error between the idealized and the actual filter characteristic
over the range of the filter, but with ripples in the passband.

Matlab Program (Design & implementation)

% Matlab program to plot frequency response of Chebyshev LP IIR filter

f1=input('Enter Passband frequency f1 = ');


f2=input('Enter Stopband frequency f2 = ');
fs=input('Enter Sampling frequency fs = ');
k1=input('Enter Passband attenuation k1 = ');
k2=input('Enter Stopband attenuation k2 = ');

%Calculation part
w1=2*f1/fs;
w2=2*f2/fs;
[n,wn]=cheb1ord(w1,w2,k1,k2);
[b,a]=cheby1(n,k1,wn);
freqz(b,a);
grid on;
title('Chebychev Filter Frequency Response');

%Graphical display part


disp('Order of the filter is n =');
disp(n);
disp('wn = ');
disp(wn);
disp('Numerator coefficients b = ');
disp(b);

Dept. of ECE, Dr.AIT


37
Digital Signal Processing Lab Manual -- 18ECL57 V semester
disp('Denominator coefficients a = ');
disp(a);

Result:
Save and execute the program;
RESULT:
Enter Passband frequency f1 = 1500
Enter Stopband frequency f2 = 2000
Enter Sampling frequency fs = 8000
Enter Passband attenuation k1 = 1
Enter Stopband attenuation k2 = 15

Order of the filter is n =


4
wn=
0.375000000000000
Numerator coefficients b=
0.019110493234620 0.076441972938480 0.114662959407719 0.076441972938480
0.019110493234620

Denominator coefficients a=
1.000000000000000 -1.799381978282539 1.963665269278695 -1.151337941252095
0.33013186753684

Fig.8. IIR Chebyshev Filter Response

Exercise:
Design an IIR Chebyshev LP filter to meet the following specifications:

f1 = Pass band edge (Hz) =1000 Hz


f2 = Stop band edge (Hz) = 3000 Hz
rp = Pass band ripple (dB) = - 1
rs = Stop band attenuation (dB) = -15
Dept. of ECE, Dr.AIT
38
Digital Signal Processing Lab Manual -- 18ECL57 V semester
fs = Sampling rate (Hz) = 10000 Hz

Ans: Order of the filter n = 2,


0.2928932 + 0.5857864z + 0.2928932z2
H(z) = -----------------------------------
0.1715729 + 5.551D-17z +

Dept. of ECE, Dr.AIT


39
Digital Signal Processing Lab Manual -- 18ECL57 V semester

Part B

Hardware programs using TMS320C6713 DSK

Dept. of ECE, Dr.AIT


40
Digital Signal Processing Lab Manual -- 18ECL57 V semester

CCS INTRODUCTION
TMS320C6713 DSK and Code Composer Studio
1. Introduction
The hardware experiments in the DSP lab are carried out on the Texas Instruments
TMS320C6713 DSP Starter Kit (DSK), based on the TMS320C6713 floating point DSP running
at 225 MHz. The basic clock cycle instruction time is 1/(225 MHz)= 4.44 nanoseconds. During
each clock cycle, up to eight instructions can be carried out in parallel, achieving up to 8×225
= 1800 million instructions per second (MIPS).
The C6713 processor has 256KB of internal memory, and can potentially address 4GB
of external memory. The DSK board includes a 16MB SDRAM memory and a 512KB Flash ROM.
It has an on-board 16-bit audio stereo codec (the Texas Instruments AIC23B) that serves both
as an A/D and a D/A converter. There are four 3.5 mm audio jacks for microphone and stereo
line input, and speaker and head-phone outputs. The AIC23 codec can be programmed to
sample audio inputs at the following sampling rates:
fs = 8, 16, 24, 32, 44.1, 48, 96 kHz
The ADC part of the codec is implemented as a multi-bit third-order noise-shaping
delta-sigma converter that allows a variety of oversampling ratios that can realize the above
choices of fs. The corresponding oversampling decimation filters act as anti-aliasing pre-filters
that limit the spectrum of the input analog signals effectively to the Nyquist interval [−fs/2,
fs/2]. The DAC part is similarly implemented as a multi-bit second-order noise-shaping delta-
sigma converter whose oversampling interpolation filters act as almost ideal reconstruction
filters with the Nyquist interval as their passband.
The DSK also has four user-programmable DIP switches and four LEDs that can be used
to control and monitor programs running on the DSP.
All features of the DSK are managed by the CCS, which is a complete integrated development
environment (IDE) that includes an optimizing C/C++ compiler, assembler, linker, debugger,
and program loader. The CCS communicates with the DSK via a USB connection to a PC. In
addition to facilitating all programming aspects of the C6713 DSP, the CCS can also read signals
stored on the DSP’s memory, or the SDRAM, and plot them in the time or frequency domains.
The following block diagram depicts the overall operations involved in all of the
hardware experiments in the DSP lab. Processing is interrupt-driven at the sampling rate fs,
as explained below.

Dept. of ECE, Dr.AIT


41
Digital Signal Processing Lab Manual -- 18ECL57 V semester

The AIC23 codec is configured (through CCS) to operate at one of the above sampling
rates fs. Each collected sample is converted to a 16-bit two’s complement integer (a short data
type in C). The codec actually samples the audio input in stereo, that is, it collects two samples
for the left and right channels.
At each sampling instant, the codec combines the two 16-bit left/right samples into a
single 32-bit unsigned integer word (an unsigned int, or Uint32 data type in C), and ships it
over to a 32-bit receive register of the multichannel buffered serial port (McBSP) of the C6713
processor, and then issues an interrupt to the processor.
Upon receiving the interrupt, the processor executes an interrupt service routine (ISR)
that implements a desired sample processing algorithm programmed with the CCS (e.g.,
filtering, audio effects, etc.). During the ISR, the following actions take place: the 32-bit input
sample (denoted by x in the diagram) is read from the McBSP, and sent into the sample
processing algorithm that computes the corresponding 32-bit output word (denoted by y),
which is then written back into a 32-bit transmit-register of the McBSP, from where it is
transferred to the codec and reconstructed into analog format, and finally the ISR returns from
interrupt, and the processor begins waiting for the next interrupt, which will come at the next
sampling instant. Clearly, all processing operations during the execution of the ISR must be
completed in the time interval between samples, that is, T = 1/fs. For example, if fs = 44.1 kHz,
then, T = 1/fs = 22.68 μsec. With an instruction cycle time of Tc = 4.44 nsec, this allows T/Tc =
5108 cycles to be executed during each sampling instant, or, up to 8×5108 = 40864
instructions, or half of that per channel.

Dept. of ECE, Dr.AIT


42
Digital Signal Processing Lab Manual -- 18ECL57 V semester

Dept. of ECE, Dr.AIT


43
Digital Signal Processing Lab Manual -- 18ECL57 V semester
Lab Tasks
In this lab, you will learn how to use some basic features of the Code Composer Studio (CCS), such as
creating projects, compiling and linking them to the run-time libraries, loading them for execution on
the DSP chip, using GEL files for changing program parameters during run-time.

2. Getting started with CCS:

STEP - 1: CCS Initial settings


1. Double click on CCS icon on desktop.

2. Then Code Composer Studio Setup dialogue box appears.

NOTE: You can do this alternatively by following the below mentioned steps

Fig : Code Composer Studio Setup dialogue box

STEP – 2: To create new project

1. Select PROJECT> New. Project Creation wizard appears.

2. Select Target>6713 >TMS3206713

3. Select CONNECTION> spectrum digital dsk-evm-ezdsp onboard usb emulator

4. Type Project Name (Ex: example1) in the Project Name Field.

5. Click on Use default location check box, this project will be stored in the location default
location

6. Select Compiler version>T1 V7.4.7>FINISH

NOTE: In the location field do not change the default path. This avoids misplacing of your projects.

Dept. of ECE, Dr.AIT


44
Digital Signal Processing Lab Manual -- 18ECL57 V semester

STEP – 3: To create a new source file perform the following steps

1. File > New > Source File

Type in your program in this new source file and save as ‘main.c’ in the folder where your project will
be saved

STEP – 4: Connection to TMS6713 kit

1. Connect 5v power card to kit.

2. Connect USB port of Kit to CPU to establish hardware connection.

3. Select DEBUG > CONNECT in CCstudio window to verify connections

STEP – 5: Run the program

1. Then select Project> Build to build your project successfully.

2. Perform the following steps to execute your program

3. Select Debug > Run to run your program.

4. Observe the program output in the Output Window.

5. To view waveforms, select CCS Edit >Expression window

6. Right click on Expression >Add variable>type output variable (ex. y)

Dept. of ECE, Dr.AIT


45
Digital Signal Processing Lab Manual -- 18ECL57 V semester
7. After adding output variable right click on output variable >View > Graph

Step 6: Changes in graph property dialog box to be made

1. Display type  Dual (to observe 2 waveforms)


2. Title  User defined
3. Start address – upper display  x (user defined variable array names used in C
program. Note: x, y should be made global to be used by graph)
4. Start address – lower display  y
5. Acquisition Buffer size  60 (depends on the array size)
6. Display Buffer size  60
7. DSP data type – 32-bit Floating pt
8. Auto scale  ON (if off  choose max value=1)

Expression
Window
Project
Window

Editor
Window

Output Graph
Window
Window

Dept. of ECE, Dr.AIT


46
Digital Signal Processing Lab Manual -- 18ECL57 V semester
EXPERIMENT NO 1

Aim: To perform linear convolution for the given sequences


 
The linear convolution sum is y[n]  x[n]  h[n]   x[k ]h[n  k ] 
k  
 x[n  k ]h[k ]
k  

C Program
#include<stdio.h>

int y[12];

main()
{
int m=6; /*Lenght of i/p samples sequence*/
int n=6; /*Lenght of impulse response Co-efficients */
int i=0,j;
int x[15]={1,2,3,4,5,6}; /*Input Signal Samples*/
int h[15]={1,2,3,4,5,6}; /*Impulse Response Co-efficients*/

for(i=0;i<m+n-1;i++)
{
y[i]=0;
for(j=0;j<=i;j++)

y[i]+=x[j]*h[i-j];

for(i=0;i<m+n-1;i++)
printf("%d\n",y[i]);

Dept. of ECE, Dr.AIT


47
Digital Signal Processing Lab Manual -- 18ECL57 V semester
Result:
The output plot is shown in Fig.1

Fig.1: Linear convolution

Dept. of ECE, Dr.AIT


48
Digital Signal Processing Lab Manual -- 18ECL57 V semester
EXPERIMENT NO 2

Aim: To perform circular convolution of two given sequences

 h[k ]x n  k 

The circular convolution sum is y[n]  x[n] N h[n]  N
k  

C Program

#include<stdio.h>
#include<math.h>
float x[5]={1,2,3,4,5};
float h[5]={2,1,3,4,5};
float y[10];
main()
{
int N=5;
int k,n,i;
for(n=0;n<N;n++)
{
y[n]=0;
for(k=0;k<N;k++)
{
i=(n-k)%N;
if(i<0)
i=i+N;
y[n]=y[n]+h[k]*x[i];
}
printf("%f\t",y[n]);
}
}
Result

41.000000 51.000000 51.000000 46.000000 36.000000


Verify with MATLAB / theoretical verification

Dept. of ECE, Dr.AIT


49
Digital Signal Processing Lab Manual -- 18ECL57 V semester
The output plot is shown in Fig.2

Fig.2: Circular convolution

Dept. of ECE, Dr.AIT


50
Digital Signal Processing Lab Manual -- 18ECL57 V semester
EXPERIMENT NO: 3: Impulse response of first order and second order system

Aim: To obtain Impulse response of a given system described by the following


differential equation using DSP 6713.
y[n] - 1.143*y[n-1] + 0.4128*y[n-1-2] = 0.0675*x[n] + 0.1349*x [n-1] + 0.0675*x[n-2]

C Program
#include<stdio.h>
float x[20],y[20],y1[20];
main()
{
float a1,a2,b0,b1,b2;
int i,j,N=20;
a1=-1.1430;a2=0.4128;
b0=0.0675;b1=0.1349;b2=0.0675;
x[0]=1;
for(i=1;i<N;i++)
{
x[i]=0;
}
for(j=0;j<N;j++)
{
y[j]=b0*x[j];
if(j>0)
y[j]=y[j]+b1*x[j-1]-a1*y[j-1];
if((j-1)>0)
y1[j]=y[j]+b2*x[j-2]-a2*y[j-2];
printf("%f\t",y[j]);
printf("%f\n",y1[j]);
}
}

The first order output plot is shown in Fig.3.1

Dept. of ECE, Dr.AIT


51
Digital Signal Processing Lab Manual -- 18ECL57 V semester

Fig 3.1: Impulse response of 1st order

Dept. of ECE, Dr.AIT


52
Digital Signal Processing Lab Manual -- 18ECL57 V semester
Result (on std out)
0.067500 0.212053 0.282012 0.234804 0.151967 0.076771 0.025017 -0.003096
-0.013866 -0.014571 -0.010931 -0.006479 -0.002893 -0.000632 0.000471 0.000800
0.000720 0.000492 0.000266 0.000100

The second order output plot is shown in Fig.3.2

Fig. 3.2. Impulse response of 2nd order

Dept. of ECE, Dr.AIT


53
Digital Signal Processing Lab Manual -- 18ECL57 V semester
EXPERIMENT 4: To compute N-point DFT of two given sequences

Aim: To compute N-point DFT of sequences and to plot magnitude spectrum


using DSP 6713.

Theory:
 Discrete Fourier Transform (DFT) is used for performing frequency analysis of
discrete time signals. DFT gives a discrete frequency domain representation whereas
the other transforms are continuous in frequency domain.
 The N point DFT of discrete time signal x[n] is given by the equation
N -1  j 2kn

X (k )   x[n]e N
; k  0,1,2,....N - 1
n 0
Where N is chosen such that N  L , where L=length of x[n].
 The inverse DFT allows us to recover the sequence x[n] from the frequency samples.
j 2kn
1 N 1
x[n]   x[n]e N ; n  0,1,2,....N - 1
N k 0
 X(k) is a complex number (remember ejw=cosw + jsinw). It has both magnitude and
phase which are plotted versus k. These plots are magnitude and phase spectrum of
x[n]. The ‘k’ gives us the frequency information.
 Here k=N in the frequency domain corresponds to sampling frequency (fs). Increasing
N, increases the frequency resolution, i.e., it improves the spectral characteristics of the
sequence. For example if fs=8kHz and N=8 point DFT, then in the resulting spectrum,
k=1 corresponds to 1kHz frequency. For the same fs and x[n], if N=80 point DFT is
computed, then in the resulting spectrum, k=1 corresponds to 100Hz frequency. Hence,
the resolution in frequency is increased.

Algorithm
1. Input the sequence for which DFT is to be computed.
2. Input the length of the DFT required (say 4, 8, >length of the sequence).
3. Compute the DFT using the ‘fft’ command.
4. Plot the magnitude & phase spectra.

C Program
#include<stdio.h>

#include<math.h>

float y[16];

float x[4]={1,3,2,5};

float w;

main()

Dept. of ECE, Dr.AIT


54
Digital Signal Processing Lab Manual -- 18ECL57 V semester
int n,k,k1,N=8,xlen=4;

for(k=0;k<2*N;k=k+2)

y[k]=0;y[k+1]=0;

k1=k/2;

for(n=0;n<xlen;n++)

w=-2*3.14*k1*n/N;

y[k]=y[k]+x[n]*cos(w);

y[k+1]=y[k+1]+x[n]*sin(w);

printf("%f+j%f\n",y[k],y[k+1]);

Result

Dept. of ECE, Dr.AIT


55
Digital Signal Processing Lab Manual -- 18ECL57 V semester

Fig.4: N-point DFT

Dept. of ECE, Dr.AIT


56
Digital Signal Processing Lab Manual -- 18ECL57 V semester

Part C

Virtual Laboratory

Dept. of ECE, Dr.AIT


57
Digital Signal Processing Lab Manual -- 18ECL57 V semester
PART – C: Virtual Laboratory

Virtual laboratory

Introduction:

The DSP Virtual Laboratory is an initiative of Ministry of Human Resource Development


(MHRD), Govt. of India, under the National Mission on Education through Information and
Communication Technology (NME-ICT).
Laboratory courses on hands-on experiments are an integral part of engineering education.
The content of this website aims to provide a virtual laboratory platform for undergraduate
Engineering students studying the course of Digital Signal Processing.

Dept. of ECE, Dr.AIT


58
Digital Signal Processing Lab Manual -- 18ECL57 V semester
EXPERIMENT NO 1. Study of sampling theorem, effect of under sampling.

Theory:

The real life signals that we encounter in our day to day basis are mostly analog signals. These
signals are defined continuously in time and have infinite range of amplitude values. In order
to process these signals to obtain meaningful information, they need to be converted to a
format which is easily handled by computing resources like microprocessors, computers etc...
The first step in this process is to convert the real-time signal into discrete-time signals.
Discrete-time signals are defined only at a particular set of time instances. They can thus be
represented as sequence of numbers with continuous range of values.
The process of converting an analog signal (denoted as x(t)) to a digital signal (denoted as
x(n)) is called the analog-to-digital conversion (referred to as digitization), usually performed
by an analog-to-digital converter (ADC). Here t is the continuous time variable and n is the
sequence order. In many applications after the processing of the digital signal is performed,
x(n) needs to be converted back to analog signal x(t) before it is applied to appropriate analog
device. This reverse process is called digital-to-analog conversion and is typically performed
using a digital-to-analog converter (DAC).
The typical block diagram of an ADC is shown in Fig. 1 below.

The process of digitization consists of first sampling (digitization in time) and quantization
(digitization in amplitude). In this experiment we will study and understand the principle of
sampling, while the principle of quantization will be studied in the next experiment. The
sampling process depicts an analog signal as a sequence of values. The basic sampling function
can be carried out with an ideal 'sample-and-hold' circuit which maintains the sampled signal
until next sample is taken. An ideal sampler can be considered as a switch that periodically
opens and closes every T seconds. The sampling frequency (fs in Hertz) is thus defined as
fs=1T....(1)
The sampled discrete time signal x(nT) , n=0,1,2,.... of the original continuous time signal x(t)
is shown in Fig. 2 below.

In order to represent an analog signal x(t) by a discrete-time signal x(nT) accurately, so that
the analog signal can be exactly reconstructed back from the discrete-time signal, the sampling
frequency fs must be at least twice the maximum frequency component (fM) of the original
analog signal. Thus we have,

Dept. of ECE, Dr.AIT


59
Digital Signal Processing Lab Manual -- 18ECL57 V semester
fs≥2fm....(2)
The minimum sampling rate is called the Nyquist rate and the above Sampling Theorem is
called the Shannon's Sampling Theorem. When an analog signal is sampled at fs , frequency
components higher than fs/2 fold back into the frequency range [0, fs/2]. This folded
frequency components overlap with the original frequency components in the same range and
leads to an undesired effect known as aliasing. In this case, the original analog signal cannot
be recovered from the sample data.
Consider an analog signal of frequency 1Hz as shown in Fig. 3(a) below. The sampling
frequency is 4Hz. The sampled signal is shown in Fig. 3(b), Note that an exact reconstruction
of the missing samples is obtained so long as the Shannon's Sampling Theorem is satisfied.

Now let's consider, the analog signal of frequency 5Hz as shown in Fig. 4(a) below. The
sampling frequency is same as above, i.e. 4Hz. The sampled signal is shown in Fig. 4(b), Note
that the reconstruction of the original analog signal is not possible since the sampling
frequency does not satisfy Shannon's Sampling Theorem. In this case the reconstructed signal
has a frequency of 1Hz. The signal of 5Hz is folded back as 1Hz, into the range determined by
the sampling frequency leading to the problem of aliasing.

Procedure:
1. Click on the Experiment tab SIMULATOR, it will open the workspace.
2. See the movie in experiment page by pressing help button ? to understand how the following
steps are to be executed.
3. In the workspace click on Browse Blocks BROWSE BLOCKS.to understand how the
following steps are to be executed.
4. Drag Sinewave Generator in the left side of the workspace. Click it to parameterize the
sinusoidal signal output. Make amplitude = 3V, frequency = 19 Hz, phase=0 angle.

Dept. of ECE, Dr.AIT


60
Digital Signal Processing Lab Manual -- 18ECL57 V semester

5. Drag Sampling Block in the workplace. Place it after Sinewave Generator to its right. Click it
to parameterize. Make sampling frequency =40 Hz. It will show no. of sample as 80 for display.
The display is conformed for 2 sec.

6. Drag the scope in the workspace after sampler to its right.


7. For making connection, take the cursor to the node provided in each block where form
connection is to be made. Click on it a circle will appear in the background. If pointed properly
a yellowish tinge will appear click at that time to enable connection.

8. Connect sinewave generator O/P to I/O of sampler by clicking at both blocks and a link will
appear.
9. Similarly connect sampler O/P to one of the I/O of scope.
10. Click somewhere in the middle of the link connecting signal generator & sampler. Keep
clicking at bends till you connect it to the other input of the scope.

Dept. of ECE, Dr.AIT


61
Digital Signal Processing Lab Manual -- 18ECL57 V semester

11. Click on the scope, a new window will appear. It shows that the sinusoidal signal as well as
sample in red dots.

12. Move the cursor from one sample to another by dragging the slider provide along the x-
axis and you will find sample values in the boxes at bottom left part of the window. Note the
first 15 values in a note book. This 15 values will go as table 1 in your report.
13. In this window, you can change parameters like frequency, amplitude and phase angle of
sinusoidal signal generator & sampling frequency.
14. Change the sinusoidal signal generator O/P amplitude to 1.5V and note 1st 15 values. This
will form Table 2 in your report. In your observation & discussion part of the reporting, you
have to compare Table 1 and Table 2.
15. Change sampling frequency to 43 Hz and amplitude of sinusoidal signal generator at 1V.
Note first 15 readings to from Table 3. Compare Table 1 and Table 3
16. Make sampling frequency 40Hz, amplitude of sinusoidal signal generator 10V, phase=30.
Table 1st reading to from Table 4. Compare Table 1 and Table 4.

Dept. of ECE, Dr.AIT


62
Digital Signal Processing Lab Manual -- 18ECL57 V semester
17. Under sampling: Change the Sinusoidal signal generator frequency 50Hz, amplitude 1.4V,
phase=0. Sampling frequency= 40 Hz. Take 1st 15 readings. This will from Table 5. Compare
Table 1 and Table 5.
18. Change the Sinusoidal signal generator frequency=30Hz, Amplitude=1V, Phase=0, sampling
frequency = 40Hz. Take 15 readings. This will produce Table 6. Compare Table 1 and Table 6
19. Optional: Select sinusoidal signal generator frequency and sampling frequency
simultaneously to form more Table, Table 7 and Table 8 which leads to nyquist rate from
observation phenomenon.
20. Click on Report Generation button. The reporting window will appear. Here on by clicking
Add Table, you can add tables. In each tables, by clicking add row will be able to add row.
21. For each table make a screenshot of your plots by taking print screen and edit in any image
editor to upload a image for each table.
22. The observation and discussion box, appears at the end. Then click, Yes I have finished my
Experiment button to submit your report.
23. Note: if at any time during making circuit if you face any problem please use reset button
to erase the circuit and draw the circuit freshly.

Dept. of ECE, Dr.AIT


63
Digital Signal Processing Lab Manual -- 18ECL57 V semester
EXPERIMENT NO 2. Study of DFT and its inverse

Theory:
The discrete-time Fourier transform (DTFT) of a sequence is a continuous function of ω, and
repeats with period 2π In practice we usually want to obtain the Fourier components using
digital computation, and can only evaluate them for a discrete set of frequencies. The discrete
Fourier transform (DFT) provides a means for achieving this .
The DFT is itself a sequence, and it corresponds roughly to samples, equally spaced in
frequency, of the Fourier transform of the signal. The discrete Fourier transform of a length N
signal x[n], n = 0, 1... N - 1 is given by

This is the analysis equation. The corresponding inverse equation is

Procedure:
1. Click on the simulator tab SIMULATOR, it will open the workspace.
2. See the movie in experiment page by pressing help button ? to understand how the following
steps are to be executed.
3. Workspace provides three user controls to visualize the DFT and inverse DFT: signal
selector, a slider to set the input signal no. of samples and another slider to set the DFT no. of
points.

Fig-1
4. Select rectangular signal first and set the no. of samples in input signal to 8 also DFT points
to 8. The input signal plot will be be shown in Graph 1.
5. Now observe the magnitude and spectrum of the signal after applying DFT in Graph no. 2
and 3. Simultaneously in Graph 4 will show the signal after inverse DFT.

Dept. of ECE, Dr.AIT


64
Digital Signal Processing Lab Manual -- 18ECL57 V semester

Fig-2
6. Note down the values of No. of samples in input signal, DFT points and first 10 to 15 values
of Graph 1, 2, 3 and 4 which will give you table no. 1 of report generations
7. Now repeat step 4 to 6 for other two types of input signals and take the reading which will
give you table 2 and 3.
8. Then set value of no. of DFT points to 16 and choose ramp signal as input, see the changes
in the magnitude and phase spectrum of the signal

Fig-3
9. Take the reading which will give you table 4 and observe the graphs and make a discussion
on it in report generation.
10. Now set the value of DFT points to 4. See the changes in graph. And take the reading will
give you table no. 5. Again do some discussions on graph you obtained in report generation.
11. For every set of readings take a screenshot of the simulation stage, using the button
provided on the simulation stage at right upper most corner and upload each
image with the table data in report generation.
12. Complete the Observation and discuss the results in report generation.
13. Then click Yes I have finished my Experiment button to submit your report.

Dept. of ECE, Dr.AIT


65
Digital Signal Processing Lab Manual -- 18ECL57 V semester

Dept. of ECE, Dr.AIT


66
Digital Signal Processing Lab Manual -- 18ECL57 V semester
EXPERIMENT NO 3 Study of FIR filter design using window method: Low pass
and high pass filter

Theory:

Finite Impulse Response (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 (a
recursive part of a filter), even though recursive algorithms can be used for FIR filter
realization. Hence it is an all zero filter. Therefore input and output difference equation for FIR
filter is given by
y(n)=b0x(n)+b1x(n−1)+b2x(n−2)+...+bM−1x(n−N+1)
Where b0, b1, b2 ... b(M-1) are filter coefficients. FIR filters are particularly useful for
applications where exact linear phase response is required. The FIR filter is generally
implemented in a non-recursive way which guarantees a stable filter.
FIR filters can be designed using different methods, but most of them are based on ideal filter
approximation. The objective is not to achieve ideal characteristics, as it is impossible anyway,
but to achieve sufficiently good characteristics of a filter. The transfer function of FIR filter
approaches the ideal as the filter order increases, thus increasing the complexity and amount
of time needed for processing input samples of a signal being filtered.

Fig-1
FIR filters can have linear phase characteristic, which is not like IIR filters. Obviously, in such
cases when it is necessary to have a linear phase characteristic, FIR filters are the only option
available. If the linear phase characteristic is not necessary, as is the case with processing
speech signals, FIR filters are not good solution at all.
One of the drawbacks of FIR filters is a high order of designed filter. The order of FIR filter is
remarkably higher compared to an IIR filter with the same frequency response. This is the
reason why it is so important to use FIR filters only when the linear phase characteristic is
very important.
A number of delay lines contained in a filter, i.e. a number of input samples that should be
saved for the purpose of computing the output sample, determines the order of a filter. For
example, if the filter is assumed to be of order 10, it means that it is necessary to save 10 input
samples preceding the current sample. All eleven samples will affect the output sample of FIR
filter
The transform function of a typical FIR filter can be expressed as a polynomial of a complex
variable z-1. All the poles of the transfer function are located at the origin. For this reason, FIR
filters are guaranteed to be stable, whereas IIR filters have potential to become unstable
Basic concepts and FIR filter specification
Most FIR filter design methods are based on ideal filter approximation. The resulting filter
approximates the ideal characteristic as the filter order increases, thus making the filter and
its implementation more complex

Dept. of ECE, Dr.AIT


67
Digital Signal Processing Lab Manual -- 18ECL57 V semester
First of all, it is necessary to learn the basic concepts that will be used further in this book. You
should be aware that without being familiar with these concepts, it is not possible to
understand analyses and synthesis of digital filters.
Figure 2.a and 2.b illustrates a low-pass digital filter specification. The word specification
actually refers to the frequency response specification

Figure 2.a: Low-pass digital filter specification


ωp normalized cut-off frequency in the passband;
ωs normalized cut-off frequency in the stopband;
δ1maximum ripples in the passband
δ2minimum attenuation in the stopband [dB]
ap maximum ripples in the passband; and
asminimum attenuation in the stopband [dB].
ap=20log10(1+δ11−δ1)
as=−20log10δ1
Frequency normalization can be expressed as follows:
ω=(2πffs)
where:
fsis a sampling frequency;
f is a frequency to normalize; and
ω is normalized frequency.
Specifications for high-pass, band-pass and band-stop filters are defined almost the same way
as those for low-pass filters. Figure 3.a and 3.b illustrates a high-pass filter specification.

Figure 3.b: High-pass digital filter specification


Comparing these two figures 2.a, 2.b and 3.a, 3.b, it is obvious that low-pass and high-pass
filters have similar specifications. The same values are defined in both cases with the
difference that in the later case the pass band is substituted by the stop band and vice versa.
Finite impulse response (FIR) filter design methods
The filter design process starts with specifications and requirements of the desirable FIR filter.
Which method is to be used in the filter design process depends on the filter specifications and
implementation
There are essentially three well-known methods for FIR filter design namely:
1. The window method.
2. The frequency sampling technique.
3. Optimal filter design methods
Each of the given methods has its advantages and disadvantages. Thus, it is very important to
carefully choose the right method for FIR filter design. Due to its simplicity and efficiency, the
window method is most commonly used method for designing filters. The sampling frequency
method is easy to use, but filters designed this way have small attenuation in the stop band.

Dept. of ECE, Dr.AIT


68
Digital Signal Processing Lab Manual -- 18ECL57 V semester
Out of these three techniques we are going to discuss about window method only
Ideal filter approximation
The ideal filter frequency response is used when designing FIR filters using window functions.
The objective is to compute the ideal filter samples. FIR filters have finite impulse response,
which means the ideal filter frequency sampling must be performed in a finite number of
points. As the ideal filter frequency response is infinite, it is easy to produce sampling errors.
The error is less as the filter order increases. Figure 4.a and 4.b illustrates the transfer
functions of two standard ideal filters

Figure 4.a and 4.b: Transfer functions of two standard ideal filters
The ideal filter frequency response can be computed via inverse Fourier transform. The two
standard ideal filters frequency responses are contained in the table 1 below.

Table 1: The frequency responses of two standard ideal filters


The value of variable n ranges between 0 and N, where N is the filter order. A constant M can
be expressed as M = N / 2. Equivalently, N can be expressed as N = 2M
The constant M is an integer if the filter order N is even, which is not the case with odd order
filters. If M is an integer (even filter order), the ideal filter frequency response is symmetric
about its Mth sample which is found via expression shown in the table 1 above. If M is not an
integer, the ideal filter frequency response is still symmetric, but not about some frequency
response sample
Since the variable n ranges between 0 and N, the ideal filter frequency response has N+1
sample
If it is needed to find frequency response of a non-standard ideal filter, the expression for
inverse Fourier transform must be used:
hd[n]=1π∫π0ejω(n−M)dω
Non-standard filters are rarely used. However, if there is a need to use some of them, the
integral above must be computed via various numerical methods
FIR filter design using window functions
The FIR filter design process via window functions can be split into several steps:
1.Defining filter specifications;
2.Specifying a window function according to the filter specifications;
3.Computing the filter order required for a given set of specifications;
4.Computing the window function coefficients;

Dept. of ECE, Dr.AIT


69
Digital Signal Processing Lab Manual -- 18ECL57 V semester
5.Computing the ideal filter coefficients according to the filter order;
6.Computing FIR filter coefficients according to the obtained window function and ideal filter
coefficients
7.If the resulting filter has too wide or too narrow transition region, it is necessary to change
the filter order by increasing or decreasing it according to needs, and after that steps 4, 5 and
6 are iterated as many times as needed
The final objective of defining filter specifications is to find the desired normalized frequencies
, transition width and stopband attenuation. The window function and filter order are both
specified according to these parameters. Accordingly, the selected window function must
satisfy the given specifications.
After this step, that is, when the window function is known, we can compute the filter order
required for a given set of specifications.
When both the window function and filter order are known, it is possible to calculate the
window function coefficients w[n] using the formula for the specified window function
After estimating the window function coefficients, it is necessary to find the ideal filter
frequency samples. The final objective of this step is to obtain the coefficients hd[n]. Two
sequences w[n] and hd[n] have the same number of elements.
The next step is to compute the frequency response of designed filter h[n] using the following
expression:
h[n]=w[n].hd[n]
Lastly, the transfer function of designed filter will be found by transforming impulse response
via Fourier transform:

If the transition region of designed filter is wider than needed, it is necessary to increase the
filter order, re-estimate the window function coefficients and ideal filter frequency samples,
multiply them in order to obtain the frequency response of designed filter and re-estimate the
transfer function as well. If the transition region is narrower than needed, the filter order can
be decreased for the purpose of optimizing hardware and/or software resources. It is also
necessary to re-estimate the filter frequency coefficients after that. For the sake of precise
estimates, the filter order should be decreased or increased by 1.
Window functions
The window method is most commonly used method for designing FIR filters. The simplicity
of design process makes this method very popular.
A window is a finite array consisting of coefficients selected to satisfy the desirable
requirements. This chapter provides a few methods for estimating coefficients and basic
characteristics of the window itself as well as the result filters designed using these
coefficients. The point is to find these coefficients denoted by w[n].
When designing digital FIR filters using window functions it is necessary to specify:
A window function to be used; and
The filter order according to the required specifications (selectivity and stop band
attenuation).
These two requirements are interrelated. Each function is a kind of compromise between the
two following requirements:
The higher the selectivity, i.e. the narrower the transition region; and
The higher suppression of undesirable spectrum, i.e. the higher the stop band attenuation.
Table 2 below contains all window functions mentioned in this chapter and briefly compares
their selectivity and stop band attenuation
These two requirements are interrelated. Each function is a kind of compromise between the
two following requirements:

Dept. of ECE, Dr.AIT


70
Digital Signal Processing Lab Manual -- 18ECL57 V semester
The higher the selectivity, i.e. the narrower the transition region; and
The higher suppression of undesirable spectrum, i.e. the higher the stop band attenuation.
Table 2 below contains all window functions mentioned in this chapter and briefly compares
their selectivity and stop band attenuation.
Special attention should be paid to the fact that minimum attenuation of window function and
that of the filter designed using that function are different in most cases. The difference, i.e.
additional attenuation occurs under the process of designing a filter using window functions.
This affects the stop band attenuation to become additionally higher, which is very desirable.
However, a drawback of this method is that the minimum stop band attenuation is fixed for
each function. The following concepts such as the main lobe, main lobe width, side lobes,
transition region, minimum stopband attenuation of window function and minimum stopband
attenuation of designed filter are described in more detail in Figure 5

Figure 5: Main lobe, main lobe width, side lobes, and transition region
As can be seen in the table 2 above, the stopband attenuation of these windows is not
adjustable. It is only possible to affect the transition region by increasing the filter order. For
this reason it is preferable to start design process by specifying the appropriate window
function on the basis of the stopband attenuation. It is most preferable to specify a window
with the least stopband attenuation that satisfies the given requirements. This enables the
designed filter to have the narrowest transition region

Frequency Response and Weight Values of different windows types

Dept. of ECE, Dr.AIT


71
Digital Signal Processing Lab Manual -- 18ECL57 V semester

Procedure:
1. Click on the simulator tab SIMULATOR, it will open the workspace.
2. See the movie in experiment page by pressing help button to understand how the different
steps, as mentioned next, are to be executed..
3. User controls like filter selection, no. of samples in the ideal filter in time domain, cutoff
frequency, window length (filter order) and window type selection are given to compare the
effect of different windows for designing FIR filters.
4. In this experiment we have provided two types of filters Lowpass and Highpass filters. The
sampling frequency is set to 5000 Hz, you can vary cut-off frequency (fa) from 1000 Hz to 3000
Hz and window length (Filter order M) from 0 to N. You can choose following window
functions: Rectangular, Barlett, Hamming, Hanning, Blackman and Kaiser windows. If you
choose Kaiser window function there is a parameter called a through which you can change
shape of the Kaiser window.

Fig-1
1. Graph 1 plots the impulse response of the filter (Green) in time domain with a time shift
of M/2 and Window function (Red) . A slider is given along the x-axis by this you can
read sample by sample value for impulse response of the filter

Fig-2

Dept. of ECE, Dr.AIT


72
Digital Signal Processing Lab Manual -- 18ECL57 V semester
2. Graph 2 plots the magnitude spectrum of FIR filter scale the x-axis range from 0 to 5000
Hz. Here also a slider is provided along the x-axis by which you can read the values at
different frequencies. A check box is provided at right top corner on Graph 2 to switch
between magnitude spectrum in Decibel and absolute value.

Fig-3
3. Graph no. 3 showing the input signal before and after passing through the filter. In the
same graph you can observe the frequency response of the output signal just by
checking the checkbox provides

Dept. of ECE, Dr.AIT


73
Digital Signal Processing Lab Manual -- 18ECL57 V semester

Fig-4

Fig-5
4. While changing the window function you can see the window function expressions on
the top right half of the experiment space. Similarly a text box is provide on the top right
hand side from this you can copy the final filter difference equation to design your filter
on hardware or software.

Fig-6
9. You can choose between sine or square signal as input signal and select input signal
frequency.
10. When experiment loads first time the default values are set in all user controls. Initially for
the Low pass filter fs = 5000 Hz, fa = 1000 Hz and M = 50. Rectangular window is being selected
by default. Square wave is the input by default and its frequency if 100 Hz.
11. Keeping filter cut-off frequency constant change the input signal frequency and note down
input signal and output signal peak to peak values. Which will give you table no. 1 for your
report generation.
12. Similarly, choose High pass filter and repeat the step 10 -12 to note down another set of
data which will give you Table no. 2.
13. Now change the window function and do the earlier steps which will give you number of
tables.
14. From each table of data you have input and output signal peak to peak values, compute the
gain in decibel and plot the gain Vs frequency plot which will give you the same plot what you
have with filter frequency response (Graph 2).
15. Use take snapshot button to take the screenshot of the experiment space.
16. Complete the Observation and discuss the results in report generation.
17. Then click Yes I have finished my Experiment button to submit your report.

Dept. of ECE, Dr.AIT


74
Digital Signal Processing Lab Manual -- 18ECL57 V semester
Experiment 4: Study of Infinite Impulse Response (IIR) filter

Theory:
Infinite Impulse Response (IIR) Filter 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. Block diagrams of FIR and IIR filters
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 filters can be designed using different methods. One of the most commonly used is via the
reference analog prototype filter. This method is the best for designing all standard types of
filters such as low-pass, high-pass, band-pass and band-stop filters.
Figure 10.1 illustrates the block diagram of this method.

Fig-10.1
FIR filters can have linear phase characteristic, which is not typical of IIR filters. When it is
necessary to have linear phase characteristic,
FIR filters are the only available solution. In other cases when linear phase characteristic is not
necessary, such as speech signal processing,
FIR filters are not good solution. IIR filters should be used instead. The resulting filter order is
considerably lower for the same frequency response.
The filter order determines the number of filter delay lines, i.e. number of input and output
samples that should be saved in order that the next output sample can be computed. For
instance, if the filter order is 10, it means that it is necessary to save 10 input samples plus 10
output samples preceeding the current sample. All these 21 samples will affect the next output
sample.
The IIR filter transfer function is a ratio of two polynomials of complex variable z-1. The
numerator defines location of zeros, whereas the denominator defines location of poles of the
resulting IIR filter transfer function.
Figure 10.2. illustrates input and output signals of the system with non-linear phase
characteristic.

Dept. of ECE, Dr.AIT


75
Digital Signal Processing Lab Manual -- 18ECL57 V semester

Fig-10.2
The system introduces phase shift of 0 radians at frequency of ω and Π radians at three times
higher frequency. Input signal consists of nature frequency ω and harmonics with the same
amplitude at three times higher frequency. Figure on the left illustrates an input signal,
whereas Figure on the right illustrates an output signal. As seen, these two signals have
different waveforms. Neither the power of the signal nor amplitudes of particular harmonics
have been changed, but the phase of the second harmonic.
Assume that an input represents a speech signal where the phase is not important. In this case
such phase distortion would be negligible as the system satisfies the stated requirements.
Otherwise, if the phase is important, such a huge distortion mustn’t be allowed.
Infinite impulse response (IIR) filter design
The most commonly used IIR filter design method uses reference analog prototype filter. It is
the best method to use when designing standard filters such as low-pass, high-pass, bandpass
and band-stop filters
The filter design process starts with specifications and requirements of the desirable IIR filter.
A type of reference analog prototype filter to be used is specified according to the
specifications and after that everything is ready for analog prototype filter design.
The next step in the design process is scaling of the frequency range of analog prototype filter
into desirable frequency range. This is how an analog prototype filter is converted into an
analog filter.
After the analog filter is designed, it is time to go through the last step in the digital IIR filter
design process. It is conversion from analog to digital filter. The most popular and most
commonly used converting method is bilinear transformation method. The resulting filter,
obtained in this way, is always stable. However, instability of the resulting filter, when bilinear
transformation is used, may be caused only by the finite word-length side-effect.
Basic concepts and IIR filter specification
First of all, it is necessary to learn the basic concepts that will be used further in this book. You
should be aware that without being familiar with these concepts, it is not possible to
understand analyses and synthesis of digital filters.
Figure 10.3 illustrates a low-pass digital filter specification. The word specification refers to
the frequency response specification.

H(ω)

Dept. of ECE, Dr.AIT


76
Digital Signal Processing Lab Manual -- 18ECL57 V semester

Figure 10.3: Lowpass digital filter specification


where
ωp normalized passband cut-off frequency
ωs normalized stopband cut-off frequency
δ1 maximum passband ripples
δ2 minimum stopband attentuation
ε passband attenuation parameter
A stopband attenuation parameter
ap maximum passband ripples [dB]
as minimum stopband attenuation [dB]
δp=1−10−ap10
=1−(11+ε2−−−−−√)
ε=δp(2−δp)−−−−−−−−√1−δp=10ap−1−−−−−−−√
ap=−20log(1−δp)=10log(1+ε2)
Frequency normalization can be expressed as follows:
ω=(2πffs)
where:
fs is the sampling frequency
f is the frequency to normalize and
ω is the normalized frequency.
Specifications for high-pass filter is defined almost the same way as those for low-pass filters.
Figure 10.4 illustrates a highpass filter specification.

Figure 10.4: Highpass digital filter specification

Procedure:
1. Click on the Simulator tab SIMULATOR, it will open the workspace.
2. See the movie in experiment page by pressing help button ? to understand how the
following steps are to be executed.
3. In this experiment we have provided two types of filters Lowpass and Highpass filter. The
sampling frequency is set to 700 Hz.
4. We have provided user controls on top left side of the simulation screen. Here you have an
option to change filter design technique like Butterworth, Chebyshiv 1 etc. You can change
filter passband and stopband frequency from the dropdown menu also the passband ripple
and stopband attenuation. You can choose between filter frequency response or pole zero plot.

Dept. of ECE, Dr.AIT


77
Digital Signal Processing Lab Manual -- 18ECL57 V semester

fig-1
5. Graph 1 plots the filter frequency response and pole zero plot. Two radio buttons has been
provided to change the plot from frequency response to pole zero plot vice versa. For
frequency response plot you can choose between magnitude or phase response or both by
selecting the corresponding checkbox given below the plot. In pole zero plot mode you will get
the filter coefficients you can use these filter coefficients for filter designing in any other
software or programming.

fig-2
6. Here we have taken sum of two sinusoidal signals of different frequencies (60Hz & 190Hz)
as input so that user can easily understand the filter operation by choosing appropriate cutoff
frequencies.
7. Graph 2 and 3 plots input and output signal respectively and also the corresponding
frequency domain plots. Here we have given two radio buttons so that user can change from
time domain to frequency domain plot.

Dept. of ECE, Dr.AIT


78
Digital Signal Processing Lab Manual -- 18ECL57 V semester

fig-3 Input and output signal time domain plots.

fig-4 Input and output signal frequency domain plots


8. Select low pass filter and Butterworth filter design observe the filter frequency response,
pole zero positions by changing cut-off frequency. Simultaneously see the output and compare
with input signal. Write the discussion in the report portion of this experiment. Similarly
change the filter design to remaining three types of designing techniques and change the cut-
off frequency and observe the output.
9. Now change the passband ripple and stopband attenuation to another values and observe
the results.
10. Repeat the step 8 and 9 for high pass also and observe the output signal and compare with
input signal.
11. Use take snapshot button to take the screenshot of the experiment space
12. Complete the Observation and discuss the results in report generation.
13. Then click Yes I have finished my Experiment button to submit your report.

Dept. of ECE, Dr.AIT


79

You might also like