You are on page 1of 128

JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57

__________________________________________________________________________________

DSP
LABORATORY
MANUAL

SEM V, B.E.

Manual Prepared By
Mrs. D Krishnaveni, Asst. Prof
Mrs.Sumangala Gejje, Asst.Prof
Prof K Chandrasekhar, Associate Prof

Department of Electronics and Communication Engg.

__________________________________________________________________________________
_
1
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________

DSP Lab Syllabus

B.E., V Semester, EC/TC

[As per Choice Based Credit System (CBCS) scheme]


Subject Code 15ECL57 IA Marks 20
Number of Lecture Hours/Week 01Hr Tutorial (Instructions) + 02 Hours Laboratory=03
Exam Marks 80 Exam Hours 03
CREDITS 02
Laboratory Experiments

Following Experiments to be done using MATLAB / SCILAB / OCTAVE or equivalent:

1. Verification of sampling theorem.


2. Linear and circular convolution of two given sequences, Commutative, distributive and
associative property of convolution.
3. Auto and cross correlation of two sequences and verification of their properties
4. Solving a given difference equation.
5. Computation of N point DFT of a given sequence and to plot magnitude and phase
spectrum (using DFT equation and verify it by built-in routine).
6. (i) Verification of DFT properties (like Linearity and Parsevals theorem, etc.)
(ii) DFT computation of square pulse and Sinc function etc.
7. Design and implementation of FIR filter to meet given specifications (using different
window techniques).
8. Design and implementation of IIR filter to meet given specifications.

Following Experiments to be done using DSP kit

9. Linear convolution of two sequences


10. Circular convolution of two sequences
11. N-point DFT of a given sequence\
12. Impulse response of first order and second order system
13. Implementation of FIR filter

Conduct of Practical Examination:

1. All laboratory experiments are to be included for practical examination.


2. Strictly follow the instructions as printed on the cover page of answer script for breakup of
marks.
3. Change of experiment is allowed only once and 15% of Marks allotted to the procedure
part to be made zero.

__________________________________________________________________________________
_
2
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________

COURSE OUTCOME

Learning the MATLAB software and writing programs in MATLAB

Verify the digital signal computations using MATLAB and observing the output through
graphs and numbers
Writing the DSP programming in Embedded C using CCS studio

Downloading the program into the DSP processor verifying processor functionality

Interface the peripheral devices to DSP processor

COURSE OBJECTIVES

1. Learn the MATLAB software to implement DSP algorithms

2. Verify the digital signal computations using mathematical descriptions, and graphs

3. Use Embedded C to write programs and download on to DSP Processor to verify the
DSP algorithms

__________________________________________________________________________________
_
3
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
DSP LAB PLAN

Planned
Week Hour Topic to be covered
Date

L1 9/8/2017
1 Introduction to MATLAB
L1 11/8/2017
L2 16-8-17 Verification of sampling theorem.
2 Computation of N point DFT of a given sequence and to plot
L2 18-8-17 magnitude and phase spectrum
L3 23-8-17 (i) Verification of DFT properties (like Linearity and Parsevals
3 theorem, etc.)
L3 1/9/2017 (ii) DFT computation of square pulse and Sinc function etc.
L4 30-8-17 Linear and circular convolution of two given sequences,
4 Commutative, distributive and associative property of
L4 8/9/2017 convolution.
L5 6/9/2017 Auto and cross correlation of two sequences and verification of
5
L5 their properties
15/9/2017
L6 20-9-17 Solving a given difference equation.
6 Design and implementation of IIR filter to meet given
L6 22/9/2017 specifications
L7 4/10/2017
Test 1
L7 6/10/2017
N-point DFT of a given sequence using CC Studio
L8 27-9-17
Linear convolution of two sequences using CC Studio
7
Circular convolution of two sequences using CC Studio
L8 7/10/2017
Impulse response of first order and second order system
L9 11/10/2017
8
L9 13-10-17 Implementation of FIR filter
Design and implementation of FIR filter to meet given
L10 25-10-17 specifications (using different Design and implementation of
FIR filter to meet given specifications (using different window
9
techniques).
L10 3/11/2017 Design and implementation of IIR filter to meet given
specifications.
L11 8/11/17 Design of Butterworth Filter (Extra)
10
L11 9/11/2017 Impulse response of a given system (Extra)

L12 15/11/17
11 Test
L12 10/11/2017

__________________________________________________________________________________
_
4
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________

Introduction to MATLAB

MATLAB is an interactive system whose basic data element is an array that does not
require dimensioning. It allows us to solve many technical computing problems, especially
those with matrix and vector formulations.

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.

MATLAB Layout

One to five different windows can be selected to appear (View)

__________________________________________________________________________________
_
5
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
Help Window: The Help Window contains help information. This window can be opened
from the Help menu in the toolbar of any MATLAB window. The Help Window is
interactive and can be used to obtain information on any feature of MATLAB.

Command Window: The Command Window is MATLABs main window and opens when
MATLAB is started. It can be used for executing commands, opening other windows,
running programs written by the user, and managing the software.

Workspace Browser

The MATLAB workspace consists of the set of variables built up during a MATLAB
session and stored in memory. You add variables to the workspace by using functions,
running M-files, and loading saved workspaces.

Figure Window: The Figure Window opens automatically when graphics commands are
executed, and contains graphs created by these commands.

Notes for working in the Command Window:

To type a command the cursor must be placed next to the command prompt (>>).

__________________________________________________________________________________
_
6
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
Once a command is typed and the Enter key is pressed, the command is executed.
However, only the last command is executed. Everything executed previously (that might be
still displayed) is unchanged.

Several commands can be typed in the same line. This is done by typing a comma between
the commands. When the Enter key is pressed the commands are executed in order from left
to right.

It is not possible to go back to a previous line that is displayed in the Command Window,
make a correction, and then re-execute the command.

A previously typed command can be recalled to the command prompt with the up-arrow
key ( ). When the command is displayed at the command prompt, it can be modified if
needed and then executed. The down-arrow key ( ) can be used to move down the list of
previously typed commands.

The semicolon (;):

When a command is typed in the Command Window and the Enter key is pressed, the
command is executed. Any output that the command generates is displayed in the Command
Window. If a semicolon (;) is typed at the end of a command the output of the command is
not displayed.

Typing %:

When the symbol % (percent) is typed at the beginning of a line, the line is designated as a
comment. This means that when the Enter key is pressed the line is not executed.

The clc command:

The clc command (type clc and press Enter) clears the Command Window.

The Command History Window:

The Command History Window lists the commands that have been entered in the Command
Window. This includes commands from previous sessions. A command in the Command
History Window can be used again in the Command Window. By double-clicking on the
command, the command is reentered in the Command Window and executed. It is also
possible to drag the command to the Command Window, make changes if needed, and then
execute it.

Editing M-Files

Use the Editor to create and debug M-files, which are programs you write to run MATLAB
functions. The Editor provides a graphical user interface for text editing, as well as for M-file
debugging. To create or edit an M-file use File > New or File > Open, or use
the edit function.

__________________________________________________________________________________
_
7
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________

Notes About Script Files

A script file is a sequence of MATLAB commands, also called a program.

When a script file runs (is executed), MATLAB executes the commands in the order they
are written just as if they were typed in the Command Window.

When a script file has a command that generates an output (e.g., assignment of a value to a
variable without a semicolon at the end), the output is displayed in the Command Window.

Using a script file is convenient because it can be edited (corrected or otherwise changed)
and executed many times.

Script files can be typed and edited in any text editor and then pasted into the MATLAB
editor.

Script files are also called M-files because the extension .m is used when they are saved.

Running (Executing) a Script File

A script file can be executed either directly from the Editor Window by clicking on the Run
icon or by typing the file name in the Command Window and then pressing the Enter key.

__________________________________________________________________________________
_
8
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________

Arithmetic operations with scalars

Operation Operator Example

Addition + 5+3
Subtraction 53
Multiplication * 5*3
Right division / 5/3
Left division \ 5\3=3/5
Exponentiation ^ 5 ^ 3 = 53 = 125

Order of Precedence

First Parentheses. For nested parentheses, the innermost are executed first.
Second Exponentiation.
Third Multiplication, division (equal precedence).
Fourth Addition and subtraction.

Relational operators:

Relational operators in MATLAB are:

< Less than ~= Not Equal to


> Greater than & Logical AND
<= Less than or equal to | Logical OR.
>= Greater than or equal to ~ Logical NOT
== Equal to

Elementary Math and trigonometry functions

__________________________________________________________________________________
_
9
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________

The inverse trigonometric functions are asin(x), acos(x), atan(x), acot(x) for the angle in
radians; and asind(x), acosd(x), atand(x), acotd(x) for the angle in degrees. The hyperbolic
trigonometric functions are sinh(x), cosh(x), tanh(x), and coth(x). pi, is equal to

Rounding functions

__________________________________________________________________________________
_
10
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________

Defining scalar variables

A variable is a name made of a letter or a combination of several letters (and digits) that is
assigned a numerical value. Once a variable is assigned a numerical value, it can be used in
mathematical expressions, in functions, and in any MATLAB statements and commands. A
variable is actually a name of a memory location. When a new variable is defined, MATLAB
allocates an appropriate memory space where the variables assignment is stored. When the
variable is used the stored data is used. If the variable is assigned a new value the content of
the memory location is replaced.

In MATLAB the = sign is called the assignment operator. The assignment operator assigns a
value to a variable.

Variable_name = A numerical value, or a computable expression

Rules About Variable Names

A variable can be named according to the following rules:

Must begin with a letter, Can be up to 63 characters long. Can contain letters, digits, and
the underscore character. Cannot contain punctuation characters (e.g., period, comma,
semicolon). MATLAB is case sensitive: it distinguishes between uppercase and lowercase
letters. No spaces are allowed between characters (use the underscore where a space is
desired). Avoid using the name of a built-in function for a variable.

Creating a vector from a known list of numbers:

The vector is created by typing the elements (numbers) inside square brackets [ ].

Row vector: To create a row vector type the elements with a space or a comma between the
elements inside the square brackets.

Column vector: To create a column vector type the left square bracket [ and then enter the
elements with a semicolon between them, or press the Enter key after each element. Type the
right square bracket ] after the last element.

variable_name = [ type vector elements]

__________________________________________________________________________________
_
11
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
Creating a vector with constant spacing by specifying the first term, the spacing, and
the last term:

In a vector with constant spacing the difference between the elements is the same. For
example, in the vector v = 2 4 6 8 10, the spacing between the elements is 2. A vector in
which the first term is m, the spacing is q, and the last term is n is created by typing:

Creating a vector with linear (equal) spacing by specifying the first and last terms, and
the number of terms:

A vector with n elements that are linearly (equally) spaced in which the first element is xi and
the last element is xf can be created by typing the linspace command (MATLAB determines
the correct spacing): When the number of elements is omitted, the default is 100.

Creating a two-dimensional array (matrix)

A matrix is created by assigning the elements of the matrix to a variable. This is done by
typing the elements, row by row, inside square brackets [ ]. First type the left bracket [ then
type the first row, separating the elements with spaces or commas. To type the next row type
a semicolon or press Enter. Type the right bracket ] at the end of the last row.

variable_name=[1st row elements; 2nd row elements; 3rd row elements; ... ; last row
elements]

Rows of a matrix can also be entered as vectors using the notation for creating vectors with
constant spacing, or the linspace command.

The zeros(m,n) and the ones(m,n) commands create a matrix with m rows and n columns in
which all elements are the numbers 0 and 1, respectively. The eye(n) command creates a
square matrix with n rows and n columns in which the diagonal elements are equal to 1 and
the rest of the elements are 0. This matrix is called the identity matrix.

The transpose operator, when applied to a vector, switches a row (column) vector to a
column (row) vector. When applied to a matrix, it switches the rows (columns) to columns
(rows). The transpose operator is applied by typing a single quote following the variable to
be transposed.

Array addressing
__________________________________________________________________________________
_
12
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
Elements in an array (either vector or matrix) can be addressed individually or in subgroups.

The address of an element in a vector is its position in the row (or column). For a vector
named ve, ve(k) refers to the element in position k. The first position is 1. For example, if the
vector ve has nine elements: ve = 35 46 78 23 5 14 81 3 55 then ve(4) = 23, ve(7) = 81, and
ve(1) = 35.

A single vector element, v(k), can be used just as a variable. For example, it is possible to
change the value of only one element of a vector by assigning a new value to a specific
address. This is done by typing: v(k) = value. A single element can also be used as a variable
in a mathematical expression.

The address of an element in a matrix is its position, defined by the row number and the
column number where it is located. For a matrix assigned to a variable ma, ma(k,p) refers to
the element in row k and column p.

Using a colon : in addressing arrays

A colon can be used to address a range of elements in a vector or a matrix.

For a vector:

va(:) Refers to all the elements of the vector va (either a row or a column vector).

va(m:n) Refers to elements m through n of the vector va.

For a matrix:

A(:,n) Refers to the elements in all the rows of column n of the matrix A.

A(n,:) Refers to the elements in all the columns of row n of the matrix A.

A(:,m:n) Refers to the elements in all the rows between columns m and n of the matrix A.

A(m:n,:) Refers to the elements in all the columns between rows m and n of the matrix A.

A(m:n,p:q) Refers to the elements in rows m through n and columns p through q of the matrix
A.

Adding elements to a vector:

Elements can be added to an existing vector by assigning values to the new elements. For
example, if a vector has 4 elements, the vector can be made longer by assigning values to
elements 5, 6, and so on. If a vector has n elements and a new value is assigned to an element
with an address of or larger, MATLAB assigns zeros to the elements that are between the last
original element and the new element.

DF=1:4 % DF =1 2 3 4

DF(5:10)=10:5:35 % DF =1 2 3 4 10 15 20 25 30 35
__________________________________________________________________________________
_
13
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
AD=[5 7 2] % AD =5 7 2

AD(8)=4 % AD =5 7 2 0 0 0 0 4

AR(5)=24 % AR =0 0 0 0 24

RE=[3 8 1 24];

GT=4:3:16;

KNH=[RE GT] % KNH =3 8 1 24 4 7 10 13 16

>> E=[1 2 3 4; 5 6 7 8] >> AW=[3 6 9; 8 5 11]


E=1234 AW =
5678 369
>> E(3,:)=[10:4:22] 8 5 11
E=1234 >> AW(4,5)=17
5678 AW =
10 14 18 22 36900
>> K=eye(3) 8 5 11 0 0
K=100 00000
010 0 0 0 0 17
001 >> BG(3,4)=15
>> G=[E K] BG =
G=1234100 0000
5678010 0000
10 14 18 22 0 0 1 0 0 0 15

Deleting elements

>> kt=[2 8 40 65 3 55 23 15 75 80] % kt = 2 8 40 65 3 55 23 15 75 80


>> kt(6)=[ ] % kt = 2 8 40 65 3 23 15 75 80
>> kt(3:6)=[ ] % kt = 2 8 15 75 80
>> mtr=[5 78 4 24 9; 4 0 36 60 12; 56 13 5 89 3]
mtr =
5 78 4 24 9
4 0 36 60 12
56 13 5 89 3
>> mtr(:,2:4) [ ]
mtr =
59
4 12
56 3

__________________________________________________________________________________
_
14
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________

Addition and subtraction

The operations + (addition) and (subtraction) can be used to add (subtract) arrays of
identical size (the same numbers of rows and columns) and to add (subtract) a scalar to an
array. When two arrays are involved the sum, or the difference, of the arrays is obtained by
adding, or subtracting, their corresponding elements. When a scalar (number) is added to (or
subtracted from) an array, the scalar is added to (or subtracted from) all the elements of the
array.

Array Multiplication: * can be used for multiplication of two matrices. When an array is
multiplied by a number (actually a number is a 1 X 1 array), each element in the array is
multiplied by the number.

Inverse of a matrix: In MATLAB the inverse of a matrix can be obtained either by raising A
to the power of 1,A-1 , or with the inv(A) function.

The determinant of a square matrix can be calculated with the det command.

If two vectors a and b are a = [ a1 a2 a3 a4 ] and b = [b1 b2 b3 b4] then element-by-element


multiplication, division, and exponentiation of the two vectors gives:

Generation of random numbers

Simulations of many physical processes and engineering applications frequently require using
a number (or a set of numbers) with a random value. MATLAB has three commandsrand,
randn, and randithat can be used to assign random numbers to variables.

__________________________________________________________________________________
_
15
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________

The randn command:

The randn command generates normally distributed numbers with mean 0 and standard
deviation of 1. The command can be used to generate a single number, a vector, or a matrix
in the same way as the rand command.

Plots or figures

Fig: Example of a
formatted two-
dimensional plot.

__________________________________________________________________________________
_
16
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________

The plot command is used to create two-dimensional plots. The simplest form of the
command is: plot (x, y) where x and y are vectors. The arguments x and y are each a vector
(one-dimensional array). The two vectors must have the same number of elements. When the
plot command is executed, a figure is created in the Figure Window. If not already open, the
Figure Window opens automatically when the command is executed. The figure has a single
curve with the x values on the abscissa (horizontal axis) and the y values on the ordinate
(vertical axis). The curve is constructed of straight-line segments that connect the points
whose coordinates are defined by the elements of the vectors x and y.

Line Specifiers: Line specifiers are optional and can be used to define the style and color of
the line and the type of markers (if markers are desired). The line style specifiers are:

The line color specifiers are:

__________________________________________________________________________________
_
17
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
The marker type specifiers are:

The specifiers are typed inside the plot command as strings. For example, the command

plot(x,y,-mo,LineWidth,2,markersize,12,MarkerEdgeColor,g,markerfacecolor, y)
creates a plot that connects the points with a magenta solid line and circles as markers at the
points. The line width is 2 points and the size of the circle markers is 12 points. The markers
have a green edge line and yellow filling.

A given function y = f(x) can be plotted in MATLAB by using the plot or the fplot
command. The fplot command plots a function with the form between specified limits. The
command has the form:

e.g. fplot('x^2+4*sin(2*x)-1',[-3 3])

Two or more graphs can be created in the same plot by typing pairs of vectors inside the
plot command. The command plot(x,y,u,v,t,h) creates three graphsy vs. x, v vs. u, and h vs.
tall in the same plot. E.g. plot(x,y,-b,u,v,--r,t,h,g:)

To plot several graphs using the hold on and hold off commands, one graph is plotted first
with the plot command. Then the hold on command is typed. This keeps the Figure Window
with the first plot open, including the axis properties and formatting) if any was done.
Additional graphs can be added with plot commands that are typed next. Each plot command
__________________________________________________________________________________
_
18
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
creates a graph that is added to that figure. The hold off command stops this process. It
returns MATLAB to the default mode, in which the plot command erases the previous plot
and resets the axis properties.

e.g. plot(x,y,'-b')

hold on

plot(x,yd,'--r')

plot(x,ydd,':k')

hold off

With the line command additional graphs (lines) can be added to a plot that already exists.
The major difference between the plot and line commands is that the plot command starts a
new plot every time it is executed, while the line command adds lines to a plot that already
exists.

line(x,y,linestyle,--,color,r,marker,o)

The text command:

A text label can be placed in the plot with the text or gtext commands:

text(x,y,text as string)

gtext(text as string)

The text command places the text in the figure such that the first character is positioned at the
point with the coordinates x, y (according to the axes of the figure). The gtext command
places the text at a position specified by the user. When the command is executed, the Figure
Window opens and the user specifies the position with the mouse.

The legend command:

The legend command places a legend on the plot. The legend shows a sample of the line type
of each graph that is plotted, and places a label, specified by the user, beside the line sample.
The form of the command is: legend(string1,string2, ..... ,pos)

The strings are the labels that are placed next to the line sample. Their order corresponds to
the order in which the graphs were created. The pos is an optional number that specifies
where in the figure the legend is to be placed. The options are:

pos = -1 Places the legend outside the axes boundaries on the right side.

pos = 0 Places the legend inside the axes boundaries in a location that interferes the least with
the graphs.

pos = 1 Places the legend at the upper-right corner of the plot (default).
__________________________________________________________________________________
_
19
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
pos = 2 Places the legend at the upper-left corner of the plot.

pos = 3 Places the legend at the lower-left corner of the plot.

pos = 4 Places the legend at the lower-right corner of the plot.

When the plot(x,y) command is executed, MATLAB creates axes with limits that are based
on the minimum and maximum values of the elements of x and y. The axis command can be
used to change the range and the appearance of the axes.

axis([xmin,xmax,ymin,ymax]) Sets the limits of both the x and y axes (xmin, xmax, ymin,
and ymax are numbers).

axis equal Sets the same scale for both axes.

axis square Sets the axes region to be square.

axis tight Sets the axis limits to the range of the data.

MATLAB commands for making plots with log axes are:

semilogy(x,y) Plots y versus x with a log (base 10) scale for the y axis and linear scale for the
x axis.

semilogx(x,y) Plots y versus x with a log (base 10) scale for the x axis and linear scale for the
y axis.

loglog(x,y) Plots y versus x with a log (base 10) scale for both axes.

INPUT : Request user input

user_entry = input('prompt')

user_entry = input('prompt', 's')

Description

The response to the input prompt can be any MATLAB expression, which is evaluated using
the variables in the current workspace.

user_entry = input('prompt') displays prompt as a prompt on the screen, waits for input from
the keyboard, and returns the value entered in user_entry.

user_entry = input('prompt', 's') returns the entered string as a text variable rather than as a
variable name or numerical value.

DISP: Display text or array

disp(X)

__________________________________________________________________________________
_
20
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
Description

disp(X): displays an array, without printing the array name. If X contains a text string, the
string is displayed. Note that disp does not display empty arrays.

DISPLAY: Display text or array

display(X)

Description

display(X): prints the value of a variable or expression, X. The MATLAB software calls
display(X) when it interprets a variable or expression, X, that is not terminated by a
semicolon. For example, sin(A) calls display, while sin(A); does not.

If X is an instance of a MATLAB class, then MATLAB calls the display method of that
class, if such a method exists. If the class has no display method or if X is not an instance of a
MATLAB class, then the MATLAB built-in display function is called.

xlabel, ylabel, zlabel: Label x-, y-, and z-axis

xlabel('string')

ylabel('string')

zlabel('string')

Description

Each axes graphics object can have one label for the x-, y-, and z-axis. The label appears
beneath its respective axis in a two-dimensional plot and to the side or beneath the axis in a
three-dimensional plot.

xlabel('string') labels the x-axis of the current axes.

ylabel(...) and zlabel(...) label the y-axis and z-axis, respectively, of the current axes.

Title : Add title to current axes

title('string')

Description

Each axes graphics object can have one title. The title is located at the top and in the center of
the axes.
title('string') outputs the string at the top and in the center of the current axes.

Examples
Display today's date in the current axes:
title(date)
__________________________________________________________________________________
_
21
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
Plot : 2-D line plot

plot(Y)

plot(X1,Y1,...)

Description

plot(Y) plots the columns of Y versus their index if Y is a real number. If Y is complex,
plot(Y) is equivalent to plot(real(Y),imag(Y)). In all other uses of plot, the imaginary
component is ignored.

plot(X1,Y1,...) plots all lines defined by Xn versus Yn pairs. If only Xn or Yn is a matrix, the
vector is plotted versus the rows or columns of the matrix, depending on whether the vector's
row or column dimension matches the matrix. If Xn is a scalar and Yn is a vector,
disconnected line objects are created and plotted as discrete points vertically at Xn.

Subplot : Create axes in tiled positions

h = subplot(m,n,p) or subplot(mnp)

Description

subplot divides the current figure into rectangular panes that are numbered row wise. Each
pane contains an axes object. Subsequent plots are output to the current pane.

h = subplot(m,n,p)

The command divides the Figure Window into m X n


rectangular subplots. The subplots are arranged like
elements in an m X n matrix where each element is a
subplot. The subplots are numbered from 1 through m.n.
The upper left subplot is numbered 1 and the lower right
subplot is numbered m.n. The numbers increase from left to
right within a row, from the first row to the last. The
command subplot(m,n,p) makes the subplot p current. This
means that the next plot command (and any formatting
commands) will create a plot (with the corresponding
format) in this subplot. For example, the command
subplot(3,2,1) creates six areas arranged in three rows and two columns as shown, and makes
the upper left subplot current.

Stem : Plot discrete sequence data

stem(Y)

stem(X,Y)

__________________________________________________________________________________
_
22
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
Description

A two-dimensional stem plot displays data as lines extending from a baseline along the x-
axis. A circle (the default) or other marker whose y-position represents the data value
terminates each stem.

stem(Y) plots the data sequence Y as stems that extend from equally spaced and
automatically generated values along the x-axis. When Y is a matrix, stem plots all elements
in a row against the same x value.

stem(X,Y) plots X versus the columns of Y. X and Y must be vectors or matrices of the same
size. Additionally, X can be a row or a column vector and Y a matrix with length(X) rows.

Figure : Create figure graphics object

figure

Description

figure creates figure graphics objects. Figure objects are the individual windows on the screen
in which MATLAB displays graphical output.

figure creates a new figure object using default property value.

Figure Windows can be closed with the close command. Several forms of the command are:

close closes the active Figure Window.

close(n) closes the nth Figure Window.

close all closes all Figure Windows that are open.

Grid: Grid lines for 2-D and 3-D plots

grid on

grid off

grid

grid minor

Description

The grid function turns the current axes' grid lines on and off.

grid on: adds major grid lines to the current axes.

grid off: removes major and minor grid lines from the current axes.

grid toggles the major grid visibility state.

__________________________________________________________________________________
_
23
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
datacursormode: Enable or disable interactive data cursor mode

datacursormode on

datacursormode off

datacursormode

Description

datacursormode on enables data cursor mode on the current figure.

datacursormode off disables data cursor mode on the current figure.

datacursormode toggles data cursor mode on the current figure.

Managing commands

cd Changes current directory.

clc Clears the Command Window.

Clear Removes all variables from the memory.

clear x y z Removes variables x, y, and z from the memory.

close Closes the active Figure Window.

fclose Closes a file.

figure Opens a Figure Window.

fopen Opens a file.

global Declares global variables.

help Displays help for MATLAB functions.

iskeyword Displays keywords.

lookfor Search for specified word in all help entries.

who Displays variables currently in the memory.

whos Displays information on variables in the memory

__________________________________________________________________________________
_
24
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________

INTRODUCTION PROGRAMS

1. Arithmetic operations: Compute the following quantities:

Solution:

__________________________________________________________________________________
_
25
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
2. Equation of a straight line: The equation of a straight line is y = mx+c where m and
c are constants. Compute the y-coordinates of a line with slope m = 0.5 and the
intercept c = 2 at the following x-coordinates: x = 0, 1.5, 3, 4, 5, 7, 9, and 10.

3. Multiply, divide, and exponentiate vectors: Create a vector t with 10 elements: 1, 2,


3, . . ., 10. Now compute the following quantities:

4. Points on a circle: All points with coordinates x = r cos and y = r sin , where r is a
constant, lie on a circle with radius r, i.e., they satisfy the equation x2 + y2 = r2. Create
a column vector for with the values 0, /4, /2, 3/4, , and 5/4. Take r = 2 and
compute the column vectors x and y. Now check that x and y indeed satisfy the
equation of circle, by computing the radius r =sqrt (x2 + y2).

Sqrt(x.^2+y.^2)

5. Create a vector and a matrix with the following commands: v =0:0.2:12; and M =
[sin(v); cos(v)]. Find the sizes of v and M using the size command. Extract the first 10
elements of each row of the matrix, and display them as column vectors.

6. A simple sine plot: Plot y = sin x, 0 x 2, taking 100 linearly spaced points in the
given interval. Label the axes and put Plot created by your name in the title.

x=linspace(0,2*pi,100);
__________________________________________________________________________________
_
26
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
plot(x,sin(x))
xlabel(x), ylabel(sin(x))
title(Plot created by xyz)

7. Line-styles: Make the same plot as above, but rather than displaying the graph as a
curve, show the unconnected data points. To display the data points with small circles,
use plot(x,y,o). Now combine the two plots with the command plot(x,y,x,y,o) to
show the line through the data points as well as the distinct data points.

plot(x,sin(x),x,sin(x),o)
xlabel(x), ylabel(sin(x))

8. An exponentially decaying sine plot: Plot y = e0.4x sin x, 0 x 4, taking 10, 50,
and 100 points in the interval.

x=linspace(0,4*pi,10); % with 10 points


y=exp(-.4*x).*sin(x);
plot(x,y)
x=linspace(0,4*pi,50); % with 50 points
y=exp(-.4*x).*sin(x);
plot(x,y)
x=linspace(0,4*pi,100); % with 100 points
y=exp(-.4*x).*sin(x);
plot(x,y)

9. Write a script file to draw a unit circle

theta = linspace(0,2*pi,100); % create vector theta


x = cos(theta); % generate x-coordinates
y = sin(theta); % generate y-coordinates
plot(x,y); % plot the circle
axis(equal); % set equal scale on axes
title(Circle of unit radius) % put a title

10. Show the center of the circle: Modify the script file circle to show the center of the
circle on the plot, too. Show the center point with a +.

theta = linspace(0,2*pi,100); % create vector theta


x = cos(theta); % generate x-coordinates
y = sin(theta); % generate y-coordinates
plot(x,y,0,0,+); % plot the circle
axis(equal); % set equal scale on axes
title(Circle of unit radius) % put a title

__________________________________________________________________________________
_
27
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
11. Change the radius of the circle: Modify the script file circle.m to draw a circle of
arbitrary radius r as follows: Include the following command in the script to ask the
user to input (r) on the screen: Modify the x and y coordinate calculations
appropriately. Save and execute the file. When asked, enter a value for the radius and
press return.

r = input(Enter the radius of the circle: )


theta = linspace(0,2*pi,100); % create vector theta
x = r*cos(theta); % generate x-coordinates
y = r*sin(theta); % generate y-coordinates
plot(x,y); % plot the circle
axis(equal); % set equal scale on axes
title(Circle of given radius r) % put a title

__________________________________________________________________________________
_
28
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________

EXPERIMENT 1: Verification of Sampling theorem

Aim: To verify Sampling theorem for a signal of given frequency.

Theory:

Sampling is a process of converting a continuous time signal (analog signal) x(t) into
a discrete time signal x[n], which is represented as a sequence of numbers. (A/D
converter)

Converting back x[n] into analog (resulting in x (t ) ) is the process of reconstruction.
(D/A converter)
Sampling theorem states that A bandlimited signal can be reconstructed exactly if it
is sampled at a rate atleast twice the maximum frequency component in it.
The maximum frequency component of bandlimited signal is fm. To recover this
signal exactly from its samples it need to be sampled at a rate fs 2fm.
The minimum required sampling rate to avoid aliasing fs = 2fm is called Nyquist rate
Aliasing is a phenomenon where the high frequency components of the sampled
signal interfere with each other because of inadequate sampling s < 2m.
In practice signal are oversampled, where fs is significantly higher than Nyquist rate
to avoid aliasing.

Techniques for reconstruction-(i) ZOH (zero order hold) interpolation results in a


staircase waveform, is implemented by MATLAB plotting function stairs(n,x), (ii)
FOH (first order hold) where the adjacent samples are joined by straight lines is
implemented by MATLAB plotting function plot(n,x),(iii) spline interpolation, etc.

For x (t ) to be exactly the same as x(t), sampling theorem in the generation of x(n)
from x(t) is used. The sampling frequency fs determines the spacing between samples.

Algorithm:

1. Input the desired frequency fm (for which sampling theorem is to be verified).


2. Generate an analog signal xt of frequency fm for comparison.
3. Generate oversampled, nyquist & under sampled discrete time signals.
4. Plot the waveforms and hence prove sampling theorem.

MATLAB Implementation:

Step 1: MATLAB can generate only discrete time signals. For an approximate analog signal
xt, choose the spacing between the samples to be very small (0), say 50s = 0.00005. Next
choose the time duration, say xt exists for 0.05seconds. (tfinal in program) (for low frequency
say <1000 Hz choose 0.05 secs, for higher choose 0.01 secs or lesser as appropriate).

__________________________________________________________________________________
_
29
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
Now begin with the vector that represents the time base- t = 0:0.00005:0.05;

The colon (:) operator in MATLAB creates a vector, in the above case a time vector running
from 0 to 0.05 in steps of 0.00005. The semicolon (;) tells MATLAB not to display the result.

Given t, the analog signal xt of frequency fm is generated as sin(t)=sin(2ft))-

xt=sin(2*pi*fm*t); pi is recognized as 3.14 by MATLAB.

Step 2: To illustrate oversampling condition, choose sampling frequency fs0=2.2*fm. For


this sampling rate T0=1/fs0, generate the time vector as n1 = 0:T0:0.05; & over sampled
discrete time signal x1=sin(2*pi*fm*n1);

[Alternately let n1 be a fixed number of samples, say n=0:10; & x1=sin(2*pi*n*fm/fs0);]

The discrete signal is converted back to analog signal (reconstructed) using the
MATLAB plot function (FOH). In one plot both the analog signal (approximate one in blue
color) and the reconstructed signal (in red) are plotted for comparison

Step 3: Repeat step 2 for different sampling frequencies, i.e., fs=1.3*fm & fs=2*fm for
under sampling and Nyquist sampling conditions.

MATLAB Program:

tfinal=0.05;
t=0:0.00005:tfinfal;
fm=input('Enter analog frequency');
%define analog signal for comparison
xt=sin(2*pi*fm*t);
%simulate condition for under sampling i.e., fs1<2*fm
fs1=1.3*fm;
%define the time vector
n1=0:1/fs1:tfinal;
%Generate the under sampled signal
xn=sin(2*pi*n1*fm);
%plot the analog & sampled signals
datacursormode on
subplot(3,1,1);
plot(t,xt,'b',n1,xn,'r*-');
title('under sampling plot');
%condition for Nyquist plot
fs2=2*fm;
n2=0:1/fs2:tfinal;
xn=sin(2*pi*fm*n2);
datacursormode on
__________________________________________________________________________________
_
30
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
subplot(3,1,2);
plot(t,xt,'b',n2,xn,'r*-');
title('Nyquist plot');
%condition for over sampling
fs3=5*fm;
n3=0:1/fs3:tfinal;

xn=sin(2*pi*fm*n3);
datacursormode on
subplot(3,1,3);
plot(t,xt,'b',n3,xn,'r*-');
title('Oversampling plot');
xlabel('time');
ylabel('amplitude');
legend('analog','discrete')

Result:

Enter analog frequency 200


The plots obtained are as shown in Fig.1.1

Inference:

1. f s 2 f m implies aliasing effect occurs and original signal cannot be reconstructed


back from the samples obtained. From the undersampling plot observe the aliasing
effect. The analog signal is of 200Hz (T=0.005s). The reconstructed (from under
sampled plot) is of a lower frequency. The alias frequency is computed as fm-fs1 =
200-1.3*200 = 200-260= -60Hz
This is verified from the plot. The minus sign results in a 180 phase shift.

2. Sampling at the Nyquist rate results in samples sin(n) which are identically zero, i.e.,
we are sampling at the zero crossing points and hence the signal component is
completely missed. This can be avoided by adding a small phase shift to the sinusoid.
The above problem is not seen in cosine waveforms. A simple remedy is to sample
the analog signal at a rate higher than the Nyquist rate. The Fig 1.2 shows the result
due to a cosine signal (x1=cos(2*pi*fm*n1). f s 2 f m indicates Nyquist criteria and
original signal can be reconstructed back from the samples
3. The over sampled plot ( f s 2 f m ) shows a reconstructed signal almost similar to that
of the analog signal. Using low pass filtering the wave form can be further
smoothened.

__________________________________________________________________________________
_
31
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________

Fig 1.1: Plots of a sampled sine wave of 200Hz

Fig 1.2: Plots of a sampled Cosine wave of 200Hz


__________________________________________________________________________________
_
32
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________

Experiment 2: Linear and circular convolution of two given sequences, Commutative,


distributive and associative property of convolution.

Aim: To obtain linear convolution and circular convolution of two finite duration sequences.
(i) using time domain approach (ii) frequency domain approach

Theory (Linear convolution): Time domain approach

The output y[n] of a LTI (linear time invariant) system can be obtained by convolving
the input x[n] with the systems impulse response h[n].

The convolution sum is y[ n] x[ n] h[ n] x[k ]h[n k ] x[n k ]h[k ]
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 n u[ n ] ), we can
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).
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 Implementation:

MATLAB recognizes index 1 to positive maximum. Index 0 is also not recognized.


The timing information for a sequence is provided by another vector, say n=-3:5; creates a
vector with values from -3 to 5 with an increment of 1.

During plotting, the time vector size and the sequence size should be the same, i.e.,
the number of elements in the sequence x1 and in its time vector n1 should be the same.
Similarly for x2 and y.

__________________________________________________________________________________
_
33
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
MATLAB Program: (Time domain approach)

%main part of computation


x1=input('Enter first sequence') % x1=[1 2 3 2 1 3 4] first sequence
n1Lend=input('Enter the n value of left end sample of first sequence') %n1Lend=-3

n1Rend=input('Enter the n value of right end sample of first sequence') %n1Rend=3


n1=n1Lend:n1Rend % n1=-3:3 ,time vector of first seq

x2=input('Enter second sequence') % x2=[ 2 -3 4 -1 0 1] %second seq

n2Lend=input('Enter the n value of left end sample of second sequence') %n2Lend=-1


n2Rend=input('Enter the n value of right end sample of second sequence') %n2Rend=4

n2=n2Lend:n2Rend %n2=-1:4, time vector of second seq

%add first elements of time vector


ybegin=n1Lend(1)+n2Lend(1);

%add last elements of time vector


yend=n1Rend(length(x1))+n2Rend(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');
datacursormode on
subplot(2,2,3);
stem(n1,x1);
xlabel('time index n');
ylabel('amplitude ');
title('plot of x1');
datacursormode on
subplot(2,2,4);
stem(n2,x2);
xlabel('time index n');

__________________________________________________________________________________
_
34
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
ylabel('amplitude ');
title('plot of x2');

Result
Enter the first sequence [1 2 3 2 1 3 4]
n1 =-3 -2 -1 0 1 2 3
Enter the second sequence [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

Fig 2.1 Linear convolution

Eg 2: Enter first sequence[1 2 3 4 5 6]


n1= 0 1 2 3 4 5
Enter second sequence[7 8 9 10]
n2= 0 1 2 3
linear con of x1 & x2 is y= 7 22 46 80 114 148 133 104 60

Linear convolution using DFT- IDFT (Frequency domain approach)

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 )

__________________________________________________________________________________
_
35
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
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=X1X2).
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 Implementation:
MATLAB has the function fft(x,N) to perform the N point DFT. The function
IFFT(X) performs the inverse discrete Fourier transform of X. IFFT(X,N) is the N-point
inverse transform. MAX - Largest component. For vectors, MAX(X) is the largest element
in X.

LENGTH Length of vector. LENGTH(X) returns the length of vector X. In


MATLAB, the operator * implies Matrix multiplication. X*Y is the matrix product of X and
Y. The number of columns of X must be equal to the number of rows of Y. The operator .*
Array multiplication. X.*Y denotes element-by-element multiplication. X and Y must have
the same dimensions (unless one is a scalar). In the below program to multiply the two DFTs
(vectors), we use .* (dot star) operator.

%Linear Convolution Program %using DFT


x1=input('Enter first sequence') %x1=[1 2 3 4];
x2=input('Enter second sequence') %x2= [1 2 3 4];
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]
yn= ifft(y,N);
disp('linear convolution of x1 &x2 is yn=');
disp(yn);

%verify

__________________________________________________________________________________
_
36
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
disp('output using conv');
yv=conv(x1,x2);
disp(yv);
%plot
datacursormode on
n1=0:1:N-1;
n2=0:length(x1)-1
n3=0:length(x2)-1
subplot(2,1,1)
stem(n1,yn);
title('linear convolution output y(n)');
subplot(2,2,3)
stem(n2,x1)
title('input1')
subplot(2,2,4)
stem(n3,x2)
title('input2')

Result

linear convolution of x1 &x2 is yn= 1.0000 4.0000 10.0000 20.0000 25.0000 24.0000
16.0000
output using conv 1 4 10 20 25 24 16

Fig 2.2: LINEAR CONVOLUTION using frequency domain approach

__________________________________________________________________________________
_
37
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________

Circular convolution (Time domain approach)

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 systems 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 ]
k
x[n k ]h[k ] . To compute this equation, the
k
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

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} .


__________________________________________________________________________________
_
38
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
Fig 2.3. Plotting of f(m) and h(-m) for circular convolution

Algorithm:

1. Input the two sequences as x and h.


2. Circularly convolve both to get output y.
3. Plot the sequences.

MATLAB Implementation:

MATLAB recognizes index 1 to be positive maximum. Index 0 is not recognized.


Hence in the below program wherever y, x and h sequences are accessed, the index is added
with +1. the modulo index calculation for circular convolution is carried out using the
function - MOD Modulus (signed remainder after division). MOD(x,y) is x - y.*floor(x./y)
if y ~= 0. By convention, MOD(x,0) is x.The input x and y must be real arrays of the same
size, or real scalars. MOD(x,y) has the same sign as y while REM(x,y) has the same sign as
x. MOD(x,y) and REM(x,y) are equal if x and y have the same sign, but differ by y if x and y
have different signs.

CIRCULAR CONVOLUTION (Time domain approach)

x=input(nter the first sequence:); % [1 2 3 4]


h= input(nter the second sequence:); % [1 2 3 4]
N=max(length(x),length(h))
if(length(x)<N)
x=[x zeros(1,N-length(x))]
elseif (length(h)<N)
h=[h zeros(1,N-length(h))]
end
%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=');
__________________________________________________________________________________
_
39
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
disp(y);
%plot
n1=0:1:N-1;
subplot(2,1,1)
stem(n1,y);
% title('Circular convolution output y(n)');
subplot(2,2,3)
stem(0:length(x)-1,x)
title('input1')
subplot(2,2,4)
stem(0:length(h)-1,h)
title('input2')

RESULT: circular convolution of x1 &x2 is y= 26 28 26 20

Fig 2.4: Circular Convolution using time domain approach

Circular convolution using DFT-IDFT (Frequency domain approach)

%Circular Convolution Program using DFT

x1=input(Enter the first sequence); %[4 3 2 1]


x2= input(Enter the second sequence); %[ [1 2 3 4]
N=max(length(x1),length(x2));

%obtain DFTs
__________________________________________________________________________________
_
40
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
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=');
disp(yn);

%plot
datacursormode on

n1=0:1:N-1;
n2=0:length(x1)-1
n3=0:length(x2)-1

subplot(2,1,1)

stem(n1,yn);
title('Circular convolution output y(n)');
subplot(2,2,3)
stem(n2,x1)
title('input1')
subplot(2,2,4)
stem(n3,x2)
title('input2')

RESULT

circular convolution of x1 &x2 is yn=

24 22 24 30

__________________________________________________________________________________
_
41
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________

Fig 2.4: CIRCULAR CONVOLUTION (DFT & IDFT) using frequency domain approach

COMMUTATIVE, ASSOCIATIVE & DISTRIBUTIVE PROPERTIES OF LINEAR &


CIRCULAR CONVOLUTION
% Commutative, Associative and Distributive properties of convolution
clc; clear all; close all;
x1=input('enter first sequence');
x2=input('enter second sequence');
x3=input('enter third sequence');
% commutative property of circular convolution
y=circn(x1,x2);
disp('circular convolution of x1&x2 is y=');
disp(y);
y1=circn(x2,x1);
disp('circular convolution of x2 & x1 is y=');
disp(y1);
% y=y1 implies commutative property holds good
%associative property of circular convolution
y2=circn(y,x3);
disp('circular convolution (x1*x2)*x3 is y=');
disp(y2);
y3=circn(x2,x3);
y4=circn(x1,y3);
__________________________________________________________________________________
_
42
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
disp('circular convolution x1*(x2*x3) is y=');
disp(y4);
%y3=y4 implies associative property (x1*x2)*x3=x1*(x2*x3) holds good
%distributive property of circular convolution
d=x2+x3;
y5=circn(x1,d);
disp('circular convolution x1*(x2+x3) is y=');
disp(y5);
e=circn(x1,x2);
f=circn(x1,x3);
y6=e+f;
disp('circular convolution x1*x2+x1*x3 is y=');
disp(y6);
%y5=y6 implies distributive property x1*(x2+x3)=x1*x2+x1*x3 holds good
% Linear convolution
%commutative property
z1=conv(x1,x2)
z2=conv(x2,x1)
% associative property
z3=conv(z1,x3)
a=conv(x2,x3);
z4=conv(x1,a)
%distrbutive property
z5=conv(x1,x2+x3)
b=conv(x1,x3);
z6=z1+b

__________________________________________________________________________________
_
43
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________

THIS IS A FUNCTION FILE FOR CIRCULAR CONVOLUTION, TO BE SAVED AS


circn.m (i.e. name of the function)
function y=circn(x,h)
N=max(length(x),length(h))
if(length(x)<N)
x=[x zeros(1,N-length(x))]
elseif (length(h)<N)
h=[h zeros(1,N-length(h))]
end
%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

RESULTS:
enter first sequence[4 3 2 1]
enter second sequence[1 2 3 4]
enter third sequence[1 0 0 1]
circular convolution of x1&x2 is y= 24 22 24 30
circular convolution of x2 & x1 is y= 24 22 24 30
circular convolution (x1*x2)*x3 is y= 46 46 54 54
circular convolution x1*(x2*x3) is y= 46 46 54 54
circular convolution x1*(x2+x3) is y= 31 27 27 35
circular convolution x1*x2+x1*x3 is y= 31 27 27 35
linear convolution of x1&x2 is z= 4 11 20 30 20 11 4
linear convolution of x2 & x1 is z= 4 11 20 30 20 11 4
linear convolution (x1*x2)*x3 is z= 4 11 20 34 31 31 34 20 11 4
linear convolution x1*(x2*x3) is z= 4 11 20 34 31 31 34 20 11 4
linear convolution x1*(x2+x3) is z= 8 14 22 35 23 13 5
linear convolution x1*x2+x1*x3 is z= 8 14 22 35 23 13 5

__________________________________________________________________________________
_
44
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________

Experiment 3: Auto and cross correlation of two sequences and verification of their
properties

Aim: To obtain cross correlation of the given sequence and verify its properties.

Theory (Cross correlation):

Comparing the equations for the linear convolution and cross correlation we find that

rxy [l ] x[n] y[n l ] x[n] y[(l n)] x[l ] y[l ]
n n
. i.e., convolving the

reference signal with a folded version of sequence to be shifted (y[n]) results in cross
correlation output. (Use fliplr function for folding the sequence for correlation).
The properties of cross correlation are 1) the cross correlation sequence sample
values are upper bounded by the inequality rxx [l ] rxx [0]ryy [0] x y
2) The cross correlation of two sequences x[n] and y[n]=x[n-k] shows a peak at the
value of k. Hence cross correlation is employed to compute the exact value of the
delay k between the 2 signals. Used in radar and sonar applications, where the
received signal reflected from the target is the delayed version of the transmitted
signal (measure delay to determine the distance of the target).

3) The ordering of the subscripts xy specifies that x[n] is the reference sequence that
remains fixed in time, whereas the sequence y[n] is shifted w.r.t x[n]. If y[n] is the
reference sequence then ryx [l ] rxy [l ] . Hence ryx[l] is obtained by time reversing the
sequence rxy[l].

Algorithm:

1. Input the sequence as x and y.


2. Use the xcorr function to get cross correlated output r.
3. Plot the sequences.

MATLAB Implementation:

MATLAB has the inbuilt function XCORR: Say C = XCORR(A,B), where A and B
are length M vectors (M>1), returns the length 2*M-1 cross-correlation sequence C. If A and
B are of different length, the shortest one is zero-padded. Using convolution to implement
correlation, the instruction is FLIPLR Flip matrix in left/right direction. FLIPLR(X) returns X
with row preserved and columns flipped in the left/right direction. X = 1 2 3 becomes 3 2 1.

Cross Correlation

x1=input('enter first sequence'); % [1,2,3,-1,0,0];


x2=input('enter second sequence'); % [0,0,1,2,3,-1]; =x1[n-2],i.e., k=2
[r1,lag1]=xcorr(x1,x2)
__________________________________________________________________________________
_
45
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
figure(1)
subplot(3,1,1)
stem(x1);
title('input sequence1');
datacursormode on
subplot(3,1,2)
stem(x2)
title('input sequence2');
datacursormode on
subplot(3,1,3)
stem(lag1, r1);
title('cross correlation seq ');
xlabel('Lag index'); ylabel('Amplitude');

x3=input('enter third sequence'); % x3=[1,2,3,-1];


x4=input('enter fourth sequence'); % x4=[3,-1,1,2];
[r2,lag2]=xcorr(x3,x4)
[r3,lag3]=xcorr(x4,x3)
figure(2)
subplot(4,1,1)
stem(x3);
title('input sequence3');
datacursormode on
subplot(4,1,2)
stem(x4)
title('input sequence4');
datacursormode on
subplot(4,1,3)
stem(lag2, r2);
title('cross correlation seq ');
subplot(4,1,4)
stem(lag3, r3);
title('cross correlation seq in reverse order');
xlabel('Lag index'); ylabel('Amplitude');

RESULT

r1 = -1.0000 1.0000 5.0000 15.0000 5.0000 1.0000 -1.0000 0.0000 -0.0000


0 0.0000

lag1 = -5 -4 -3 -2 -1 0 1 2 3 4 5

r2 = 2.0000 5.0000 7.0000 2.0000 2.0000 10.0000 -3.0000

__________________________________________________________________________________
_
46
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
lag2 = -3 -2 -1 0 1 2 3

r3 = -3.0000 10.0000 2.0000 2.0000 7.0000 5.0000 2.0000

lag3 = -3 -2 -1 0 1 2 3

Fig 3.1Cross Correlation

__________________________________________________________________________________
_
47
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________

Fig 3.2 Cross correlation properties

__________________________________________________________________________________
_
48
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
Cross correlation using convolution and correlation commands

x = input('Type in the reference sequence = ');


y = input('Type in the second sequence = ');
% Compute the correlation sequence
n1 = length(y)-1;
n2 = length(x)-1;
a= conv(x,fliplr(y));
disp('Cross correlation output a is =');
disp(a);
k1 = (-n1):n2; %time vector for plotting
subplot(2,1,1)
stem(k1,a);
xlabel('Lag index'); ylabel('Amplitude');
title('Cross correlation using conv')
% Computation of Cross-correlation Sequence using xcorr function
b = xcorr(x,y);
%[b,lag]=xcorr(x,y);
disp('Cross correlation output b is =');
disp(b);
N=max(n1,n2) ;
k2 = (-N):N;
datacursormode on
subplot(2,1,2)
stem(k2 , b); %stem(lag,b);
xlabel('Lag index'); ylabel('Amplitude');
title('Cross correlation using xcorr')

Type in the reference sequence = [1 3 -2 1 2 -1 4 4 2]

Type in the second sequence = [2 -1 4 1 -2 3]

Cross correlation output a is =

3 7 -11 14 13 -15 28 6 -2 21 12 12 6 4

Cross correlation output b is =

-0.0000 -0.0000 0.0000 3.0000 7.0000 -11.0000 14.0000 13.0000 -15.0000


28.0000 6.0000 -2.0000 21.0000 12.0000 12.0000 6.0000 4.0000

__________________________________________________________________________________
_
49
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________

Fig 3.3 Cross correlation using conv and xcorr

__________________________________________________________________________________
_
50
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
Aim: To obtain auto correlation of the given sequence and verify its properties.

Theory (Auto Correlation):

Correlation is mathematical technique which indicates whether 2 signals are related and
in a precise quantitative way how much they are related. A measure of similarity between
a pair of energy signals x[n] and y[n] is given by the cross correlation sequence rxy[l]

defined by rxy [l ] x[n] y[n l ]; l 0,1,2,... .
n

The parameter l called lag indicates the time shift between the pair.

Autocorrelation sequence of x[n] is given by rxx [l ] x[n]x[n l ]; l 0,1,2,...
n

Some of the properties of autocorrelation are enumerated below

o The autocorrelation sequence is an even function i.e., rxx [l ] rxx [l ]


o At zero lag, i.e., at l=0, the sample value of the autocorrelation sequence has its maximum

value (equal to the total energy of the signal x) i.e., rxx [l ] rxx [0] x x
n
2
[ n] .

This is verified in Fig. 2, where the autocorrelation of the rectangular pulse (square) has a
maximum value at l=0. All other samples are of lower value. Also the maximum value =
11 = energy of the pulse [12+12+12..].

o A time shift of a signal does not change its autocorrelation sequence. For example, let
y[n]=x[n-k]; then ryy[l] = rxx[l] i.e., the autocorrelation of x[n] and y[n] are the same
regardless of the value of the time shift k. This can be verified with a sine and cosine
sequences of same amplitude and frequency will have identical autocorrelation functions.
o For power signals the autocorrelation sequence is given by
k
1
rxx [l ] lim
k 2k 1
x[n]x[n l ]; l 0,1,2,... and for periodic signals with period N it
n k

1 N 1
is rxx [l ] x[n]x[n l ]; l 0,1,2,... and this rxx[l] is also periodic with N. This is
N n 0
verified in Fig. 3 where we use the periodicity property of the autocorrelation sequence to
determine the period of the periodic signal y[n] which is x[n] (=cos(0.25*pi*n)) corrupted
by an additive uniformly distributed random noise of amplitude in the range [-0.5 0.5]

Algorithm:

1. Input the sequence as x.


2. Use the xcorr function to get auto correlated output r.
3. Plot the sequences.

MATLAB Implementation:

MATLAB has the inbuilt function XCORR(A), when A is a vector, is the auto-
correlation sequence. If A is of length M vector (M>1), then the xcorr function returns the
length 2*M-1 auto-correlation sequence. The zeroth lag of the output correlation is in the
middle of the sequence at element M.
__________________________________________________________________________________
_
51
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
XCORR(...,MAXLAG) computes the (auto/cross) correlation over the range of lags:
-MAXLAG to MAXLAG, i.e., 2*MAXLAG+1 lags. If missing, default is MAXLAG = M-1.

[C,LAGS] = XCORR(...) returns a vector of lag indices (LAGS).

Autocorrelation of rectangular sequence

%simple sequence
x2=[3,-1,2,1];
[r1,lag1]=xcorr(x2)
subplot(2,1,1)
stem(x2);
title('input sequence');
figure(1)
datacursormode on
subplot(2,1,2)
stem(lag1,r1)
title('autocorrelation output');
xlabel('Lag index'); ylabel('Amplitude');

%Computation of Autocorrelation of a rectangular Sequence


n = -5:5;
N=10;
% Generate the square sequence
x = ones(1,11);
% Compute the correlation sequence
r=xcorr(x);%[r,lag]=xcorr(x)
disp('autocorrelation sequence r=');
disp(r);
%plot the sequences
figure(2)
datacursormode on
subplot(2,1,1)
stem(n,x);
title('square sequence');
datacursormode on
subplot(2,1,2)
k = -N:N;
stem(k, r);%stem(lag,r)
title('autocorrelation output'); xlabel('Lag index'); ylabel('Amplitude');

__________________________________________________________________________________
_
52
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________

Fig 3.3 Auto correlation

Fig 3.4 Auto correlation

Inference: Following Autocorrelation properties are verified

1) Max peak of 11 (=energy of the pulse) at zero lag (l=0)

2)the autocorrelation sequence is an even function


__________________________________________________________________________________
_
53
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________

%Periodic signal computation of Autocorrelation of a Noise Corrupted Sinusoidal


Sequence

N = 30; %number of points of input


n = 1:N;
% Generate the sinusoidal sequence
x = cos(pi*0.25*n);
% Generate the noise sequence
d = rand(1,N) - 0.5;
%Generate the noise-corrupted sinusoidal sequence
y = x + d;
% Compute the autocorrelation sequence of corrupted signal
[ry,lag]=xcorr(y);
% Compute the autocorrelation sequence of noise
[rn,lag1]=xcorr(d);
%plot the sequences
figure(1)

datacursormode on
subplot(3,1,1)
stem(x);
title('reference sinusoidal sequence');
datacursormode on
subplot(3,1,2)
stem(y)
title('noise corrupted signal');
datacursormode on
subplot(3,1,3)
stem(lag, ry);
title('autocorrelation seq of corrupted signal');
xlabel('Lag index'); ylabel('Amplitude');
figure(2);
stem(lag1,rn);
title('autocorrelation seq of noise');
xlabel('Lag index'); ylabel('Amplitude');

__________________________________________________________________________________
_
54
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________

Fig 3.5 autocorrelation sequence of corrupted signal

__________________________________________________________________________________
_
55
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________

Fig 3.6 autocorrelation seq of noise

Inference: Auto correlation of noise component has a very strong peak only at zero lag. The
amplitudes are correspondingly smaller at other values of lag as the sample value of noise
generated by random function are uncorrelated with each other.

The plot of noise corrupted signal does not show any noticeable periodicity, but its
autocorrelation sequence has distinct peaks at lags that are multiples of N=8 indicating that it
is periodic with N=8.

Cos(0.25n)=cos(n)

=2f=0.25

N=1/f=2/0.25=8

__________________________________________________________________________________
_
56
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________

Experiment 4. Solving a given difference equation.

Aim: To obtain the impulse response/step response of a system described by the given
difference equation

Theory:

A difference equation with constant coefficients describes a LTI system. For example
the difference equation y[n] + 0.8y[n-2] + 0.6y[n-3] = x[n] + 0.7x[n-1] + 0.5x[n-2]
describes a LTI system of order 3. The coefficients 0.8, 0.7, etc are all constant i.e.,
they are not functions of time (n). The difference equation y[n]+0.3ny[n-1]=x[n]
describes a time varying system as the coefficient 0.3n is not constant.
The difference equation can be solved to obtain y[n], the output for a given input x[n]
by rearranging as y[n] = x[n] + 0.7x[n-1]+0.5x[n-2]- 0.8y[n-2]- 0.6y[n-3] and solving.
The output depends on the input x[n]
o With x[n]= [n], an impulse, the computed output y[n] is the impulse
response.
o If x[n]=u[n], a step response is obtained.
o If x[n] = cos(wn) is a sinusoidal sequence, a steady state response is obtained
(wherein y[n] is of the same frequency as x[n], with only an amplitude gain
and phase shift).
o Similarly for any arbitrary sequence of x[n], the corresponding output
response y[n] is computed.
The difference equation containing past samples of output, i.e., y[n-1], y[n-2], etc
leads to a recursive system, whose 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=). The MATLAB function filter is used to compute the impulse
response/ step response/ response to any given x[n]. Note: The filter function
evaluates the convolution of an infinite sequence (IIR) and x[n], which is not possible
with conv function (remember conv requires both the sequences to be finite).
The difference equation having only y[n] and present and past samples of input (x[n],
x[n-k]), represents a system whose impulse response is of finite duration (FIR). The
response of FIR systems can be obtained by both the conv and filter functions. The
filter function results in a response whose length is equal to that of the input x[n],
whereas the output sequence from conv function is of a longer length (xlength +
hlength-1).

Algorithm:

1. Input the two sequences as a and b representing the coefficients of y and x.


2. If IIR response, then input the length of the response required (say 100, which can be
made constant).
3. Compute the output response using the filter command.
4. Plot the input sequence & impulse response (and also step response, etc if required).

__________________________________________________________________________________
_
57
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________

MATLAB Implementation:

MATLAB has an inbuilt function filter to solve difference equations numerically, given
the input and difference equation coefficients (b,a). y=filter(b,a,x) where x is the input
sequence, y is the output sequence which is of same length as x. Given a difference equation
a0y[n]+a1y[n-1]+a2y[n-2]=b0x[n]+b2x[n-2], the coefficients are written in a vector as b=[b0 0
b2] and a=[a0 a1 a2]. Note the zero in b (x[n-1] term is missing). Also remember a 0, the
coefficient of y[n] should always be 1.

For impulse response x[ n] {1,0,0,0,....} the number of zeros = the length of the IIR response

required (say 100 implemented by function zeros(1,99)). For step response x[ n] {1,1,1,1,1,....}

the number of ones = the length of the IIR response required-1 (say 100 implemented by
function ones(1,100). Similarly for any given x[n] sequence, the response y[n] can be
calculated.

Given Problem

1)Difference equation y(n) - y(n-1) + 0.9y(n-2) = x(n);

(i) Calculate impulse response h(n) and

(ii) Calculate step response at n=0,..,100

2)Plot the steady state response y[n] to x[n]=cos(0.05n)u(n), given y[n]-0.8y[n-1]=x[n]

MATLAB Program:

(i) Calculation of impulse response

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


b=[1]; %x[n] coefficient
a=[1,-1,0.9]; %y coefficients
%impulse input
x=[1,zeros(1,N-1)];

%time vector for plotting


n=0:1:N-1;
%impulse response
y=filter(b,a,x);

%plot the waveforms


datacursormode on
subplot(2,1,1);
__________________________________________________________________________________
_
58
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
stem(n,x);
title('impulse input');
xlabel('n');
ylabel('impulse');
datacursormode on
subplot(2,1,2);
stem(n,y);
title('impulse response');

xlabel('n');
ylabel('h(n)');

Fig 4.1 Difference equation-impulse response

(i) Calculation of step response

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


b=[1]; %x[n] coefficient
a=[1,-1,0.9]; %y coefficients
x=[ones(1,N)]; %step input
n=0:1:N-1; %time vector for plotting
%n1=1:N;
y=filter(b,a,x); %step response
%plot the waveforms
datacursormode on
__________________________________________________________________________________
_
59
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
subplot(2,1,1);
stem(n,x);
title('step input');
xlabel('n');
ylabel('u(n)');
datacursormode on
subplot(2,1,2);
stem(n,y);
title('step response');
xlabel('n');
ylabel('y(n)');

Fig 4.2 Difference equation step response

(i) Finding steady state response

%To find steady state response


%y[n]-0.8y[n-1]=x[n]
N=input('Length of response required=');
b=[1]; %x[n] coefficient
a=[1,-0.8]; %y coefficients
n=0:1:N-1; %time vector

__________________________________________________________________________________
_
60
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
x=cos(0.05*pi*n); % sinusoidal input
y=filter(b,a,x); %steady state response
subplot(2,1,1);
stem(n,x);
title('sinusoidal input');
xlabel('n');
ylabel('x[n]');
% datacursormode on
subplot(2,1,2);
stem(n,y);
title('steady state response');
xlabel('n');
ylabel('y(n)');

Fig 4.3 Steady state response (diff eqn)

__________________________________________________________________________________
_
61
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

Experiment 5: Computation of N point DFT of a given sequence and to plot


magnitude and phase spectrum (using DFT equation and verify it by built-in
routine).

Aim: To compute DFT of the given sequence.

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 2kn

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 2kn
1 N 1
x[n] x[n]e N ; n 0,1,2,....N - 1
N k 0

X(k) is a complex number (ejw=cosw + j sinw). 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.
Since N L , increasing N to 8 from 80 for the same x[n] implies x[n] is still
the same sequence (<8), the rest of x[n] is padded with zeros. This implies that
there is no further information in time domain, but the resulting spectrum has
higher frequency resolution. This spectrum is known as high density
spectrum (resulting from zero padding x[n]). Instead of zero padding, for
higher N, if more number of points of x[n] are taken (more data in time
domain), then the resulting spectrum is called a high resolution spectrum.

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.

62
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

MATLAB Implementation:

MATLAB has an inbuilt function FFT which computes the Discrete Fourier
transform. FFT(X) is the discrete Fourier transform (DFT) of vector X. For length N
input vector x, the DFT is a length N vector X, with elements N. FFT(X,N) is the N-
point FFT, padded with zeros if X has less than N points and truncated if it has more.
The magnitude spectrum is computed using the function ABS Absolute value.
ABS(X) is the absolute value of the elements of X. When X is complex, ABS(X) is
the complex modulus (magnitude) of the elements of X. The phase spectrum is
computed using the function ANGLE Phase angle. ANGLE (H) returns the phase
angles, in radians, of a matrix with complex elements.

x= input(Enter a sequence x[n]=); % Enter a sequence x[n]= [1,2,3,6];


N=input(Enter the value of N=) % Enter the value of N=4
xk=fft(x,N); %computes DFT
disp(The DFT values of x[n] are xk=);
disp(xk);

% compute & plot amplitude spectrum


n=0:1:N-1;
mag= abs(xk);
figure(1);
stem(n,mag);
xlabel(' k');
ylabel('lxkl');
title('Magnitude spectrum');

% phase spectrum
phase= angle(xk)
figure(2);
datacursormode on
stem(n,phase);
xlabel(' k');
ylabel('angle(xk)');
title('phase spectrum');
figure(3);
n1=0:1:length(x)-1;
datacursormode on
stem(n1,x);
xlabel(' n');
ylabel('x[n]');
title('original signal');

63
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

RESULT
Enter a sequence x[n]= [1,2,3,6];
Enter the value of N=4
The DFT values of x[n] are xk =12.0000, -2.0000 + 4.0000i, -4.0000, -2.0000 -
4.0000i
mag =12.0000 4.4721 4.0000 4.4721
phase =0 2.0344 3.1416 -2.0344

original signal
6

4
x[n]

0
0 0.5 1 1.5 2 2.5 3
n
phase spectrum
4

1
angle(xk)

-1

-2

-3 64
0 0.5 1 1.5 2 2.5 3
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

Magnitude spectrum
12

10

8
lxkl

0
0 0.5 1 1.5 2 2.5 3
k

Fig 5.1 N point DFT

65
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

Experiment 6: (i) Verification of DFT properties (like Linearity and Parsevals


theorem, etc.) (ii) DFT computation of square pulse and Sinc function etc.

Summary of DFT properties

1) Time shift property

clc; clear all; close all;

x = input('Enter the sequence'); %[3 1 5 2 4]


N = length(x) % N: data length
m=input('Enter the value by which the sequence has to be shifted');
n = 0:N-1
a=mod(n-m,N);
b=x(a+1)% time shifted sequence
subplot(3,1,1)
stem(n,x)
title('original sequence');
subplot(3,1,2)
stem(n,b)
title('shifted sequence');

W = exp(2*pi/N*sqrt(-1));
X = fft(x);
k = [0:N-1]; % frequency index
G = W.^(-m*k) .* X;
g = ifft(G)
subplot(3,1,3)
stem(k,g)
title('time domain sequence obtained from frequency domain sequence');

66
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

RESULT

Enter the sequence [3 1 5 2 4]


N= 5
Enter the value by which the sequence has to be shifted 2
n= 0 1 2 3 4
b= 2 4 3 1 5
g = 2.0000 - 0.0000i 4.0000 + 0.0000i 3.0000 - 0.0000i 1.0000 - 0.0000i 5.0000
+ 0.0000i

Fig 6.1 Time shift property

2) Time reversal property

clc; clear all; close all;


x = input('Enter the sequence');% x =1 3 5 2
N=length(x)
n = 0:N-1;
b=x(mod(-n,N)+1) % b =1 2 5 3
subplot(3,1,1)
stem(n,x)
title('original sequence');
subplot(3,1,2)

67
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

stem(n,b)
title('folded sequence');

X = fft(x);
k = [0:N-1]; % frequency index
G=X(mod(-k,N)+1)
g = ifft(G)
subplot(3,1,3)
stem(k,g)
title('time domain sequence obtained from frequency domain sequence');

RESULT

Enter the sequence [1 3 5 2]


N= 4
b= 1 2 5 3
G = 11.0000 -4.0000 + 1.0000i 1.0000 -4.0000 - 1.0000i
g= 1 2 5 3

Fig 6.2 Time reversal property

3) Linearity property

%dft(a.x1+b.x2)=dft(a.x1)+dft(b.x2)----Linearity property

clc; clear all; close all;


x1 = input('Enter the sequence x1');% x1 =1 3 5 2

68
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

x2 = input('Enter the sequence x2');% x2 =2 5 7 3


a=input('Enter the scalar quantity with which x1 need to be multiplied'); %2
b=input('Enter the scalar quantity with which x2 need to be multiplied'); %3
N=length(x1);
n = 0:N-1;
X1 = fft(x1);
X2 = fft(x2);
ax1=a*x1;
aX1=fft(ax1);
bx2=b*x2;
bX2=fft(bx2);
g1=(ax1+bx2);
G1=fft(g1)
G2=aX1+bX2

RESULT

Enter the sequence x1 [1 3 5 2]


Enter the sequence x2 [2 5 7 3]
Enter the scalar quantity with which x1 need to be multiplied 2
Enter the scalar quantity with which x2 need to be multiplied 3
G1 = 73.0000 -23.0000 - 8.0000i 5.0000 -23.0000 + 8.0000i
G2 = 73.0000 -23.0000 - 8.0000i 5.0000 -23.0000 + 8.0000i

4) Parsevals theorm

%Parsevals theorm

clc; clear all; close all;


x = input('Enter the sequence x');% x =1 3 5 2
g = input('Enter the sequence g');% g =2 5 7 3
N=length(x);
n = 0:N-1;
X = fft(x);
G = fft(g);
T=sum(x.*conj(g))
F=sum(X.*conj(G))/N

RESULT
Enter the sequence x[1 3 5 7]
Enter the sequence g[2 5 7 3]
T = 73
F = 73

69
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

FFTSHIFT shifts zero-frequency component to center of spectrum. FFTSHIFT


is useful for visualizing the Fourier transform with the zero-frequency
component in the middle of the spectrum.

ii)a) DFT of sinc function

clc; clear all; close all;

fs=100;
t=-1:1/fs:1;
f=5;
y=sinc(pi*t*f);
subplot(2,1,1);
plot(t,y);
xlabel('x');
ylabel(' magnitude');

N=512;
fy=(fft(y,N));
subplot(2,1,2);
fr=(0:N-1)*fs/N;

plot(fr,fftshift(abs(fy)));
xlabel(' frequency x^{-1}');
ylabel(' magnitude');

Fig 6.3 DFT of SInc function

70
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

b) DFT of square pulse

clc; clear all; close all;


clc; clear all; close all;
x1=[zeros(1,32),ones(1,64),zeros(1,32)];
X1=fft(x1);
X2=fftshift(X1);
subplot(2,1,1)
plot(x1);
title('time domain');
subplot(2,1,2)
plot(abs(X2));
title('frequency domain');

Fig 6.4 DFT of square pulse

71
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

Experiment 7: Design and implementation of FIR filter to meet given


specifications (using different window techniques).

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

Theory:

There are two types of systems Digital filters (perform signal filtering in time
domain) and spectrum analyzers (provide signal representation in the frequency
domain). The design of a digital filter is carried out in 3 steps- specifications,
approximations and implementation.

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.

72
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

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);
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

73
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

Table: Commonly used window function characteristics

Matlab Window Transition Width Min. Stop band


Name Approximate Exact Attenuation
Command values

Rectangular 4 1.8 21db B =FIR1(N,Wn,boxcar)


M M

Bartlett 8 6.1 25db B FIR1(N,Wn,bartlett)


M M

Hanning 8 6.2 44db B=FIR1(N,Wn,hanning)


M M

Hamming 8 6.6 53db B=FIR1(N,Wn,hamming)


M M

Blackman 12 11 74db B=FIR1(N,Wn,blackman)


M M

Program:

%Method 2: the following program gives only the design of the FIR filter- for
%implementation continue with the next program (after h[n]) input data to be given:
Passband & Stopband frequency

% Data given: Passband ripple & stopband attenuation As. If As>40 dB, Choose
%hamming

clear
Fpa=input('Enter passband edge frequency in Hz');
Fsa= input('Enter stopband edge frequency in Hz');
Fs1= input('Enter sampling frequency in Hz');
%Calculate transmission BW,Transition band tb,order of the filter
wpd=2*pi*Fpa/Fs1;
wsd=2*pi*Fsa/Fs1;
tb=wsd-wpd;
N=ceil(6.6*pi/tb)

74
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

Wc=(wsd+wpd)/2
%compute the normalized cut off frequency
wc=Wc/pi
fc=wc*Fs1/2
%calculate & plot the window
hw=hamming(N+1);
figure (1)
datacursormode on
stem(hw);
title('Fir filter window sequence- hamming window');
%find h(n) using FIR
h=fir1(N,wc,hamming(N+1));
%plot the frequency response
figure(2);
[m,w]=freqz(h,1,128);
mag=20*log10(abs(m));
datacursormode on
plot(Fs1*w/(2*pi),mag);
title('Fir filter frequency response');
grid;

%generate simulated input of 50, 300 & 200 Hz, each of 30 points
n=1:30;
fi1=50;f2=300;f3=200;fs=1000;
%fi1=150;f2=300;f3=170;fs=1000;

x=[];
x1=sin(2*pi*n*fi1/fs);
x2=sin(2*pi*n*f2/fs);
x3=sin(2*pi*n*f3/fs);
x=[x1 x2 x3];
figure (3)
datacursormode on
subplot(2,1,1);

stem(x);
title('input-fi1=150;f2=300;f3=170;fs=1000');
y=filter(h,1,x);
datacursormode on
subplot(2,1,2);
stem(y);
title('output with cutoff freq fc=150Hz');

75
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

FIR
passband edge frequency =100Hz,stopband edge frequency 200Hz, sampling
frequency 1000Hz.

Find the output for (a) fi1=150;f2=300;f3=170;fs=1000 (b)


fi1=50;f2=300;f3=200;fs=1000; for different windows.

Fig 7.1 FIR filter window sequence (hamming window)

76
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

Fig 7.2 FIR filter frequency response (hamming window)

Fig 7.3 Filter output (fi1=150; f2=300; f3=170; fs=1000;)

77
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

Fig 7.4 Filter output (fi1=50; f2=300; f3=200; fs=1000;)

Fig 7.5 Rectangular window

78
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

Fig 7.6 Frequency response (Rectangular window )

Fig 7.7 Filter output (fi1=50; f2=300; f3=200; fs=1000;)

79
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

Fig 7.8 Filter output fi1=150;f2=300;f3=170;fs=1000

Experiment 8: Design and implementation of IIR filter to meet given


specifications.

Aim: To design and implement an IIR filter for given specifications.

Theory:

There are two methods of stating the specifications as illustrated in previous


program. In the first program, the given specifications are directly converted to digital
form and the designed filter is also implemented. In the last two programs the
butterworth and chebyshev filters are designed using bilinear transformation (for
theory verification).

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

80
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

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');

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,

81
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

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.

%generate filter coefficients for the given %order & cutoff Say N=2, fc=150Hz,
%fs=1000 Hz, butterworth filter

[b,a]=butter(2, 150/(1000/2));
% wc=[150/(1000/2) 250/(1000/2)];
% [b,a]=butter(4, wc);
%[b,a]=butter(2, 150/(1000/2), 'HIGH');
%wc=[150/(1000/2) 250/(1000/2)];
% [b,a]=butter(4, wc,'STOP');

%generate simulated input of 100, 300 & 170 Hz, each of 30 points
n=1:30;
f1=100;fi2=300;f3=170;fs=1000;
x=[];
x1=sin(2*pi*n*f1/fs);
x2=sin(2*pi*n*fi2/fs);
x3=sin(2*pi*n*f3/fs);
x=[x1 x2 x3];
datacursormode on
subplot(2,1,1);
stem(x);
title('input');
%generate o/p
y=filter(b,a,x);
82
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

datacursormode on
subplot(2,1,2);
stem(y);
title('output');

% Note: If fp,fstp,fs, rp,As are given then use


% [N,wc]=buttord(2*fp/fs,2*fstp/fs,rp,As)
% [b,a]=butter(N,wc);
%
% If wp & ws are in radians
% [N,wc]=buttord(wp/pi,ws/pi,rp,As)
% [b,a]=butter(N,wc);
%
% If wc is in radians & N is given
% [b,a]=butter(N,wc/pi);
%
% For a bandpass output
% wc=[150/(1000/2) 250/(1000/2)];
% [b,a]=butter(4, wc);
Q1. Design an IIR Butterworth (Low pass/ High pass) filter using MATLAB to meet
given specifications: order of the filter N=2, cutoff frequency fc=150Hz, sampling
frequency fs=1000 Hz, Implement the filter by generating simulated input of 100, 300
& 170 Hz, each of 30 points

Q2. Design an IIR Butterworth (Band pass/ Band stop) filter using MATLAB to meet
given specifications: order of the filter N=2, lower frequency f1=150Hz,upper
frequency f2=250Hz, sampling frequency fs=1000 Hz, Implement the filter by
generating simulated input of 100, 300 & 170 Hz, each of 30 points

83
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

Fig 8.1 IIR Low pass filter

Fig 8.2 BAND PASS IIR

84
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

Fig 8.3 High pass filter [b,a]=butter(2, 150/(1000/2), 'HIGH');

Fig 8.4 BANDSTOP IIR

85
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

STEPS FOR EXECUTION OF CCSTUDIO SOFTWARE

1) Start --->>--All programs --->>--Texas Instruments

2) Code composer studio 5.3.0 --->>--Code composer studio 5.3.0


3) File---->>--New --->>--Target configuration

86
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

4) File Name-->>-----xyz.ccxml 5) Finish

6) Basic window: Connection------------Texas Instruments XDS100V1USB Emulator

Device -----------------TMS320C6748-------- Save

87
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

7) Same window--- click advanced option-----Select c674x-0-------Browse

L138 sub port (C drive): Select c6748.gel, open

88
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

Save

8) View ------>>-----Target configuration

89
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

Userdefined -> right click filename.ccxml-- Launch selected configuration

Switch ON the board


Right click Texas Instruments XDS100V1USB - Connect target -- Error window opens

90
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

9) Reset the device (Hardware)by Reset switch (S5)


10) Click Retry (Now it will connect)

91
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

11) File-------->>---New--- project

92
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

12) CCS Project

Project Name

Output type--->>--executable

Family--->>---------C6000

Variant ---------->>-----Empty---------->>--------TMS320C6748

Connection--->>----------Texas Instrument XDS100V1USB Emulator

93
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

Advanced settings--- linker command file

To Add link file

Browse ---->>--------C drive

L138 Sub port

Select---------->>-------Linker -dsp.cmd

Finish

94
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

13) Type the program--------->>---------save

14)

Project

15) Build all

95
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

16) Run
17) Load
18) Load program

96
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

19) Browse project- project name-- debug

97
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

20) Select file name.out

21) Run

98
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

22) Resume

23) Output seen in console

EXPERIMENT 9: Linear convolution of two given sequences

99
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

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>
# include<math.h>
float y[10];
main()
{//the two sequences can be of different lengths, no need to zero pad for this
program
float h[4] = { 2,2,2,2}; float x[4] ={1,2,3,4};

int xlen=4; int hlen=4;


int N=xlen+hlen-1;
int k,n;
for(n=0;n<N;n++) //outer loop for y[n] array
{ y[n]=0;
for(k=0;k<hlen;k++) //inner loop for computing each y[n] point
{ if (((n-k)>=0) & ((n-k)<xlen))
y[n]=y[n]+h[k]*x[n-k]; //compute output
} //end of inner for loop
printf("%f\t", y[n]);
} //end of outer for loop
} //end of main

Result

6.000000 12.000000 20.000000 18.000000 14.000000 8.000000

100
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

EXPERIMENT 10 : Circular convolution of two given sequences.

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>
main()
{ //input the two sequences, if of uneven lengths zero pad the smaller one such that
both are of same size
float x[5]={1,2,3,4,5};
float h[5]={2,1,3,4,5};
float y[10]; //output sequence
int N=5; // N=max of xlen and hlen//
int k,n,i;
for(n=0;n<N;n++) //outer loop for y[n] array
{ y[n]=0;
for(k=0;k<N;k++) //inner loop for computing each y[n] point
{ i=(n-k)%N; //compute the index modulo N
if(i<0) //if index is <0, say x[-1], then convert to x[N-1]
i=i+N;
y[n]=y[n]+h[k]*x[i]; //compute output
} //end of inner for loop
printf("%f\t",y[n]);
} //end of outer for loop
} //end of main

Result

41.000000 51.000000 51.000000 46.000000 36.000000

101
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

EXPERIMENT 11: Computation of N- Point DFT of a given sequence

Aim: To compute the N (=4/8/16) point DFT of the given sequence

Theory:

The N point DFT of discrete time signal x[n] is given by the equation
N -1 j 2kn

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]. To implement using C


j 2kn
2kn 2kn
program we use the expression e cosN
j sin and allot memory
N N
space for real and imaginary parts of the DFT X(k)

C Program

#include <stdio.h>

#include <math.h>

main()

{float y[16]; //for 8 point DFT to store real & imaginary

float x[4]={1,3,2,5}; //input only real sequence

float w;

int n,k,k1,N=8,xlen=4;

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

{y[k]=0; y[k+1]=0; //initialize real & imag parts

k1=k/2; //actual k index

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

102
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

{w=-2*3.14*k1*n/N; //careful about minus sign

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]);

}//end of main

Result: (on std out)

11.000000+j0.000000 -0.407551+j-7.660230 -1.009554+j1.996801

2.424618+j-3.646700 -4.999950+j-0.022297 2.396780+j3.673694

-0.971311+j-2.009436 -0.460726+j7.633037

MATLAB verification

>> x=[1 3 2 5];

>> fft(x,8) 11.0000 -0.4142 - 7.6569i -1.0000 + 2.0000i 2.4142 -


3.6569i -5.0000 2.4142 + 3.6569i -1.0000 - 2.0000i -0.4142 + 7.6569i

103
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57

EXPERIMENT 12: Impulse response of first order and second order system

Aim: To find the Impulse response of the given first order / second order system

Theory:

A linear constant coefficient difference equation representing a second order


system is given by y[n] a1 y[n 1] a 2 y[n 2] b0 x[n] b1 x[n 1] b2 x[n 2];

For a first order system the coefficients a2 and b2 are zero.

Since the difference equation contains past samples of output, i.e., y[n-1], y[n-2], 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=).

Impulse response implies x[n]= [n], an impulse, and the initial conditions x[-1],
x[-2], y[-1] and y[-2] are zero.

(refer expt 2 &7of part A - h=impz(b,a,N); %impulse response verification in


MATLAB)

To implement in C the following algorithm is used.

Algorithm

1. Input the coefficients b0 b1 b2, a1 a2 (Say the coefficients from a 2nd order
butterworth filter. Note coefficient of y[n] is a0=1 always)
2. Generate the impulse input of size n (1st element=1, rest all=0)
3. Compute the output as
y[n] a1 y[n 1] a 2 y[n 2] b0 x[n] b1 x[n 1] b2 x[n 2];
4. Repeat step 3 for n=0 through N (say 50,100, etc)
C Program

104
#include <stdio.h>
float x[60],y[60];
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;
//generate impulse input
x[0]=1;
for(i=1;i<N;i++)
x[i]=0;
//generate output
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)
y[j]=y[j]+b2*x[j-2]-a2*y[j-2];
printf("%f \t",y[j]);
}
}//end of main
Note: For a first order system just enter a2=0 and b2=0.
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
MATLAB verification
[b,a]=butter(2,0.2) //copy the coeffs into C program
x=impz(b,a,20)
x = 0.0675 0.2120 0.2819 0.2347 0.1519 0.0767 0.0250 -0.0031 -
0.0139
-0.0146 -0.0109 -0.0065 -0.0029 -0.0006 0.0005 0.0008 0.0007 0.0005
0.0003 0.0001
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL- 15ECL57
_____________________________________________________________________

EXPERIMENT 13: FIR FILTER DESIGN

Aim: To find the coefficients of FIR filter using Hamming window.

#include<stdio.h>
#include<math.h>
int main(void)
{
int N,n;
float wc,*hd,*w,*h,pi,alp;
hd=(float*)0x0000100;
h=(float *)0x0000200;
pi=3.1456;
printf("enter the order");
scanf("%d",&N);
printf("enter the cutoff freq");
scanf("%f",&wc);
alp=(N-1)/2;
for(n=0;n<N;n++)
{
if(n==alp)
{
hd[n]=wc/pi;
}
else
{
hd[n]=sin(wc*(n-alp))/(pi*(n-alp));
}
}
for(n=0;n<N;n++)
{
w[n]=0.54-0.46*cos((2*pi*n)/(N-1));
h[n]=hd[n]*w[n];
printf("h[%d]=%f\n",n,h[n]);
}
return 0;
}

Enter the order N=7,


Enter the frequency wc=1

h[0]=0.001196
h[1]=0.044883
h[2]=0.206265
h[3]=0.317903
h[4]=0.205410

109
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL- 15ECL57
_____________________________________________________________________
h[5]=0.044422
h[6]=0.001197
EXTRA EXPERIMENTS

Impulse response of a given system

Aim:

To find the impulse response h(n) of the given LTI system whose response y(n) to an
input x(n) is given.

Theory:

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
Y ( z ) b0 b1 z 1 b2 z 2
difference 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. 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].
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.
Given Problem

1) Find the impulse response h(n) of the given LTI system whose response y(n)=[1 4
8 8 3 -2 -1] to an input x(n)=[1 2 3 1] is given (FIR).

110
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL- 15ECL57
_____________________________________________________________________
2) A LTI system is described by the difference equation y(n) - y(n-1) + 0.9y(n-2) =
x(n);

Find its impulse response h(n) at n=0,..,100. (IIR)

Algorithm for Problem1:

1. Input the two sequences as x and y.


2. Use impz function to get the impulse response h.
3. Plot the sequences.

Algorithm for Problem2:

1. Input the two coefficient arrays as b and a.


2. Input the length of the impulse response required as N.
3. Use impz unction to get impulse response h.
4. Plot the impulse response.

MATLAB Implementation:

h=deconv(y,x): y the output sequence should be of longer length than x.


DECONV -Deconvolution and polynomial division. [Q,R] = DECONV(B,A)
deconvolves vector A out of vector B. The result is returned in vector Q and the
remainder in vector R such that B = conv(A,Q) + R. If A and B are vectors of
polynomial coefficients, deconvolution is equivalent to polynomial division. The
result of dividing B by A is quotient Q and remainder R. (Remember conv is
polynomial multiplication).

Note: Valid y and x should be given, else the conv verification will result in a
slightly different y (because of the remainder generated by deconv).

h=impz(b,a,N), returns the impulse response h[n], where b and a are


coefficient arrays obtained from difference equation, N = length of the response
required. (refer expt.7). For the given difference equation b=[1]; a=[1 -1 0.9].

IMPZ Impulse response of digital filter. [H,T] = IMPZ(B,A) computes the


impulse response of the filter B/A choosing the number of samples for you, and
returns the response in column vector H and a vector of times (or sample intervals) in
T (T = [0 1 2 ...]').

[H,T] = IMPZ(B,A,N) computes N samples of the impulse response.

1) Find the impulse response h(n) of the given LTI system whose response y(n)=[1 4
8 8 3 -2 -1] to an input x(n)=[1 2 3 1] is given (FIR).

y= input('The output sequence y(n) of the system=');


x=input('the input sequence of the system=');

111
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL- 15ECL57
_____________________________________________________________________
h=impz(y,x,length(y)-length(x)+1);
disp('the impulse response of the system is=');
disp(h);
%graphical display part
N=length(h);
n=0:N-1;
subplot(2,1,1)
stem(n,h);
xlabel('Time index n');
ylabel('Amplitude');
title('impulse response of a system')
subplot(2,2,3)
stem(0:length(x)-1,x);
xlabel('Time index n');
ylabel('input x');
title('input')

subplot(2,2,4)
stem(0:length(y)-1,y);
xlabel('Time index n');
ylabel('output y');
title('output')

[h1,r]=deconv(y,x)

%Verification
yv=conv(x,h);
yv1=conv(x,h1)+r

RESULT

The output sequence y(n) of the system=[1 4 8 8 3 -2 1]

the input sequence of the system=[1 2 3 1]

the impulse response of the system is= [1 2 1 -1]

h1 = 1 2 1 -1

r= 0 0 0 0 0 0 2

yv1 = 1 4 8 8 3 -2 1

112
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL- 15ECL57
_____________________________________________________________________

Fig IMPULSE RESPONSE FIR

2) A LTI system is described by the difference equation y(n) - y(n-1) + 0.9y(n-2) =


x(n); Find its impulse response h(n) at n=0,..,100. (IIR)

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


b=[1]; %x[n] coefficient
a=[1,-1,0.9]; %y coefficients
h=impz(b,a,N); %impulse response

%Plot the Impulse Response Sequence


n=0:N-1; %time vector for plotting
figure(1)
stem(n,h);
title('impulse response');
xlabel('n');
ylabel('h(n)');

113
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL- 15ECL57
_____________________________________________________________________
RESULT

Length of impulse response required=100

Fig IMPULSE RESPONSE IIR

114
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL- 15ECL57
_____________________________________________________________________

Design of Butterworth and Chebyshev filters

(a) Butterworth filter


% Butterworth filter: Given data: Ap=1dB, As=40dB, w1=800, w2=1200,ws=3600;
Ap=1
As=40
w1=800
w2=1200
ws=3600
% Analog frequency
aw1= 2*pi*w1/ws
aw2=2*pi*w2/ws

% Prewrapped frequency
pw1 = 2*tan(aw1/2)
pw2 = 2*tan(aw2/2)
%Calculate order and cutoff freq
[n,wc]= buttord (pw1,pw2,Ap,As,'s')

% analog filter transfer


[b,a] = butter(n,wc,'s')

% obtaining the digital filter using bilinear transformation


fs=1;
[num,den]= bilinear(b,a,fs)

%plot the frequency response


[mag,freq1]=freqz(num,den,128)
freq=freq1*ws/(2*pi)
m = 20*log10(abs(mag))
datacursormode on
plot(freq,m);
grid;

115
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL- 15ECL57
_____________________________________________________________________

BUTTERWORTH FILTER

(b) Chebyshev filter

%To design a chebyshev filter for given specifications


%Given data
Ap=1,As=40,w1=800,w2=1200,ws=3600

%Analog frequencies
aw1= 2*pi*w1/ws;
aw2=2*pi*w2/ws;

% Prewrapped frequency assuming T=1/fs


pw1 = 2*tan(aw1/2);
pw2 = 2*tan(aw2/2);

[n,wc]= cheb1ord (pw1,pw2,Ap,As,'s');


[b,a] = cheby1(n,Ap,wc,'s');

116
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL- 15ECL57
_____________________________________________________________________

% obtaining the digital filter using bilinear transformation


fs=1;
[num,den]= bilinear(b,a,fs);

%plot the frequency response


[mag,freq1]=freqz(num,den,128);
freq=freq1*ws/(2*pi);
m = 20*log10(abs(mag));
plot(freq,m);
grid;

CHEBYSHEV FILTER

117
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL- 15ECL57
_____________________________________________________________________

118
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL- 15ECL57
_____________________________________________________________________

119
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL- 15ECL57
_____________________________________________________________________
VIVA QUESTIONS

What is MATLAB?
What are the applications of MATLAB?
State sampling theorem.
What is meant by Nyquist rate and Nyquist criteria?
Explain scaling and superposition properties of a system.
What is meant by linearity of a system and how it is related to scaling and superposition?

What is meant by impulse response?


What is impulse function?
What is energy signal? How to calculate energy of a signal?
What is power signal? How to calculate power of a signal?
Differentiate between even and odd signals.
Explain time invariance property of a system with an example.
What is memory less system?
When a system is said to have memory?
What is meant by causality?
Explain linear convolution and circular convolution.
What is the length of linear and circular convolutions if the two sequences are having the length n1 and n2?
What are Fourier series and Fourier transform?
What are the advantages and special applications of Fourier transform, Fourier series, Z transform and Laplace
transform?
Differentiate between DTFT and DFT. Why it is advantageous to use DFT in computers rather than DTFT?
In DTFT, frequency appears to be continuous. But, in DFT, frequency is discrete. This property is useful for
computation in computers
How to perform linear convolution using circular convolution?
If two signals x (n) and y (n) are of length n1 and n2, then the linear convoluted output z (n) is of length n1+n2-1.
Each of the input signals is padded with zeros to make it of length n1+n2-1. Then circular convolution is done on
zero padded sequences to get the linear convolution of original input sequences x (n) and y (n).
What is meant by correlation?
Correlation is the measure of similarity between two signal/waveforms. It compares the waveforms at different
time instants.
What is auto-correlation?
It is a measure of similarity of a signal/waveform with itself.
What is cross-correlation?
What are the advantages of using autocorrelation and cross correlation properties in signal processing fields?
How auto-correlation can be used to detect the presence of noise?
Differentiate between IIR filters and FIR filters.
What is the procedure to design a digital Butterworth filter?
What is the difference between Butterworth, Chebyshev I and Chebyshev II filters?
What are difference equations and differential equations?
What is non real time processing?
What is meant by real time processing?
What is a Digital Signal Processor (DSP)?
Differentiate between RISC and CISC architectures.
Differentiate between General purpose MPU(Micro Processor Unit) and DSP Processor

120
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL- 15ECL57
_____________________________________________________________________
What is pipelining?
What is parallel processing?
What is MAC?
Differentiate between floating point DSP and fixed point DSP.
What is barrel shifter? Why it is advantageous to use it in DSP processor?
What is code composer studio?
Explain Von-Neumann and Harvard architectures
What are Line-in, Line-out, Mic-in, Mic-out?
What do you mean by signal processing system?
What is the use of Random Signals?
Classify Systems.
What do you mean by aliasing in digital signal processing? How it can be avoided?
Which function is used to perform 2D DFT using FFT algorithm?
Which function is used to find the impulse invariant IIR digital filter?
Which function is used to find correlation of a sequence?
Why we need circular convolution?
What is the difference between circular & linear convolution?
What is the length of output sequence after circular convolution if the lengths of input & impulse responses are
M1 & M2 respectively?
State the circular convolution property of DFT?
Where we required convolution property?
What does zero padding mean? Where we required this concept?

What is difference between linear shifting & circular shifting of signal? Show with example.

What is difference between linear & circular folding of signal? Show with example.
What is the advantage with sectioned convolution?.
What is the requirement for convolution?.
What is the difference between convolution & correlation?
What is meant by impulse response?
Is it possible to represent any discrete time signal in terms of impulses? If yes, represent by using example
Draw the h(2n-k) & h(n-2k) for the following sequence h(n) = { 4 3 2 1} assume (i) k= 3 (ii) k =5.
Write the expressions for LTI system convolution formula & causal LTI system convolution formula.
What is the length of linear convolution if length of input & impulse responses are N1 & N2 respectively?
What is the difference between continuous and discrete convolution?
Multiplication of two DFT sequences in frequency domain is equal to ________________ of the sequences in
time domain.

The (linear) convolution of two sequences of width N1 and N2 has width _________.

Circular convolution gives the same result as linear convolution if both sequences are _________ to an
appropriate length.
Time shifting of discrete time signal means
a. y[n] = x[n-k] b. y[n] = x[-n-k] c. y[n] = -x[n-k] d. y[n] = x[n+k]

What are the advantages of FIR as compared to IIR?


How many types of FIR design methods are used in real time?.

121
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL- 15ECL57
_____________________________________________________________________

What is meant by Gibbs Phenomenon? Where we found such type of effect in FIR filters?

What are the advantages& disadvantages of Rectangular window FIR filter as compared to remaining window
techniques?

Which window technique having less peak amplitude of side lobe as compared to all?

What do you understand by linear phase responce?


To design all types of filters what would be the expected impulse response?
What are the properties of FIR filter?.
How the zeros in FIR filter is located?
What are the desirable characteristics of the window?
What are the specifications required to design filter?
What is meant by IIR filter?
What is the difference between recursive & non-recursive systems?
Write the difference equation for IIR system.

What are the mapping techniques in IIR filter design? Discuss the advantage & disadvantages of them.

What are IIR analog filters? What are the advantages & disadvantages of them?
What is the disadvantage in impulse invariance method?

What does warping effect mean? Where we found this effect? How can we eliminate warping effect

Explain the pole mapping procedure of Impulse invariant & bilinear transformation method.

For given same specification what is the difference we find in Butterworth & chebyshev filter.

What is the difference between type I & type II chebyshev filters?.


Where the poles are located for Butter worth & chedbyshev filters?
What is meant by spectral transformation?
. Why we need spectral transformation in IIR filter?

What is the difference between continuous time & discrete time Fourier transform?

What is the condition for convergence of Fourier transform?


What is the difference between discrete Time Fourier Transform (DTFT)& DFT?
What is the difference between Z transform & DFT?

State convolution property of the DFT? Where we could use the convolution property?

State Parsevals theorem.?


State correlation property of the DFT.?
What is the difference between radix 2 & radix4 FFT algorithms?
Why we need FFT?.
What is the difference between decimation in time (DIT FFT) & Decimation in frequency (DIFFFT)
algorithms?
What is meant by in-place computation in DIF & DIF algorithms?
Which properties are used in FFT to reduce no of computations?

122
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL- 15ECL57
_____________________________________________________________________
What is the difference between correlation & auto correlation function?
What is the difference between PSD & ESD?
What is the unit for energy density spectrum?
What is the formula for PSD of a function?
Same power density spectrum signals always have same magnitude & phase spectrums Is above
statement true (or) False: Justify your answer.
If we know the impulse response of the system, the How can you find output signal power density from
the input signal?
What is the unit for power density spectrum?
What is the relation between auto correlation & PSD of a function ?
How many types of DSP processors are available in the market?
TMS 320C6X, C stands for what?
What are the features of TMS 320C6X processor?
What is meant by VLIW architecture? Why we required in DSP processor?
How many functional units are in TMS 320C6X DSP processor?
What is meant by Circular addressing mode how is it useful for DSP?
Which instruction is used to move 16 bit constant in to the upper bits of a register?

What is the difference between Von Neumann architecture & Harvard architecture?

Which architecture is used in DSP processor?


How many instructions can we execute per cycle in TMS320C6X DSP processor?
What are the applications for the TMS320 DSPs?
Which soft ware tool is required to compile and run the DSP assembly program ?
What is the difference between full version Code composer studio &DSK CCS?
Define impulse signal
Define ramp signal
Define unit step signal
Define exponent ional signal
Define sinusoidal signal
Define C.T.S
Define D.T.S.
Compare C.T.S & D.T.S
Define Stem, Plot, Plot3,fplot, ezplot, linspace, flyplr, grid,mesh and legend
Draw the C.T.S & D.T.S diagrams

Which built in function is used to solve a given difference equation?

What is frequency response? Give equation for first order system and second order system?

What is an LTI system?


What is steady state response?
Differentiate between linear and circular convolution.
Determine the unit step response of the linear time invariant system with impulse response h(n)=a n u(n)
a<1&-a<1

123
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL- 15ECL57
_____________________________________________________________________

Determine the range of values of the parameter a for which linear time invariant system with impulse response
h(n)=a n u(n) is stable.
Consider the special case of a finite duration sequence given as X(n)={2 4 0 3}, resolve the sequence x(n) into a
sum of weighted sequences.
Describe impulse response of a function?
Where to use command filter or impz, and what is the difference between these two?

How to calculate output of DFT using MATLAB?


Where DFT is used?
What is the difference between DFT and IDFT?

How to compute maximum length N for a circular convolution using DFT and IDFT.(what is command).

Explain the function of twiddle factor?


Give the practical application DFT & IDFT?

Explain the role of DFT & IDFT when the signal converted from the time domain to frequency domain?

Differentiate between time variant and time invariant system. If x 1(n)={1,2,3,4} and x 2(n)={1,2,3} Find the
convolution using tabular representation.
Draw all elementary standard discrete time signals.
Differentiate between causal and Non causal system.

If x 1(n)={1,2,3,4} and x 2(n)={5,6,7,8} Find the circular representation for the above sequences.

How can you compute Fourier transform form Z-transform ?


Time reversal of a discrete time signal refers to
a. y[n] = x[-n+k] b. y[n] = x[-n] c. y[n] = x[-n-k] d. y[n] = x[n-k]

FFT is in complex domain how to use it in real life signals optimally?


What is the difference between FFT and IFFT?
Explain using convolution the effects of taking an FFT of a sample with no windowing
What is the need of FFT ?
Whats the difference between FFT and DFT?
Why do we need Fourier transform in DSP?
Give any practical application of fft in daily life?
What is the importance of fft in OFDMA technology?
In STB DVB how many point fft is currently using?

Give FFT & IFFT formulae and calculate for any sequence?
What is "decimation-in-time" versus "decimation-in-frequency"?
What is "bit reversal"?
How does the FFT work?

What do you mean by phase spectrum and magnitude spectrum/ give comparison?
How do you reduce spectral leakage?
What do you mean by spectral resolution?

124
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL- 15ECL57
_____________________________________________________________________

What is filter?
What is FIR and IIR filter define, and distinguish between these two?
What is window method? How you will design an FIR filter using window method?
What are low-pass and band-pass filter and what is the difference between these two?
What is the matlab command for Hamming window? Explain.
What do you mean by built in function abs and where it is used?
Explain how the FIR filter are stable?
Why is the impulse response "finite"?
What does "FIR" mean?
What are the advantages of FIR Filters (compared to IIR filters)?
What are the disadvantages of FIR Filters (compared to IIR filters)?
What terms are used in describing FIR filters?
What is the delay of a linear-phase FIR?

What is the Z transform of a FIR filter?


What is the frequency response formula for a FIR filter?

How Can I calculate the frequency response of a FIR using the Discrete Fourier Transform (DFT)?

What is the DC gain of a FIR filter?

What do you mean by cut-off frequency?


Give the difference between analog and digital filter?
What is the difference between type 1 and type 2 filter structure?
what is the role of delay element in filter design?
Explain how the frequency is filter in filters?
Differences between Butterworth chebyshev filters?
Can IIR filters be Linear phase? how to make it lin

What is the special about minimum phase filter?

What is the special about minimum phase filter?


In signal processing, why we are much more interested in orthogonal transform?
How is the non-periodic nature of the input signal handled?
If a have two vectors how will i check the orthogonality of those vectors?

Explain the significance of convolution.


Define linear convolution.
Why linear convolution is called as a periodic convolution?
Why zero padding is used in linear convolution?
What are the four steps to find linear convolution?
What is the length of the resultant sequence in linear convolution?
How linear convolution will be used in calculation of LTI system response?

125
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL- 15ECL57
_____________________________________________________________________
List few applications of linear convolution in LTI system design.
Give the properties of linear convolution.
How the linear convolution will be used to calculate the DFT of a signal?

Give mathematical definition of circular convolution


Why circular convolution is called as periodic convolution?
Difference between linear convolution and circular convolution
Explain the circular shift
How circular convolution is used to calculate the Z-transform of a signal?
List few Applications of circular convolution
What are the different methods used to calculate circular convolution?
Explain properties of circular convolution?
Explain modulo N operation

What is the importance of circular convolution to realization of digital systems or digital filters?

What is a filter?
Differentiate analog filter and digital filter.
Define FIR filter.
What are the differences between recursive and non recursive systems?
List a few Applications of FIR filters.
Explain advantages of FIR filters over IIR filters.
Explain limitations of FIR filters.
What is the different method to design FIR filters?
Explain different window functions.
Differentiate rectangular, triangular and Kaiser windows.

List some advantages of digital filters over analog filters.


Write some differences between FIR and IIR filters.
What are the different methods to design IIR filters?
Why IIR filters are not reliable?
What are different applications of IIR filters?
What are advantages of IIR filters?
What are disadvantages of IIR filters?
Differentiate Butterworth and Chebyshev approximations.
What is meant by impulse response?
What is the importance of impulse response to calculate the o/p response of the filter?

Define transform. What is the need for transform?


Differentiate Fourier transform and discrete Fourier transform.
Differentiate DFT and DTFT.
What are the advantages of FFT over DFT?
Differentiate DITFFT and DIFFFT algorithms.
What is meant by radix?

126
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL- 15ECL57
_____________________________________________________________________
What is meant by twiddle factor and give its properties?
How FFT is useful to represent a signal?
Compare FFT and DFT with respect to number of calculation required?
How the original signal is reconstructed from the FFT of a signal?
What is magnitude and phase spectrum?
What are the phase factors involved in all stages of computation in 8-point DIF radix-2 FFT?
Draw the basic butterfly diagram or flow graph of DIF radix-2 FFT?
Draw the basic butterfly diagram or flow graph of DIT radix-2 FFT?
What are the phase factors involved in all stages of computation in the 8-point DIT radix-2 FFT?
What is phase factor or twiddle factor?
. Draw the DIF FFT structure with the length of 8?
Draw the DIT FFT structure with the length of 8?
What are the various algorithms to calculate FFT?
compare FFT and DFT?
What is FFT, What it's importance?
List any four properties of DFT
What is the drawback in Fourier transform and how is it overcome?
What is the relation between DTFT and DFT?
Define inverse DFT.
Define DFT of a discrete time sequence?
What is sectioned convolution? Why is it performed?
What are the two methods of sectioned convolution?
Define cross correlation and auto-correlation?
What are the properties of correlation?
What are recursive and non recursive systems? give examples

127
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL- 15ECL57
_____________________________________________________________________
QUESTION BANK

Students need to write algorithm, program, expected results, expected graphs, verification for the
expected results/ inference which ever suitable.

MATLAB QUESTIONS

1. State and verify the Sampling theorm using MATLAB. (Analog frequency fd=500Hz) Show how
aliasing can be prevented? How can the samples obtained on zero axis for a sine wave using Nyquist
criterion can be avoided?

2. Find the Linear convolution of two given sequences using time domain approach, using MATLAB.x1
=[1 2 3 2 1 3 4], origin at 4th sample, x2 =[2 -3 4 -1 0 1] origin at 2nd sample, .

3. Find the Circular convolution of two given sequences x1=[1 2 3 4]; x2= [1 2 3 4] using time domain
approach and verify the same using frequency domain approach using MATLAB.

4. Verify the Commutative, distributive and associative property of linear and circular convolution.

5. Find the Autocorrelation of a (i) rectangular sequence (ii) periodic sequence using MATLAB and verify
its properties.

6. Find the Cross correlation of given sequences and verify its properties. reference sequence = [1 3 -2 1
2 -1 4 4 2], second sequence = [2 -1 4 1 -2 3]

7. (i) Calculate impulse response h(n) OR step response for the Difference equation y(n) - y(n-1) + 0.9y(n-
2) = x(n); at n=0,..,100 (ii) Plot the steady state response y[n] to x[n]=cos(0.05n)u(n), given y[n]-
0.8y[n-1]=x[n] using MATLAB

8. Compute N point DFT of a given sequence using MATLAB and plot magnitude and phase spectrum.
x=[1 2 -1 2 4 2 -1 2]. Verify Time shift property, Parsevals Theorm of DFT.

9. Find the DFT of (i) Square pulse (ii) Sinc function.

10. Design FIR filter using MATLAB to meet given specifications. (i) passband edge frequency
=100Hz,stopband edge frequency 200Hz, sampling frequency 1000Hz. Choose Hamming window.
Implement the filter by generating simulated input of 50, 300 & 200 Hz, each of 30 points

11. Design an IIR Butterworth (Low pass/ High pass) filter using MATLAB to meet given specifications: order
of the filter N=2, cutoff frequency fc=150Hz, sampling frequency fs=1000 Hz, Implement the filter by
generating simulated input of 100, 300 & 170 Hz, each of 30 points

12. Design an IIR Butterworth (Band pass/ Band stop) filter using MATLAB to meet given specifications:
order of the filter N=2, lower frequency f1=150Hz,upper frequency f2=250Hz, sampling frequency
fs=1000 Hz, Implement the filter by generating simulated input of 100, 300 & 170 Hz, each of 30 points

CCSTUDIO PROGRAMS

1. Find the Impulse response of the second order system defined by the difference equation y[n] + -1.1430
y[n-1]+ 0.4128y[n-2]= 0.0675x[n]+ 0.1349x[n-1]+ 0.0675x[n-2] and N=20 using CCStudio.

2. Find the Circular convolution of two given sequences. x[n]={1,2,3,4,5}; h[n]={2,1,3,4,5} using CC Studio

3. Compute N- Point DFT of a given sequence x[4]={1,3,2,5}, N=4 using CC Studio

4. Find the Linear convolution of two given sequences h[n] = { 2,2,2,2}; x[n] ={1,2,3,4}; using CC Studio

5. Design the coefficients of an FIR filter using CCStudio

128
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL- 15ECL57
_____________________________________________________________________

State and verify the Sampling theorm using MATLAB. (Analog frequency fd=500Hz) Show how aliasing can
1. a. be prevented? How can the samples obtained on zero axis for a sine wave using Nyquist criterion can be
avoided?
Find the Impulse response of the second order system defined by the difference equation y[n] + -1.1430 y[n-
1. b.
1]+ 0.4128y[n-2]= 0.0675x[n]+ 0.1349x[n-1]+ 0.0675x[n-2] and N=20 using CCStudio.

2. a. Verify the Commutative, distributive and associative property of linear and circular convolution.
2. b. Find the Circular convolution of two given sequences. x[n]={1,2,3,4,5}; h[n]={2,1,3,4,5} using CC Studio

Find the Linear convolution of two given sequences using time domain approach, using MATLAB.x1 =[1 2 3
3. a.
2 1 3 4], origin at 4th sample, x2 =[2 -3 4 -1 0 1] origin at 2nd sample, .
3. b. Compute N- Point DFT of a given sequence x[4]={2,3,2,1}, N=4 using CC Studio.

Find the Circular convolution of two given sequences x1=[1 2 3 4]; x2= [1 2 3 4] using time domain approach
4. a.
and verify the same using frequency domain approach using MATLAB.
4. b. Compute N- Point DFT of a given sequence x[4]={1,3,2,5}, N=4 using CC Studio.

Find the Autocorrelation of a (i) rectangular sequence (ii) periodic sequence using MATLAb and verify its
5. a.
properties.
5. b. Find the Linear convolution of two given sequences h[n] = { 2,2,2,2}; x[n] ={1,2,3,4}; using CC Studio

Find the Cross correlation of given sequences and verify its properties. reference sequence = [1 3 -2 1 2 -1 4 4
6. a.
2], second sequence = [2 -1 4 1 -2 3]
6. b. Design the coefficients of an FIR filter using using CCStudio

(i) Calculate impulse response h(n) OR step response for the Difference equation y(n) - y(n-1) + 0.9y(n-2) =
7. a. x(n); at n=0,..,100 (ii) Plot the steady state response y[n] to x[n]=cos(0.05n)u(n), given y[n]-0.8y[n-
1]=x[n] using MATLAB
7. b. Find the Linear convolution of two given sequences h[n] = { 2,1,2,1}; x[n] ={4,3,2,1}; using CCStudio

Compute N point DFT of a given sequence using MATLAB and plot magnitude and phase spectrum. x=[1 2 -
8. a.
1 2 4 2 -1 2]. Verify Time shift property of DFT.
Find the Impulse response of the second order system defined by the difference equation y[n] + -1.1430 y[n-
8. b.
1]+ 0.4128y[n-2]= 0.0675x[n]+ 0.1349x[n-1]+ 0.0675x[n-2] and N=20 using CCStudio.

Design FIR filter using MATLAB to meet given specifications. (i) passband edge frequency =100Hz,stopband
9. a. edge frequency 200Hz, sampling frequency 1000Hz. Choose Hamming window. Implement the filter by
generating simulated input of 50, 300 & 200 Hz, each of 30 points
9.b. Find the Linear convolution of two given sequences h[n] = { 2,0,2,1}; x[n] ={1,2,0,4}; using CC Studio

Design an IIR Butterworth (Low pass/ High pass) filter using MATLAB to meet given specifications: order of
10.a. the filter N=2, cutoff frequency fc=150Hz, sampling frequency fs=1000 Hz, Implement the filter by generating
simulated input of 100, 300 & 170 Hz, each of 30 points
10.b. Find the Circular convolution of two given sequences. x[n]={1,2,3,4}; h[n]={2,1,3,4} using CC Studio

129
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL- 15ECL57
_____________________________________________________________________

Design an IIR Butterworth (Band pass/ Band stop) filter using MATLAB to meet given specifications: order of
11.a. the filter N=2, lower frequency f1=150Hz,upper frequency f2=250Hz, sampling frequency fs=1000 Hz,
Implement the filter by generating simulated input of 100, 300 & 170 Hz, each of 30 points
Find the Impulse response of the second order system defined by the difference equation y[n] + -1.1430 y[n-
11.b.
1]+ 0.4128y[n-2]= 0.0675x[n]+ 0.1349x[n-1]+ 0.0675x[n-2] and N=20 using CCStudio.

12.a. Find the DFT of (i) Square pulse (ii) Sinc function. Verify Parsevals Theorm.
12.b. Design the coefficients of an FIR filter using using CCStudio

NOTE: For verification of 8 point DFT you can use FFT (butterfly diagram)

130
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL- 15ECL57
_____________________________________________________________________

131

You might also like