DSP Lab Manual Final PDF
DSP Lab Manual Final PDF
DSP Lab Manual Final PDF
LAB MANUAL
Page 1
LAB MANUAL
Lab No
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
List of Labs
Introduction to Matlab
Discrete Time Signals in Time Domain
Discrete time systems in Time Domain
Discrete Time System in Frequency Domain
Z-Transform
Digital Processing of Continuous Signals
Term Project
Decimation & Interpolation
Digital Filter Structure
Digital Filter Design
Digital Filter Design Using Matlab Tools
Discrete Fourier Transform
Introduction to Hardware & Software tools of TMS320C6713 DSK
Performing Linear Convolution on TMS320C6713 DSK
Performing Circular Convolution on TMS320C6713 DSK
Interfacing TMS320C6713 DSK with Matlab
Page 2
LAB MANUAL
Lab # 01
Introduction to MATLAB
Matlab is a software package which was developed for numerical analysis involving matrices (matlab"
as in matrix laboratory). It is now widely used for general technical computing and solving complex
engineering problems. It is an interpreted language, which means that commands are run as they are
entered in, without being compiled. It also means that most of the commands, except the most basic
ones, are defined in script/text files which are written in this interpreted language. So, you can read
these files, and add to the language by making similar files. Many commands you will use have been
created especially for the analysis and processing of digital signals. Matlab is an imperative language and
is like C in several respects. It has syntax similar to Java, but it is not object-oriented. The basic data
element for Matlab is the matrix or array. This means that you can write programs which act on arrays
easily and without the need for dimensioning and memory allocation. Because it is interpreted, it is
slower than C, and to get the fastest performance, the matrix nature of Matlab must be used fully (the
programs must be vectorized"). Matlab has built-in graphics and visualization tools. There are many
add-on toolboxes" like Aerospace, Communications, Control Systems, Filter Design, Signal Processing
and many more. Matlab is an excellent prototyping language, because it has so many useful
mathematics utilities, built-in. Many of the latest algorithms and research ideas in machine learning
appear as Matlab packages before they are produced in other forms, such as C++. When one gets
experience with the software, one can produce algorithms in matlab much more quickly than one could
in JAVA, say. The downside is that these will run much more slowly than if they were written in C++, or
even in JAVA. This is why Matlab is often used to prototype ideas. When the algorithms applied to large
systems and need to Our focus for this course will obviously be on the signal processing and filter
designing tools available in MATLAB.
Command Window
As clear from its name, it is the prompt window where different commands are entered.
Workspace
Workspace is the area of memory where all the defined variables/structures are kept. The
workspace window displays all the defined variables/structures along with their data types and
details including their sizes and values
Current Directory
The current directory displays the contents of the directory which is currently in use for keeping
and retrieving different files. The default current directory is work, which resides inside the main
MATLAB directory.
Page 3
LAB MANUAL
Command History
MATLAB maintains a history of the commands that have been previously entered in the
command window
Working in MATLAB
Getting Help
If you need more information about any Matlab functions, there are several ways of getting it:
To look for a command whose name you do not know, use lookfor",
Page 4
LAB MANUAL
The help menu from the menu bar gives access to a huge range of documents and tutorials.
Look under \MATLAB Help". \Getting Started" which contains a good tutorial. \Using Matlab" is
a useful reference.
The help can be referenced by typing helpdesk or doc, which will open complete help for
Matlab in hypertext format.
and create a variable x in the workspace (if it did not already exist), and set its value to the above. If you
put a semicolon after the command, the answer will not be printed on the screen, but the value of x will
be set. This is useful when you don't need to see the value (because it is part of an intermediate
calculation), or when the variable being set is a large structure which would take many pages to print
out. If you don't give a variable name to the calculation, the variable is stored in a variable called ans.
E.g.,
Result in
Matrices
There are several ways to enter matrices in Matlab. These include:
Entering an explicit list of elements.
Page 5
LAB MANUAL
and assigns it to the variable `A'. If you don't know what a magic square is, you can find it in the Matlab
help. Be careful Matlab is case-sensitive, so it distinguishes between `A' and `a'.) Matlab will echo the
matrix back at you, unless you put a semi-colon (;) at the end of the line. This is very useful when the
matrices are very large.
This matrix can be referred to as A until the end of the session, unless you decide to alter it in some way.
When it encounters a variable it hasn't seen before, Matlab automatically creates one. To see which
variables have been created so far, look in the Workspace submenu. If you type A (or any defined
variable name) at the Matlab prompt, it will print back the name with its contents. This is useful if you
want to check the contents of a variable. There are commands for creating special matrices. These take
parameters which define the size of matrix they generate. Some of these are:
zeros: makes a matrix of all zeros (for initilization, for example). For example, zeros(2,3) makes a
2 by 3 matrix of zeros.
ones: makes a matrix of all ones. Used like the zeros command.
rand: makes a matrix of random numbers uniformly distributed between 0 and 1. E.g. rand(1,10)
makes a column of random numbers.
eye: makes an identity matrix. E.g. eye(10) makes a 10 by 10 matrix with 1s on the diagonal and
0s off the diagonal.
The colon by itself refers to the entire row or column. For example, A(:,2) is the entire second column of
A,
Page 6
LAB MANUAL
Functions on Matrices
Matlab has a number of built-in functions which can be performed on matrices. Here is a list of the more
immediately useful ones. sum: Returns the sum of the columns of a matrix, or, if used on a row vector,
the sum of the row. For example,
Sums the columns in the matrix, and returns the result as a 1 by 4 matrix. Notice how the special
variable `ans' is used to store the temporary result of the operation. mean: Returns the mean (average)
of the columns of a matrix. transpose: To return the transpose of a matrix, append an apostrophe (or
"single-quote") to the name. For example:
Page 7
LAB MANUAL
Operators on Matrices
You can add or subtract two matrices
The result could easily have been stored in another variable, e.g.:
The multiplication operator *, division operator / and power operator ^ refer to matrix multiplication,
division, and power respectively. If a dot is put before these operators, the operator acts component by
component. For example,
returns the matrix containing the square of each component of A, whereas
performs matrix multiplication between the two. On scalars, both forms have the same meaning.
Logical operations are also allowed. These are the same as in most other languages: &, |, ~, xor have
their usual meanings when applied to scalars. Any non-zero number represents True, and zero
represents False. They can also be applied to matrices, and the result is a matrix of 0's and 1's. For
example:
Relation operators are similar to that of other languages: ==, <, >, <=, >=, ~=. These return either 1 or 0,
in much the same way as the logical operators:
Page 8
LAB MANUAL
Lab Task
1. Calculate the area of a circle in Matlab
2. Write a program in Matlab to get 10 numbers from user and generate the square of those numbers.
3. Calculate inverse of a matrix [3x3] matrix A using Matlab and confirm your answer using Matlab builtin inv() command.
4. Open help windows by typing doc command in the Command Window, and find out the functions of
the following commands;
a. real
b. conj
c. rand
d. cat
e. factor
f. eye
g. zeros
h. ones
i. diag
j. tic, toc
k. etime
5. Enter two matrices of [3x3] size, and find the product of the two matrices, also find the element-wise
product of the matrices.
6. Generate two 10,000 sampled random data points using rand() function i.e. rand(1,10000). Add the
two vectors together using simple vector addition. Determine the time required for addition using tic,
toc pair or etime function. [Hint: you may use Matlab help for using any of the used commands].
Page 9
LAB MANUAL
graphs the function sin function divided by x between -20 and 20. The points of the x axis are separated
by 0:01; for different spacing, you would use a
different increment in the colon operator in the
definition of x.
Type help plot at the prompt to get a
description of the use of the plot function. Your
math teacher may have taught you to always
label your axes; here is how: xlabel and ylabel
puts strings on the axes, like so,
Page
10
LAB MANUAL
For example, if we wanted to plot the graphs above as crosses in red, the command would be
Create line plot using specific line width, marker color, and
marker size:
Page
11
LAB MANUAL
Multiple Plots
If you want to compare plots of two different
functions, calling plot twice in succession will
not
be satisfactory, because the second plot will
overwrite the first. You can ensure a new plot
window for a plot by calling figure first. If you
want to put multiple plots on the same figure,
we set hold on. The default is hold off, which
Page
12
LAB MANUAL
makes a new figure overwrite the current one. Here is an example. Suppose we want to compare the log
function with the square root function graphically. We can put them on the
same plot. By default, both plots will appear in blue, so we will not know which is which. We could make
them different colors using options. Here is the final answer
,
What appears after the % on a line is a comment. The options can also be used to plot the values as
points rather than lines. For example, '+' plots a cross at each point, '*' a star and so forth. So,
Sub-plotting
More than one plot can be put on the same figure using the subplot command. The subplot command
allows you to separate the figure into as many plots as desired, and put them all in one figure. To use
this command, the following line of code is entered into the Matlab command window or an m-file:
subplot(m,n,p)
This command splits the figure into a
matrix of m rows and n columns,
thereby creating m*n plots on one
figure. The p'th plot is selected as the
currently active plot. For instance,
suppose you want to see a sine wave,
cosine wave, and tangent wave plotted
on the same figure, but not on the same
axis. The following m-file will
accomplish this:
Page
13
LAB MANUAL
The variables in1, etc. are input arguments, and out1 etc. are output arguments. You can
have as many as you like of each type (including zero) and call them whatever you want. The
name myfun should match the name of the disk file.
Here is a function that implements (badly, it turns out) the quadratic formula.
Page
14
LAB MANUAL
r1 =
1
r2 =
1
One of the most important features of a function is its local workspace. Any arguments or other
variables created while the function executes are available only within the function. Conversely, the
variables available to the command line (the so-called base workspace) are normally not visible to the
function. If during the function execution, other functions are called, each of those calls also sets up a
private workspace. These restrictions are called scoping, and they make it possible to write complex
programs without worrying about name clashes. The values of the input arguments are copies of the
original data, so any changes you make to them will not change anything outside the functions scope. In
general, the only communication between a function and its caller is through the input and output
arguments.
You can always see the variables defined in the current workspace by typing who or whos. Another
important aspect of function M-files is that most of the functions built into MATLAB (except core math
functions) are themselves M-files that you can read and copy. This is anexcellent way to learn good
programming practice.
General Information
MATLAB is case sensitive so "a" and "A" are two different names.
Help for MATLAB can be reached by typing helpdesk or help for the full menu or typing help
followed by a particular function name or M-file name. For example, help cos gives help on the
cosine function.
The number of digits displayed is not related to the accuracy. To change the format of the
display, type format short e for scientific notation with 5 decimal places, format long e for
scientific notation with 15 significant decimal places and format bank for placing two significant
digits to the right of the decimal.
The commands who and whos give the names of the variables that have been defined in the
workspace.
Page
15
LAB MANUAL
The command length(x) returns the length of a vector x and size(x) returns the dimension of the
matrix x.
When using MATLAB, you may wish to leave the program but save the vectors and matrices you
have defined. To save the file to the working directory, type save filename where "filename" is a
name of your choice. To retrieve the data later, type load filename.
The following commands typed from within MATLAB demonstrate how this M-file is used:
All variables used in a MATLAB function are local to that function only, whereas, variables which are
used in a script m-file which is not a function are all global variables.
Lab Task
1. Generate and plot the following signals in MATLAB using an M-File, each plot must include proper
axis labeled as well as the title. Also, display the last three plots using subplot command.
I. x1(t)=sin(t)
II. x2(t)=sin(2t)
III. x3(t)=sin(3t)
IV. x4(t)=sin(4t)
V. x5(t)=x1(t)+x2(t)
VI. x6(t)=x5(t)+x3(t)
VII. x7(t)=x6(t)+x4(t)
VIII. y1(t)=x1(t+1)
IX. y2(t)=x2(3t)
Page
16
LAB MANUAL
X. y3(t)=x3(2t+1)
2. What are the purposes of the commands clear all; close all, clc, axis, title, xlabel, and ylabel?
3. Construct a function in M-file by the name of greater(x,y), which will take two inputs from the user,
finds the value that is greater among the two and then displays it.
4. Construct a function that computes a factorial of a number given to it. Use help to find the command
and how to use it, and then use it to get the answer.
5. Create an m-file that takes two vectors from user. Make sure that the second vector taken is of the
same size as the first vector (Hint: use while loop). In a while loop, generate a third vector that contains
the sum of the squares of corresponding entries of both the vectors.
6. If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of
these multiples is 23. Write a script in Matlab to find the sum of all the multiples of 3 or 5 below 1000.
LAB # 02:
Discrete-Time Signals in the Time Domain
Digital signal processing involves the processing of a discrete time signal (input signal) to produce
another discrete time signal (output signal) which has some desired properties. A strong background of
discrete time signals is essential for analyzing discrete time systems. This lab focuses on the creation of
discrete time signals in MATLAB and explains the required MATLAB commands. After performing the
lab, the students will be able to
Create discrete time signals in MATLAB
Use MATLAB commands to perform simple operations on discrete time signals
Generation of Sequences
Following are some of the commonly used discrete time signals generated using MATLAB
UNIT IMPULSE AND UNIT STEP SEQUENCES
A unit impulse sequence of length N can be generated in MATLAB by the following command
A unit impulse sequence delayed by M samples where M < N can be generated as follows
Likewise, a unit step sequence s[n] of length N can be generated using the MATLAB command
A delayed unit step sequence can be generated in a manner similar to that used in the generation of a
delayed unit sample sequence.
Program P3_1 can be used to generate and plot a unit impulse sequence.
Page
17
LAB MANUAL
Page
18
LAB MANUAL
Page
19
LAB MANUAL
Page
20
LAB MANUAL
reasonable approximation to s [n]. This can be done by averaging the samples of x[n]. This is referred to
as moving average filter.
Page
21
LAB MANUAL
Page
22
LAB MANUAL
Lab Task
1.
Modify Program P3_1 to generate a delayed unit impulse sequence ud[n] with a delay of 11
samples. Run the modified program and display the sequence generated.
2.
Modify Program P3_1 to generate a unit step sequence s[n]. Run the modified program and
display the sequence generated.
3. Modify Program P3_1 to generate a delayed unit step sequence sd[n] with an advance of 7
samples. Run the modified program and display the sequence generated.
4.
In Program P3_2, which parameter controls the rate of growth or decay of this sequence?
Which parameter controls the amplitude of this sequence?
5.
6. In Program P3_3, which parameter controls the rate of growth or decay of this sequence? Which
parameter controls the amplitude of this sequence?
7. What is the difference between the arithmetic operators ^ and .^?
8.
What will happen if the parameter a is less than 1? Run Program P3_3 again with the parameter
a changed to 0.9 and the parameter K changed to 20.
9.
10. Replace the stem command in Program P3_4 with the plot command and run the program
again. What is the difference between the new plot and the one generated before?
11. Replace the stem command in Program P3_4 with the stairs command and run the program
again. What is the difference between the new plot and those generated before?
12. Write a MATLAB program to generate and display a random signal of length 100 whose
elements are uniformly distributed in the interval [2, 2] .
13. What are Periodic & Aperiodic Signals? Write a Matlab code to check whether given signals are
periodic or Aperiodic.
1. Cos((2/7)*n)
2. Cos((2*pi/7)*n)
Page
23
LAB MANUAL
Lab #03:
Discrete-Time Systems in the Time Domain
A Discrete time systems is defined mathematically as a transformation or operator that maps an input
sequence with values x[n]. this can be donated as
Y[n]=T{x[n]}
Page
24
LAB MANUAL
y[n]=5x1[n] + 10x2[n]
We now consider the simulation of some additional discrete-time systems and study their properties.
For the simulation of causal LTI discrete-time systems, the command filter can be used. There are
several versions of this command. If we denote
then y = filter(num,den,x) generates an output vector y of the same length as the specified input vector
x with zero initial conditions, that is, y[-1] y[-2] = ... = y[-N] = 0. The output can also be computed using y
= filter(num,den,x,ic) where ic = [y[-1], y[-2], ..., y[-N]] is the vector of initial conditions. Access to final
conditions is obtained using [y,fc] filter(num,den,x, ic).
Page
25
LAB MANUAL
which defines a causal M -point smoothing FIR filter. The system of Eq. (4.1) is also known as a moving
average filter. We illustrate its use in filtering high-frequency components from a signal composed of a
sum of several sinusoidal signals.
Page
26
LAB MANUAL
In this project you will generate the output y[n] of the above system for different types of the input x[n]
using Program P4_2.
The following MATLAB program can be used to generate an input signal x[n] composed of a sum of two
sinusoidal sequences and simulate the LTI system of Eq. (4.2) to generate y[n].
Page
27
LAB MANUAL
MATLAB Program P4_3 is used to simulate the system, to generate three different input sequences
x1[n], x2[n], and x[n] = a x1[n] + b x2[n], and to compute and plot the corresponding output
sequences y1[n], y2[n], and y[n].
Page
28
LAB MANUAL
Page
29
LAB MANUAL
Or can be represented as
for increasing values of K, and checks the value of |h[K]| at each iteration step. If the value of |h[K]| is
smaller than 10-6, then it is assumed that the sum S(K) of Eq. 4.7 has converged and is very close to
S().
Page
30
LAB MANUAL
Page
31
LAB MANUAL
Lab Tasks
1. Run the Program P4_1 for M = 2 to generate the output signal with x[n] = s1[n] + s2[n] as the
input. Which component of the input x[n] is suppressed by the discrete-time system simulated
by this program?
2.
If the LTI system is changed from y[n]= 0.5(x[n] + x[n - 1]) to y[n] = 0.5(x[n] - x[n - 1]), what
would be its effect on the input x[n] = s1[n] + s2[n]?
3. Consider another system described by: y[n] = x[n] x[n 1]. Modify Program P4 3 to compute
the output sequences y1[n], y2[n], and y[n] of the above system. Compare y[n] with yt[n]. Are
these two sequences equal? Is this system linear? Run Program P4_4 and compare the output
sequences y[n] and yd[n - 10]. What is the relation between these two sequences? Is this system
time-invariant?
4. Consider another system described by Modify Program P4_4 to simulate the above system and
determine whether this system is time-invariant or not.
Page
32
LAB MANUAL
Lab #04:
Discrete-Time Signals in the Frequency Domain
In Lab#03 we studied various properties of discrete time signals and systems in the time domain.
Further insight into their properties can be obtained in the frequency domain which we will study in this
lab. This lab deals with discrete time Fourier transform.
can be evaluated. In the following two projects you will learn how to evaluate and plot the DTFT and
study certain properties of the DTFT using MATLAB.
Project 5.1 DTFT Computation
The DTFT X(ejW ) of a sequence x[n] of the form of Eq. (5.1) can be computed easily at a prescribed set of
L discrete frequency points w = w3 using the MATLAB function freqz. Since X(ejW ) is a continuous
function of X(ejW ), it is necessary to make L as large as possible so that the plot generated using the
command plot provides a reasonable replica of the actual plot of the DTFT. In MATLAB, freqz computes
the L-point DFT of the sequences {p0 p1 . . . PM } and {d0 d1 . . . dM }, and then forms their ratio to
arrive at X(ejW ), l = 1, 2, . . . , L. For faster computation, L should be chosen as a power of 2, such as 256
or 512.
Program P5_1 can be used to evaluate and plot the DTFT of the form of Eq. (5.1).
Page
33
LAB MANUAL
Most of the properties of the DTFT can be verified using MATLAB. Since all data in MATLAB have to be
finite-length vectors, the sequences being used to verify the properties are thus restricted to be of finite
length.
Program P5_2 can be used to verify the time-shifting property of the DTFT.
Page
34
LAB MANUAL
Program P5_3 can be used to verify the frequency-shifting property of the DTFT.
Page
35
LAB MANUAL
Program P5_4 can be used to verify the convolution property of the DTFT.
Program P5_5 can be used to verify the modulation property of the DTFT
Page
36
LAB MANUAL
Program P5_6 can be used to verify the time-reversal property of the DTFT.
Page
37
LAB MANUAL
Lab Task
1. What is the expression of the DTFT being evaluated in Program P5_1? What is the function of
the MATLAB command pause?
2. Run Program P5_1 and compute the real and imaginary parts of the DTFT, and the magnitude
and phase spectra. Is the DTFT a periodic function of W? If it is, what is the period? Explain the
type of symmetries exhibited by the four plots.
3. Modify Program P5_1 to evaluate in the
4. Modify Program P5_2 by adding appropriate comment statements and program statements for
labeling the two axes of each plot being generated by the program. Which parameter controls
the amount of time-shift?
5. Modify Program P5_3 by adding appropriate comment statements and program statements for
labeling the two axes of each plot being generated by the program. Which parameter controls
the amount of frequency-shift?
6. Repeat Question Q 8 for a different value of the frequency-shift.
Page
38
LAB MANUAL
LAB # 05:
Discrete-Time Signals in the Frequency Domain
In the previous lab we studied properties of discrete time signals and systems in the frequency domain
including discrete time Fourier transform. This lab deals with discrete Fourier transform and the ztransform.
In mathematics and signal processing, the Z-transform converts a discrete time-domain signal, which is a
sequence of real or complex numbers, into a complex frequency-domain representation.
The Z-transform, like many other integral transforms, can be defined as either a one-sided or two-sided
transform.
Unilateral Z-transformAlternatively, in cases where x[n] is defined only for n 0, the single-sided or
unilateral Z-transform is defined as
Page
39
LAB MANUAL
G(z)=( 0.6667 + 0.4z-1 + 0.5333 z-2) (1.000 + 2.000 z-1 +2.000 z-2)
(1.000 + 2.000z-1 -4.000z-2 )(1.000 - 1.000 z-1 + 1.000 z-2)
It is the inverse of the above case, when the transfer function is given in factored form and it is required
to convert in rational form then a single matlab command can serve the purpose.
Example:
Lets use the above result i-e;transfer function in factored for,
G(z)=( 0.6667 + 0.4z-1 + 0.5333 z-2) (1.000 + 2.000 z-1 +2.000 z-2)
(1.000 + 2.000z-1 -4.000z-2 )(1.000 - 1.000 z-1 + 1.000 z-2)
Page
40
LAB MANUAL
For building up transfer function in rational form we find the poles and zers of above system simply by
using matlab root command or by hand. Or simply we have poles and zeros of the given system we can
find the transfer function in factored form.
Matlab command that converts poles and zeros of the system in to transfer function is zp2tf .
This technique is usually used , while taking the inverse Z-transform and when the order
H(z) is high so that it is quite difficult to solve it mathematically.
Example:
Consider the transfer function in the rational form i-e;
18z3
G(z)= -----------------18z3+3z2-4z-1
We can evaluate the partial fraction form of the above system using matlab command. The partial
fraction form be,
G(z)=
0.36__ + __0.24__
1 0.5z-1
1+0.33 z-1
_0.4____
(1+0.33 z-1)
Page
41
LAB MANUAL
0.36__ + __0.24__
1 0.5z-1
1+0.33 z-1
_0.4____
(1+0.33 z-1)
Matlab command that converts partial fraction form into rational z-transform is
residuez
Zplane:
Zero-pole plot
zplane(b,a)
This function displays the poles and zeros of discrete-time systems.
MATLAB:
syms z n
a=ztrans(1/16^n)
Inverse Z-Transform:
MATLAB:
syms Z n
iztrans(3*Z/(Z+1))
Page
42
LAB MANUAL
Matlab Code:
b=[0 1 1 ]
a= [1 -2 +3]
roots(a)
roots(b)
zplane(b,a);
ans =
1.0000 + 1.4142i
1.0000 - 1.4142i
ans=
-1
Page
43
LAB MANUAL
LAB TASK:
Task#1: Express the following z-transform in factored form , plot its poles and zeros,and then determine
its ROCs.
2z4+16z3+44z2+56z+32
G(z)= -------------------------------3z4+3z3-15z2+18z-12
Task#2: Determine the partial fraction expansion of the z-transform G(z) given by
18z3
G(z)= -----------------18z3+3z2-4z-1
Page
44
LAB MANUAL
LAB # 06:
Digital Processing of Continuous Time Signals
Continuous time signals can be processed using digital signal processing techniques. First of all the
continuous time signal is converted to equivalent discrete time system by sampling and then processed
using digital signal processing algorithms. Then the processed discrete time signal is converted to
equivalent continuous time signal. In this lab through various exercises we will learn the process of
sampling, anti-aliasing filter design and design of analog reconstruction filter.
Page
45
LAB MANUAL
this equation on MATLAB, the summation in Eq. (7.1) needs to be replaced with a finite sum, and hence
we can generate only an approximation to the desired reconstructed continuous-time signal ya (t).
Page
46
LAB MANUAL
Page
47
LAB MANUAL
Page
48
LAB MANUAL
Lab Task
1. Run Program P7_1 to generate both the continuous-time signal and its sampled version, and
display them.
2.
What is the frequency in Hz of the sinusoidal signal? What is the sampling period in seconds?
3. Run Program P7_1 for four other values of the sampling period with two lower and two higher
than that listed in Program P7_1. Comment on your results.
4. Repeat Program P7 1 by changing the frequency of the sinusoidal signal to 3 Hz and 7 Hz,
respectively. Is there any difference between the corresponding equivalent discrete-time signals
and the one generated in Question Q7.1? If not, why not?
5. Run Program P7_2 to generate both the discrete-time signal x[1] and its continuous- time
equivalent ya (t), and display them.
6. Run Program P7_3 to generate and display both the discrete-time signal and its continuous-time
equivalent, and their respective Fourier transforms. Is there any visible effect of aliasing?
7. Repeat Program P7_3 by increasing the sampling period to 1.5. Is there any visible effect of
aliasing?
Page
49
LAB MANUAL
LAB # 07
Interpolation & Decimation
The digital signal processing structures discussed so far belong to the class of single-rate systems as the
sampling rates at the input and the output and all internal nodes are the same. There are applications
where it is necessary and often convenient to have unequal rates of sampling at various parts of the
system including the input and the output. In this laboratory exercise you will investigate first using
MATLAB the properties of the up-sampler and the down-sampler, the two basic components of a multirate system. You will then investigate their use in designing more complex systems, such as
interpolators and decimators, and filter banks.
Page
50
LAB MANUAL
The Signal Processing Toolbox includes three M-functions which can be employed to design and
implement an interpolator or a decimator. The three M-functions are decimate, interp, and resample.
Each function is available with several options. In this section you will study the decimation and
interpolation operation using these functions.
Page
51
LAB MANUAL
Page
52
LAB MANUAL
Page
53
LAB MANUAL
Page
54
LAB MANUAL
Lab Task
1. What is the angular frequency in radians of the sinusoidal sequence in Program P10_1? What is
its length? What is the up-sampling factor L?
2. How is the up-sampling operation implemented in Program P10_1?
5. What is the angular frequency in radians of the sinusoidal sequence Program P10_2? What is its
length? What is the down-sampling factor M?
6.
7.
What are the frequencies of the two sinusoidal sequences forming the input sequence in
Program P10_3? What is the length of the input?
8.
9. Change the frequencies of the two sinusoidal sequences in Program P10_3 in the input signal to
0.045 and 0.029, and the length of the input to 120. Run the modified Program P10 5 for M = 3.
Comment on your results.
10. What are the frequencies of the two sinusoidal sequences in Program P10_4 forming the input
sequence? What is the length of the input? What are the type and order of the interpolation
filter?
12. Change the frequencies of the two sinusoidal sequences in the input signal to 0.045 and 0.029,
and the length of the input to 40. Run the modified Program P10_4 for L = 3. Comment on your
results.
Page
55
LAB MANUAL
Lab # 08:
Digital Filter Structure
A structural representation using interconnected basic building blocks is the first step in the hardware or
software implementation of an LTI digital filter. The structural representation provides the relations
between some pertinent internal variables with the input and the output that in turn provide the keys to
the implementation. This lab considers the development of structural representations of causal IIR and
FIR transfer functions in the form of block diagrams.
Page
56
LAB MANUAL
There are two parallel-form realizations of a causal IIR transfer function. Parallel Form I is based on its
partial-fraction expansion in z-1 as in Eq. (8.4), which can be obtained using MATLAB function residuez.
Parallel Form II is based on the partial-fraction expansion in z as in Eq. (8.5), which is obtained using the
function residue. Program P8_2 develops both types of parallel realizations.
In the above, for a real pole 2k = 1k = 0. H (z) expressed in the parallel form II
Page
57
LAB MANUAL
Page
58
LAB MANUAL
Lab Tasks
1.
Using Program P8_1, develop a cascade realization of the following FIR transfer function:
Sketch the block diagram of the cascade realization. Is H1 (z) a linear-phase transfer function?
2.
Using Program P8_ 1, develop a cascade realization of the following causal IIR transfer function
Using Program P8_2, develop the two different parallel-form realizations of the causal IIR transfer
function of the equation given in Question 2. Sketch the block diagrams of both realizations.
4.
Using Program P8_2, develop the two different parallel-form realizations of following causal IIR transfer
function
Page
59
LAB MANUAL
LAB # 09:
Digital Filter Design
The process of deriving the transfer function G(z) whose frequency response G(ejw)
approximates the given frequency response specifications is called digital filter design. After G(z)
has been obtained, it is then realized in the form of a suitable filter structure. In the previous
laboratory exercise, the realizations of FIR and IIR transfer functions have been considered. In
this laboratory exercise you will learn how to design an IIR or FIR digital filter to meet a specified
magnitude or gain response.
where the input parameters are the normalized pass band edge frequency Wp, the normalized
stop band edge frequency Ws, the pass band ripple Rp in dB, and the minimum stop band
attenuation Rs in dB. Both Wp and Ws must be a number between 0 and 1 with the sampling
frequency assumed to be 2 Hz. The output data are the lowest order N meeting the
specifications and the normalized cutoff frequency Wn. If Rp = 3 dB, then Wn = Wp. buttord can
also be used to estimate the order of a high pass, a band pass, and a band stop Butterworth
filter. For a highpass filter design, Wp > Ws. For bandpass and bandstop filter designs, Wp and
Page
60
LAB MANUAL
Ws are two-element vectors specifying both edge frequencies, with the lower edge frequency
being the first element of the vector. In the latter cases, Wn is also a two-element vector.
For estimating the order of a Type 1 Chebyshev filter, the MATLAB command is
and for designing a Type 2 Chebyshev filter, the MATLAB command for estimating the order is
As before, Wp and Ws are the pass band and stop band edge frequencies with values between 0
and 1. Likewise, Rp and Rs are the pass band ripple and the minimum stop band attenuation in
dB. N contains the estimated lowest order and Wn is the cutoff frequency. It should be noted
that for band pass and band stop filter designs, the actual order of the transfer function
obtained using the appropriate filter design command is 2N.
where the input parameters N and Wn are determined through the use of the function buttord,
and the output is the vectors num and den containing, respectively, the coefficients of the
numerator and denominator polynomials of the transfer function in ascending powers of z-1 . If
Wn is a scalar, butter returns a low pass transfer function of order N, and if Wn is a two-element
vector, it returns a band pass transfer function of order 2N. For designing a Butterworth digital
high pass filter of order N, the command is
Returns the transfer function of a Butterworth band stop filter of order 2N provided Wn is a
two-element vector. For designing a Type 1 Chebyshev digital filter, the commands are
Page
61
LAB MANUAL
A low pass transfer function of order N is returned in each case if Wn is a scalar, and a band pass
transfer function of order 2N is returned if Wn is a two-element vector. In each of the above
commands, filter type is high for designing a high pass filter with Wn being a scalar, and filter
type is stop for designing a bandstop filter with Wn being a two-element vector.
Program P9_ 1 illustrates the design of a Butterworth band stop filter
Page
62
LAB MANUAL
with N an even integer, is used for designing a high pass filter. The command
with Wn a two-element vector, is employed for designing a band stop FIR filter.
Page
63
LAB MANUAL
Lab task
1. Using MATLAB to determine the lowest order of a digital IIR low pass filter of all four types. The
specifications are as follows: sampling rate of 40 kHz, pass band edge frequency of 4 kHz, stop
band edge frequency of 8 kHz, pass band ripple of 0.5 dB, and a minimum stop band attenuation
of 40 dB. Comment on your results.
2. Using MATLAB determine the lowest order of a digital IIR high pass filter of all four types. The
specifications are as follows: sampling rate of 3,500 Hz, pass band edge frequency of 1,050 Hz,
stopband edge frequency of 600 Hz, pass band ripple of 1 dB, and a minimum stop band
attenuation of 50 dB. Comment on your results.
3. Using MATLAB determine the lowest order of a digital IIR band pass filter of all four types. The
specifications are as follows: sampling rate of 7 kHz, pass band edge frequencies at 1.4 kHz and
2.1 kHz, stop band edge frequencies at 1.05 kHz and 2.45 kHz, pass band ripple of 0.4 dB, and a
minimum stop band attenuation of 50 dB. Comment on your results.
4. (a) sampling rate of 20 kHz, (b) p = 0.002 and S = 0.002, and (c) stop band edge = 2.3 kHz.
Using the function fir1, design a linear-phase FIR low pass filter meeting the specifications given
above and plot its gain and phase responses. Estimate the order of filter. Does your design meet
the specifications? If it does not, adjust the filter order until the design meets the specifications.
What is the order of the filter meeting the specifications?
Page
64
LAB MANUAL
LAB # 10
There are two tool boxes available for designing, analyzing and for viewing different responses
(Impulse & Step) of FIR and IIR filters.
fvtool
fdatool
Filter Visualization Tool:
FVTOOL is a Graphical User Interface (GUI) that allows you to analyze digital filters. FVTOOL (B,A)
launches the Filter Visualization Tool and computes the magnitude Response for the filter defined
in B and A. FVTOOL(B,A,B1,A1,...) will perform an analysis on multiple filters. The real advantage of
this visualization tool is that we can view the magnitude response and phase response
simultaneously, the impulse response, step response the coefficients of the filter etc Let us
consider a Low Pass FIR filter of order 30 which passes all frequencies below 2000 Hz with sampling
rate of 8000 Hz.
b=fir1(30,2000/4000,low);
fvtool(b,1)
Page
65
LAB MANUAL
Now we will design a LPF on fdatool, the specifications for the filter are shown in respective
columns of FDA tool
Page
66
LAB MANUAL
Lab Tasks
1. Design IIR butter worth filter with following specifications
-50 dB or more for 0 to 1200 Hz ( Stop Band Attenuation )
-1 dB or less from 2000 Hz to 4000 Hz ( Pass Band Characteristics )
-50 dB or more above 6000 Hz ( Stop Band Attenuation )
Sampling frequency 16000 Hz
2. Design FIR Equripple Filter with following specifications
-50 dB or more for 0 to 1200 Hz ( Stop Band Attenuation )
-1 dB or less from 2000 Hz to 4000 Hz ( Pass Band Characteristics )
-50 dB or more above 6000 Hz ( Stop Band Attenuation )
Sampling frequency 16000 Hz
3. Use FVA Tool to Analyze a Low pass filter that passes all frequencies below 2000 Hz and
sampling frequency is 8000Hz and Order of filter is 30
Page
67
LAB MANUAL
LAB # 11
Discrete Fourier Transform
The discrete Fourier transform (DFT) X[k] of a finite-length sequence x[n] can be easily computed in
MATLAB using the function fft. There are two versions of this function. fft(x) computes the DFT X[k]
of the sequence x[n] where the length of X[k] is the same as that of x[n]. fft(x,L) computes the Lpoint DFT of a sequence x[n] of length N where L N . If L > N , x[n] is zero-padded with L N
trailing zero-valued samples before the DFT is computed. The inverse discrete Fourier transform
(IDFT) x[n] of a DFT sequence X[k] can likewise be computed using the function ifft, which also has
two versions.
Project 13.1 DFT Properties
Two important concepts used in the application of the DFT are the circular-shift of a sequence and
the circular convolution of two sequences of the same length. As these operations are needed in
verifying certain properties of the DFT, we implement them as MATLAB functions circshift1 and
circonv as indicated below:
function y = circshift1(x,M)
% Develops a sequence y obtained by
% circularly shifting a finite-length
% sequence x by M samples
if
end
if
end
y =
end
M
M
<
=
0
M
length(x);
[x(M+1:length(x))
x(1:M)];
function y = circonv(x1,x2)
L1 = length(x1);
L2 = length(x2);
if L1 ~= L2,
error('Sequences of unequal lengths'),
end
y = zeros(1,L1);
x2tr = [x2(1) x2(L2:-1:2)];
for k = 1:L1
sh = circshift1(x2tr,1-k); h = x1.*sh;
y(k) = sum(h);
end
Page
68
LAB MANUAL
Program P13_1 can be used to illustrate the concept of circular shift of a finite-length sequence. It
employs the function circshift1
% Program P13_1
% Illustration of Circular Shift of a Sequence
clear all; close all; clc
M=6;
a=[0 1 2 3 4 5 6 7 8 9];
b = circshift1(a,M);
L = length(a)-1;
n = 0:L;
subplot(2,1,1);
stem(n,a);axis([0,L,min(a),max(a)]);
title('Original Sequence');
subplot(2,1,2);
stem(n,b);axis([0,L,min(a),max(a)]);
title(['Sequence Obtained by Circularly Shifting by
',num2str(M),'Samples']);
Program P13_2 can be used to illustrate the circular time-shifting property of the DFT. It employs
the function circshift1.
% Program P13_2
% Circular Time-Shifting Property of DFT
close all; clear all; clc
x=[0 2 4 6 8 10 12 14 16];
N = length(x)-1; n = 0:N;
y = circshift1(x,5);
XF = fft(x);
YF = fft(y);
subplot(2,2,1)
stem(n,abs(XF)); grid
title('Magnitude of DFT of Original Sequence');
subplot(2,2,2)
stem(n,abs(YF)); grid
title('Magnitude of DFT of Circularly Shifted Sequence');
subplot(2,2,3)
stem(n,angle(XF)); grid
title('Phase of DFT of Original Sequence');
subplot(2,2,4)stem(n,angle(YF)); grid
title('Phase of DFT of Circularly Shifted Sequence');
Page
69
LAB MANUAL
60
40
40
20
20
-2
-2
-4
-4
Program P13_3 can be used to illustrate the circular convolution property of the DFT. It employs
the function circonv.
% Program P13_3
% Circular Convolution Property of DFT
clear all; close all; clc
g1=[1 2 3 4 5 6];
g2=[1 -2 3 3 -2 1];
ycir = circonv(g1,g2);
disp('Result of circular convolution = ');
disp(ycir)
G1 = fft(g1);
% similarly compute fft of g2 and save in G2
yc = real(ifft(G1.*G2));
disp('Result of IDFT of the DFT products = ');
disp(yc)
Program P13_4 can be used to illustrate the relation between circular and linear convolutions
% Program P13_4
% Linear Convolution via Circular Convolution
close all; clear all; clc
g1=[1 2 3 4 5];
g2 = [2 2 0 1 1];
g1e = [g1
g2e = [g2
zeros(1,length(g2)-1)];
zeros(1,length(g1)-1)];
%Do circular convolution of g1e and g2e and save in ylin yourself
disp('Linear convolution via circular convolution = ');
disp(ylin);
y = conv(g1, g2);
disp('Direct linear convolution = ');disp(y)
Page
70
LAB MANUAL
Program P13_5 can be used to verify the relation between the DFT of a real sequence, and the
DFTs of its periodic even and the periodic odd parts.
% Program P13_5
% Relations between the DFTs of the Periodic Even
% and Odd Parts of a Real Sequence
close all; clear all; clc
x=[1 2 4 2 6 32 6 4 2 zeros(1,247)];
x1 = [x(1) x(256:-1:2)];
xe = 0.5 *(x + x1);
XF = fft(x);
XEF = fft(xe);
k = 0:255;
subplot(2,2,1);
plot(k/128,real(XF)); grid
ylabel('Amplitude');
title('Re(DFT\{x[n]\})');
subplot(2,2,2);
plot(k/128,imag(XF));
grid
ylabel('Amplitude');
title('Im(DFT\{x[n]\})');
subplot(2,2,3);
plot(k/128,real(XEF)); grid
xlabel('Time index n'); ylabel('Amplitude');
title('Re(DFT\{x_{e}[n]\} )');
subplot(2,2,4);
plot(k/128,imag(XEF)); grid
xlabel('Time index n');ylabel('Amplitude');
title('Im(DFT\{x_{e}[n]\})');
Page
71
LAB MANUAL
Lab # 12
Introduction to Hardware & Software tools of TMS320C6713 DSK
Digital Signal Processors (DSPs) are used for a wide range of applications, from communications and
controls to speech and image processing. Many consumer products have embedded DSPs such as
cellular phones, fax/modems, hearing aids, printers, radio, MP3 players, digital cameras, etc. In this lab,
a block sine-wave generator function is used to create the data samples, which is a simple for loop
generating individual sine values to be graphed later. The focus of Lab 1 is to introduce and familiarize
the students with the TMS320C6713 DSK and the Code Composer Studio. All the steps required to
create, build and execute a complete project are discussed in detail.
2. Digital signals can be manipulated easily. Since the signal is just a sequence of zeros and ones, and
since a computer (or other similar devices) can do anything specifiable to such a sequence, a great
number of operations can be performed on the digital signals. This is called Digital Signal Processing.
Page
72
LAB MANUAL
Fig. 12.1
3. Digital Signal Processors are programmable, i.e., the same hardware can be used for different
application by writing a different code.
Page
73
LAB MANUAL
Page
74
LAB MANUAL
Page
75
LAB MANUAL
Lab Procedure
The complete programming procedure for this lab consists of the following steps.
1. Since CCS has already been installed on the workstations, you only have to connect the DSK
to the PC. Plug the AC power cord into the power supply and then plug the power cable
into the board. Connect the USB cable to your PC. When the DSK board is powered on, a
program stored in Flash Memory called POST.c (Power On Self Test) is run to test the DSK.
It tests the memories (internal, external and flash), Direct Memory Access (DMA), two
Multichannel Buffered Serial Ports (McBSP), onboard codec, and the LEDs. If all the tests
are successful, all four LEDs blink three times and then stop while remaining on.
2. For testing the DSK as well as the USB connection, launch 6713 DSK Diagnostics Utility from
the icon on the desktop. From the diagnostic utility, press the start button to run the
diagnostics. In approximately 30 seconds, all the test indicators, namely USB, Emulation,
DSP, External Memory, Flash, Codec, LED and dip switches, should turn green as shown in
Figure 12. 6.
3. To create a new project, open the CCS and select Project -> New as shown in Figure 11. 8. A
window as in Figure 12.7 will appear. make sure that the project location is
C:\CCStudio_v3.1\MyProjects. Project type should be Executable (.out) and choose the
correct target according to the DSK being used (TMS320C67XX in this lab).
Page
76
LAB MANUAL
4. Click on the + sign next to the Projects folder in the Project View Window to check whether the
project has been created correctly or not
5. To create a new BIOS file. Select file a, new ,DSP/BIOS Configuration file.
Page
77
LAB MANUAL
7. Click on dsk6713 configuration file and click ok a new window will open
8. Right click on RTDX and then click on properties. Set the properties as shown in figure
below
Page
78
LAB MANUAL
9. Save the configuration file. Now right click on project then click on add and add the above
config (cdb) file in project.
10. The dependant files can be included in the project by right-clicking intro.pjt and selecting Scan
All File Dependencies or doing the same from Project menu bar.
11. Select the following options from Project -> Build Options:
a. Basic -> Target Version C671x
b. Preprocessor -> Pre-Define Symbol (-d) CHIP_6713
c. Preprocessor -> Include Search Path (-i) C:\CCStudio_v3.1\Support
12. Examine the main C code once again by inspecting intro.c by double clicking on the file name in
the Project Window.
13. Build the program to create an executable file (intro.out) by either using the Rebuild All toolbar
icon
or selecting Project -> Rebuild All. Check the Build Output Window at the bottom of the
CCS. Make sure that there are no errors and warnings.
14. If any of the following warnings appear after compilation, apply the correspond remedy as
follows:
a. >> warning: creating .stack section with default size of 400 (hex) words. Since we did not
define any stack size, it is just informing us that it is going to default the stack size to 1K (=
400H). Go to Project -> Build Options -> Linker -> Stack Size (-stack) and set it equal to 400H.
b. >> warning: Detected a near (.bss section relative) data reference to the symbol
_DSK6713_AIC23_codecdatahandle defined in section .far. The reference occurs in
C:\CCStudio_v3.1\MyProjects\Introduction\Debug\c6713dskinit.obj, section .text, SPC offset
00000058. Either make the symbol near data by placing it in the .bss section, or make the
references to the symbol far. For C/C++ code use 'far' or 'near' modifiers on the type
definition of the symbol or compile with the --mem_model:data switch. Go to Project -> Build
Options -> Advanced -> Memory Models and set memory model data = far.
Page
79
LAB MANUAL
c. >> warning: last line of file ends without a newline. Just add an empty line after the closing
bracket } of the function main ().
15. Any variable values can be monitored by adding those variables to the Watch Window. The
programmer can see the value of those variables being updated during various steps of the
program. For this lab, select and highlight different variables in the program, right click on the
variable and select Add to Watch Window and a window like Figure 11.11 will appear as a result.
16. The contents of the memory (e.g., value of individual elements in an array) can be viewed by
selecting View -> Memory and type the following.
Name of variable
a. Title
b. Address
Name of variable
c. Q-Value
0
d. Format
Any style
Before the program is run, random values will be present at the memory location at that time.
17. For initializing a variable in the memory, select Edit -> Memory -> Fill and fill in the required
information in the window.
18. The code can be run through CCS by any of the following ways.
a. Use the toolbar icon
b. Select Debug -> Run
c. Press F8
19. Press DIP switch # 0 and check if LED # 0 is turned on. Simultaneously, keep the DIP switch # 0
pressed, and connect speakers to line out or headphone out of the DSK 6713. Can you hear a
tone?
20. Although Watch Window is a great resource to watch the variables values, but it is better to view
them in a graph (e.g., to confirm in our experiment that sine_table is a sine wave). CCS provides
this capability of graphing the available data. Select View -> Graph -> Time/Frequency and modify
the following.
a. Graph Title
Name of variable
b. Start Address
Name of variable
c. Acquisition Buffer Size
As required
d. Display Data Size
As required
e. DS Data Type
As required
Page
80
LAB MANUAL
f.
Sampling Rate
As required
CCS supports many graphing features such as time frequency, FFT magnitude, dual-time,
constellation, etc.
Page
81
LAB MANUAL
Lab # 13
Performing Linear Convolution on TMS320C6713 DSK
13.1 Create new Project:
1.
2.
Page
82
LAB MANUAL
13.2 Aim:
Linear Convolution of the two given sequence
Where x(n) is the input signal and h(n) is the impulse response of the system.
13.4 C Program:
Page
83
LAB MANUAL
13.5 Output:
1, 4, 10, 20, 25, 24, 16.
4. Enter the source code and save the file with .C extension.
Page
84
LAB MANUAL
5.Right click on source, Select add files to project and Choose .C file Saved before.
Page
85
to
Project..
and
choose
LAB MANUAL
a) Go to Project to Compile
b) Go to Project to Build.
c) Go to Project to Rebuild All.
7. Go to file and load program and load .out file into the board.
Page
86
LAB MANUAL
Page
87
LAB MANUAL
10. To see the Graph go to View and select time/frequency in the Graph, And give the correct Start
address provided in the program, Display data can be taken as per user.
Page
88
LAB MANUAL
11. Green line is to choose the point, Value at the point can be seen (Highlighted by circle at the left
corner).
Page
89
LAB MANUAL
Lab # 14
Performing Circular Convolution on TMS320C6713 DSK
14.1 Create new Project:
1.
2.
Page
90
LAB MANUAL
3. Click on File
Page
91
LAB MANUAL
14.2 AIM:
To implement circular convolution of two sequences
14.4 Program:
On Next Page
Page
92
LAB MANUAL
Page
93
LAB MANUAL
14.5 Output:
enter the length of the first sequence
4
enter the length of the second sequence
4
enter the first sequence
4321
enter the second sequence
1111
the circular convolution is
10 10 10 10
4. Enter the source code and save the file with .C extension.
4. Right click on source, Select add files to project and Choose .C file Saved before.
Page
94
LAB MANUAL
5. Right
Click
on
libraries
and
select
add
files
C:\CCStudio_v3.1\C6000\cgtools\lib\rts6700.lib and click open.
7. a) Go to Project to Compile .
Page
95
to
Project..
and
choose
LAB MANUAL
b) Go to Project to Build.
c) Go to Project to Rebuild All.
8. Go to file and load program and load .out file into the board.
Page
96
LAB MANUAL
Page
97
LAB MANUAL
Page
98
LAB MANUAL
Page
99
LAB MANUAL
The corresponding output will be shown on the output window as shown below
10. To see the Graph go to View and select time/frequency in the Graph, and give the correct Start
address provided in the program, Display data can be taken as per user.
Page
100
LAB MANUAL
11. Green line is to choose the point, Value at the point can be seen (Highlighted by circle at the left
corner).
Page
101
LAB MANUAL
Lab No 15
Interfacing TMS320C6713 DSK with MATLAB
Page
102