Professional Documents
Culture Documents
__________________________________________________________________________________
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
__________________________________________________________________________________
_
1
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
__________________________________________________________________________________
_
2
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
COURSE OUTCOME
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
COURSE OBJECTIVES
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
__________________________________________________________________________________
_
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.
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.
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 (type clc and press Enter) clears the Command 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
__________________________________________________________________________________
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.
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
__________________________________________________________________________________
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:
__________________________________________________________________________________
_
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
__________________________________________________________________________________
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.
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.
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.
__________________________________________________________________________________
_
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.
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.
For a vector:
va(:) Refers to all the elements of the vector va (either a row or a column vector).
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.
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;
Deleting elements
__________________________________________________________________________________
_
14
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
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.
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 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:
__________________________________________________________________________________
_
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:
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)
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 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.
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 tight Sets the axis limits to the range of the data.
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.
user_entry = input('prompt')
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(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(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('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.
ylabel(...) and zlabel(...) label the y-axis and z-axis, respectively, of the 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.
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)
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
Description
figure creates figure graphics objects. Figure objects are the individual windows on the screen
in which MATLAB displays graphical output.
Figure Windows can be closed with the close command. Several forms of the command are:
grid on
grid off
grid
grid minor
Description
The grid function turns the current axes' grid lines on and off.
grid off: removes major and minor grid lines from the current axes.
__________________________________________________________________________________
_
23
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
datacursormode: Enable or disable interactive data cursor mode
datacursormode on
datacursormode off
datacursormode
Description
Managing commands
__________________________________________________________________________________
_
24
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
INTRODUCTION PROGRAMS
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.
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.
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 +.
__________________________________________________________________________________
_
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.
__________________________________________________________________________________
_
28
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
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.
Algorithm:
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.
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:
Inference:
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
__________________________________________________________________________________
Aim: To obtain linear convolution and circular convolution of two finite duration sequences.
(i) using time domain approach (ii) frequency 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
Algorithm:
MATLAB Implementation:
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)
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
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.
%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
__________________________________________________________________________________
_
37
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
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
__________________________________________________________________________________
_
38
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
Fig 2.3. Plotting of f(m) and h(-m) for circular convolution
Algorithm:
MATLAB Implementation:
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')
%obtain DFTs
__________________________________________________________________________________
_
40
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
X1= fft(x1,N);
X2= fft(x2,N);
%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
24 22 24 30
__________________________________________________________________________________
_
41
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
Fig 2.4: CIRCULAR CONVOLUTION (DFT & IDFT) using frequency domain approach
__________________________________________________________________________________
_
43
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
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.
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:
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
RESULT
lag1 = -5 -4 -3 -2 -1 0 1 2 3 4 5
__________________________________________________________________________________
_
46
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
lag2 = -3 -2 -1 0 1 2 3
lag3 = -3 -2 -1 0 1 2 3
__________________________________________________________________________________
_
47
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
__________________________________________________________________________________
_
48
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
Cross correlation using convolution and correlation commands
3 7 -11 14 13 -15 28 6 -2 21 12 12 6 4
__________________________________________________________________________________
_
49
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
__________________________________________________________________________________
_
50
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
Aim: To obtain auto correlation of the given sequence and verify its properties.
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
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:
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.
%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');
__________________________________________________________________________________
_
52
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
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
__________________________________________________________________________________
__________________________________________________________________________________
_
55
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL-15ECL57
__________________________________________________________________________________
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
__________________________________________________________________________________
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:
__________________________________________________________________________________
_
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
MATLAB Program:
xlabel('n');
ylabel('h(n)');
__________________________________________________________________________________
_
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)');
__________________________________________________________________________________
_
61
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57
Theory:
X (k ) x[n]e N
; k 0,1,2,....N - 1
n 0
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
Algorithm:
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.
% 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
65
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57
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
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
3) Linearity property
%dft(a.x1+b.x2)=dft(a.x1)+dft(b.x2)----Linearity property
68
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57
RESULT
4) Parsevals theorm
%Parsevals theorm
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
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');
70
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57
71
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57
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.
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
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.
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
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.
76
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57
77
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57
78
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57
79
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57
Theory:
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
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 3: Compute the Impulse Response [b,a] coefficients of the required IIR
filter and the response type as [b,a] =butter(N, wc , 'high');
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
[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
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');
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
84
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57
85
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57
86
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57
87
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57
88
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57
Save
89
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57
90
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57
91
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57
92
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57
Project Name
Output type--->>--executable
Family--->>---------C6000
Variant ---------->>-----Empty---------->>--------TMS320C6748
93
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57
Select---------->>-------Linker -dsp.cmd
Finish
94
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57
14)
Project
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
97
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57
21) Run
98
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57
22) Resume
99
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57
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};
Result
100
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57
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
101
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57
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
C Program
#include <stdio.h>
#include <math.h>
main()
float w;
int n,k,k1,N=8,xlen=4;
for(k=0;k<2*N;k=k+2)
for(n=0;n<xlen;n++)
102
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL -15ECL57
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
-0.971311+j-2.009436 -0.460726+j7.633037
MATLAB verification
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:
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.
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;
#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;
}
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
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);
MATLAB Implementation:
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).
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).
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
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
_____________________________________________________________________
113
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL- 15ECL57
_____________________________________________________________________
RESULT
114
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL- 15ECL57
_____________________________________________________________________
% 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')
115
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL- 15ECL57
_____________________________________________________________________
BUTTERWORTH FILTER
%Analog frequencies
aw1= 2*pi*w1/ws;
aw2=2*pi*w2/ws;
116
JYOTHY INSTITUTE OF TECHNOLOGY DSP LAB MANUAL- 15ECL57
_____________________________________________________________________
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?
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]
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 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 continuous time & discrete time Fourier transform?
State convolution property of the DFT? Where we could use the convolution property?
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?
What is frequency response? Give equation for first order system and second order system?
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 compute maximum length N for a circular convolution using DFT and IDFT.(what is command).
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.
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?
How Can I calculate the frequency response of a FIR using the Discrete Fourier Transform (DFT)?
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?
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.
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.
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
4. Find the Linear convolution of two given sequences h[n] = { 2,2,2,2}; x[n] ={1,2,3,4}; using CC Studio
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