lab manual final - fuuasteefuuastee.weebly.com/uploads/1/0/5/6/10561538/dsp_lab_manual_final… ·...

102
LAB MANUAL| DIGITAL SIGNAL PROCESSING Page 1

Upload: duongxuyen

Post on 06-Feb-2018

222 views

Category:

Documents


0 download

TRANSCRIPT

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page 1

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page 2

Lab No List of Labs 1 Introduction to Matlab

2 Discrete Time Signals in Time Domain

3 Discrete time systems in Time Domain

4 Discrete Time System in Frequency Domain

5 Z-Transform

6 Digital Processing of Continuous Signals

7 Term Project

8 Decimation & Interpolation

9 Digital Filter Structure

10 Digital Filter Design

11 Digital Filter Design Using Matlab Tools

12 Discrete Fourier Transform

13 Introduction to Hardware & Software tools of TMS320C6713 DSK

14 Performing Linear Convolution on TMS320C6713 DSK

15 Performing Circular Convolution on TMS320C6713 DSK

16 Interfacing TMS320C6713 DSK with Matlab

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page 3

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.

The MATLAB Environment MATLAB’s desktop includes four sub-windows

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

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page 4

• Command History

MATLAB maintains a history of the commands that have been previously entered in the

command window

Figure 1.1: The Matlab Window.

The Command Window is where you enter commands. The Workspace Window shows the variables

defined in the workspace. The Command History window stores a history of the commands you have

run. You can move these child windows around within the main Matlab window if you wish.

Working in MATLAB

Getting Help If you need more information about any Matlab functions, there are several ways of getting it:

• At the prompt, type help followed by the function name, e.g.

(type help” on its own to get a list of help topics.) Matlab online help entries use uppercase

characters for the function and variable names to make them stand out from the rest of the

text. When typing function names, however, always use the corresponding lowercase characters

because Matlab is case sensitive and most function names are actually in lowercase.

• To look for a command whose name you do not know, use “lookfor",

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page 5

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

Entering Commands and Command-line Editing In Matlab, commands are entered at the prompt and run when the return key is entered. For example, if

you wanted to know the value of 2π, you could enter

At the prompt (pi is a built-in constant). Matlab will give the answer,

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.

• Loading matrices from external data files.

• Generating matrices using functions.

To enter a matrix explicitly, there are a few basic rules to follow:

• Separate the elements of a row with blanks or commas.

• Use a semicolon “;” or carriage returns to indicate the end of each row.

• Surround the entire list of elements with square brackets, [ ].

For example, to input a 4 x 4 magic square enter:

at the prompt, this describes the matrix

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page 6

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.

• randn: as rand, except the numbers are normally distributed.

• eye: makes an identity matrix. E.g. eye(10) makes a 10 by 10 matrix with 1’s on the diagonal and

0’s off the diagonal.

Accessing Elements of a Matrix An element of a matrix can be referred to by using the format M(row,column). For example, A(3,2) is 6.

So to calculate the sum of the top row of A, one could use

(There are simpler ways to do this, as shown in the next section). A range of the array can be referred to

by using the colon operator. M(i:j,k) refers to the rows i through j of the kth column. For example,

yields,

The colon by itself refers to the entire row or column. For example, A(:,2) is the entire second column of

A,

Thus, A(:,2)is equivalent to A(1:4,2).

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page 7

More on the Colon Operator The colon (:) is one of Matlab's most important operators. It occurs in several different forms. The

expression 1:10 is a row vector containing the integers from 1 to 10 (i.e. [1 2 3 4 5 6 7 8 9 10]). To obtain

non-unit spacing, specify an increment. For example:

(pi is a built-in scalar constant).

Subscript expressions involving colons refer to portions of a matrix, as we have seen. So, A(1:3,4) means

the same as A([1,2,3],4),

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:

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page 8

diag: Returns the diagonal of the matrix M.

sqrt: Returns the square root of the elements of matrix M.

size: Returns the dimensions of the matrix M. This is returns a list of two values; the form is like this

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:

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page 9

However, these can be used with matrices as well:

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 built-

in 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].

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

10

Introduction to MATLAB -- Continued Graphics in Matlab

Plotting Functions Matlab has range of built-in graphics and plotting routines. The command plot(x,y) makes a two

dimensional plot of x against y. For example,

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,

To get rid of the figure, type close at the Matlab

prompt.

There are a load of options to plot, which help

plot will show. It is possible to control whether

the plots are lines or points, the line style, color,

and other properties of the plots. The basic

form is plot(x,y,str) where str is a string of one

to three characters denoting color, symbol plotted at each point (if any) and line type (if any). Here is a

table of options,

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

11

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:

Modify axis tick marks and tick labels:

Add a plot title, axis labels, and annotations

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

12

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

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

13

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:

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

14

Scripts and functions An M-file is a plain text file containing MATLAB commands and saved with the filenameextension “.m”.

There are two types, scripts and functions. MATLAB comes with a pretty good editor that is tightly

integrated into the environment; start it by typing edit with a file name. However, you are free to use

any text editor. An M-file should be saved in the path in order to be executed. The path is just a list of

directories folders) in which MATLAB will look for files. Use editpath or menus to see and change the

path. There is no need to compile either type of M-file. Simply type in the name of the file (without the

extension) in order to run it. Changes that are saved to disk will be included in the next call to the

function or script. (You can alter this behavior with mlock.) One important type of statement in an M-file

is a comment, which is indicated by a percent sign %. Any text on the same line after a percent sign is

ignored (unless % appears as part of a string in quotes). Furthermore, the first contiguous block of

comments in an M-file serves as documentation for the file and will be typed out in the command

window if help is used on the file.

Using scripts effectively The contents of a script file are literally interpreted as though they were typed at the prompt. In fact,

some people prefer to use MATLAB exclusively by typing all commands into scripts and running them.

Good reasons to use scripts are

• Creating or revising a sequence of more than four or five lines.

• Reproducing or rereading your work at a later time.

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.

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

15

From MATLAB you could call

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 function’s 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.

• Comment statements are preceded by a "%".

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

• You can make a keyword search by using the lookfor command.

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

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

16

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

Learning to work in M-Files M-files are macros of MATLAB commands that are stored as ordinary text files with the extension "m" ,

that is ‘filename.m’. An M-file can be either a function with input and output variables or a list of

commands.

For example, consider using MATLAB on a PC with a user-defined M-file stored in a directory called

"C:\MATLAB\MFILES" . Then to access that M-file, either change the working directory by typing cd c:\matlab\mfiles from within the MATLAB command window or by adding the directory to the path.

Permanent addition to the path is accomplished by editing the C:\MATLAB\matlabrc.m file, while

temporary modification to the path is accomplished by typing path(path,'c:\matlab\mfiles') from within

MATLAB.

Or, this can easily be achieved through the path browser. As example of an M-file that defines a

function, create a file in your working directory named yplusx.m that contains the following commands:

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)

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

17

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.

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

18

PROJECT 3.2 EXPONENTIAL SIGNALS Exponential signals can be generated in MATLAB using “.^” and “exp” commands. Program P3_2 can be

used to generate a complex valued exponential.

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

19

Program P3_3 can be used to generate a real valued exponential sequence

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

20

PROJECT 3.3 SINUSOIDAL SEQUENCES Sinusoidal sequences can be generated in MATLAB using “sin” and “cos” functions. Program

P3_4 is a MATLAB code that generates a sinusoidal signal.

PROJECT 3.4 RANDOM SIGNALS A random signal of length N with samples uniformly distributed in the interval [0,1] can be generated

using the following MATLAB command

Similarly a random signal of length N with samples normally distributed with zero mean and variance

one can be generated using the MATLAB command

Simple Operations on Sequences The main purpose of digital signal processing is to process an input signal to produce an output signal.

This processing is a combination of addition, scalar multiplication, time reversal, delaying and product

operations. The following projects illustrate some of these operations.

PROJECT 3.5 SIGNAL SMOOTHING One of the applications of digital signal processing is to remove random noise from a signal which has

been corrupted by noise. Let s [n] be the signal corrupted by a random noise d [n] resulting in the noisy

signal x[n] = s[n] + d[n] . The objective is to operate on x [n] to generate a signal y [n] which is a

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

21

reasonable approximation to s [n]. This can be done by averaging the samples of x[n]. This is referred to

as moving average filter.

Program P3_5 implements the above algorithm

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

22

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

23

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. What will happen if the parameter c is changed to (1/12)+(pi/6)*i?

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. What is the length of this sequence and how can it be changed?

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)

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

24

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]=Tx[n]

The aim of the lab is to develop algorithms for this operator T.

Following systems will be implemented in this lab

1. Linear System

2. Time invariant System

3. Linear Time Invariant System

1. Linear & Non-Linear Systems

The class of linear system is defined by the principle of superposition. If y1[n] and y2[n] are the

responses of system when x1[n] and x2[n] are the respective inputs, then system is linear if and only if

Tx1[n] + x2[n] =Tx1[n] + Tx2[n] = y1[n]+y2[n]

And

Tax1[n]= aTx1[n]

Where a is an arbitrary constant. The first property is called additivity property, and second is called the

homogeneity or scaling property. These two properties can be combined into the principle of

superposition stated as

Consider the following system

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

25

y[n]=5x1[n] + 10x2[n]

2. Time Invariant and Variant Systems

A time invariant system for which a delay or shift in input sequence causes corresponding shift in output

sequence. Specifically, suppose that system transforms the input sequence with values x[n] into output

sequence with values y[n]. the system in invariant if and only if for all n1, the sequence with input values

x1[n]=x[n-n1] produces output sequence with values y1[n]=y[n-n1]

Simulation of Discrete-Time Systems In Project 3_5 during the last lab we illustrated the application of a simple discrete-time system in the

smoothing of data corrupted by a random noise. The equation of that smoothing filter is given below;

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

Project 4.1 The Moving Average System Generalizing form moving average system is

(4.1)

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

26

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.

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

27

Project 4.2 A Simple Nonlinear Discrete-Time System (Optional) Let y[n] be a signal generated by applying the following nonlinear operations on a signal x[n]:

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

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

28

Project 4.3 Linear and Nonlinear Systems We now investigate the linearity property of a causal system. Consider the system given by

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

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

29

Project 4.4 Time-Invariant and Time-Varying Systems We next investigate the time-invariance property of a causal system.

MATLAB Program P4.4 is used to simulate the system, to generate two different input sequences x[n]

and x[n - D], and to compute and plot the corresponding output sequences y1[n], y2[n], and the

difference y1[n] - y2[n + D].

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

30

Project 4.5 Convolution The convolution operation is implemented in MATLAB by the command conv, provided the two

sequences to be convolved are of finite length. For example, the output sequence of an FIR system can

be computed by convolving its impulse response with a given finite-length input sequence.

Or can be represented as

The following MATLAB program illustrates this approach.

Project 4.6 Stability of LTI Systems As indicated, an LTI discrete-time system is BIBO stable if its impulse response is absolutely sum able. It

therefore follows that a necessary condition for an IIR LTI system to be stable is that its impulse

response decays to zero as the sample index gets larger. Program P4 8 is a simple MATLAB program

used to compute the sum of the absolute values of the impulse response samples of a causal IIR LTI

system. It computes N samples of the impulse response sequence, evaluates

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(∞).

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

31

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

32

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.

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

33

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.

5.1 Discrete-Time Fourier Transform The discrete-time Fourier transform (DTFT) X(e

jW ) of a sequence x[n] is a continuous function of W.

Since the data in MATLAB is in vector form, X(ejW

) can only be evaluated at a prescribed set of discrete

frequencies. Moreover, only a class of the DTFT that is expressed as a rational function in e-jW in the

form

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(e

jW ) 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).

Project 5.2 DTFT Properties

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

34

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.

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

35

Program P5_3 can be used to verify the frequency-shifting property of the DTFT.

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

36

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

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

37

Program P5_6 can be used to verify the time-reversal property of the DTFT.

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

38

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 range the following DTFT:

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.

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

39

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 z-

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

Bilateral Z-transformThe bilateral or two-sided Z-transform of a discrete-time signal x[n] is the

function X(z) defined as

.

Unilateral Z-transformAlternatively, in cases where x[n] is defined only for n ≥ 0, the single-sided or

unilateral Z-transform is defined as

In signal processing, this definition is used when the signal is causal.

As analog filters are designed using the Laplace transform, recursive digital filters are developed with a

parallel technique called the z-transform. The overall strategy of these two transforms is the same:

probe the impulse response with sinusoids and exponentials to find the system's poles and zeros. The

Laplace transforms deals with differential equations, the s-domain, and the s-plane. Correspondingly,

the z-transform deals with difference equations, the z-domain, and the z-plane. However, the two

techniques are not a mirror image of each other; the s-plane is arranged in a rectangular coordinate

system, while the z-plane uses a polar format. Recursive digital filters are often designed by starting with

one of the classic analog filters, such as the Butterworth, Chebyshev, or elliptic. A series of mathematical

conversions are then used to obtain the desired digital filter. The Z transform of a discrete time system

X[n] is defined as Power Series.

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

40

Rational Z-transform to factored Z-transform:

Example:

Let the given transfer function be in the rational form,

2z4+16z

3+44z

2+56z+32

G(z)= --------------------------------

3z4+3z

3-15z

2+18z-12

It is required to convert it into factored form, so that we can find the poles and zeros mathematically by

applying quadratic equation.

Matlab command required for converting rational form to factored form be

‘Zp2sos’

The factored form of G(z) as evaluated by ‘zp2sos’ be,

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

)

Factored Z-transform / zeros,poles to rational Z-transform:

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)

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

41

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

Rational Z-transform to partial fraction form:

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__ + _0.4____

1 – 0.5z-1 1+0.33 z-1 (1+0.33 z-1)

Matlab command that converts rational z-transform in to partial fraction form is

‘residuez’.

Partial fraction form to Z-transform:

This technique is used when it is required to convert partial fraction expression in to

rational Z-transform.

Example:

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

42

Take the partial fraction form of above ,

The partial fraction form be,

G(z)= 0.36__ + __0.24__ + _0.4____

1 – 0.5z-1 1+0.33 z-1 (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))

Pole Zero Diagrams For A Function In Z Domain:

Z plane command computes and display the pole-zero diagram of Z function.

The Command is

Zplane(b,a)

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

43

To display the pole value, use root(a)

To display the zero value, use root(b)

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

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

44

LAB TASK:

Task#1: Express the following z-transform in factored form , plot its poles and zeros,and then determine

its ROCs.

2z4+16z

3+44z

2+56z+32

G(z)= --------------------------------

3z4+3z

3-15z

2+18z-12

Task#2: Determine the partial fraction expansion of the z-transform G(z) given by

18z3

G(z)= ------------------

18z3+3z

2-4z-1

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

45

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.

6.1 The Sampling Process in the Time Domain The purpose of this section is to study the relation in the time domain between a continuous-time signal

xa (t) and the discrete-time signal x[1] generated by a periodic sampling of xa (t).

Project 6.1 Sampling of a Sinusoidal Signal In this project you will investigate the sampling of a

continuous-time sinusoidal signal xa (t) at various sampling rates. Since MATLAB cannot strictly generate

a continuous-time signal, you will generate a sequence xa (nTH ) from xa (t) by sampling it at a very high

rate, 1/TH , such that the samples are very close to each other. A plot of xa (nTH ) using the plot

command will then look like a continuous-time signal.

Project 6.2 Aliasing Effect in the Time Domain

In this project you will generate a continuous-time equivalent ya (t) of the discrete-time signal x[1]

generated in Program P7_1 to investigate the relation between the frequency of the sinusoidal signal xa

(t) and the sampling period. To generate the reconstructed signal ya (t) from x[1], we pass x[1] through

an ideal lowpass filter that in turn can be implemented according to Eq. (7.1). If Eq. (7.1) is computed at

closely spaced values of t, a plot of ya (t) will resemble a continuous-time signal. In order to implement

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

46

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

6.2 Effect of Sampling in the Frequency Domain

Project 7.3 Aliasing Effect in the Frequency Domain The relation between the continuous-time Fourier

transform (CTFT) of an arbitrary band- limited continuous-time signal and the discrete-time Fourier

transform (DTFT) of the discrete-time signal is investigated next in this project. In order to convert a

continuous-time signal xa (t) into an equivalent discrete-time signal x[1], the former must be band-

limited in the frequency domain. To illustrate the effect of sampling in the frequency domain we choose

an exponentially decaying continuous-time signal with a CTFT that is approximately band-limited.

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

47

6.3 Analog Low pass Filters Analog low pass filters are employed as anti-aliasing filters and as anti-imaging filters in the digital

processing of continuous-time signals. In this section you will learn the design of the four types of analog

lowpass filters summarized in R7.6 through R7.9.

Project 7.4 Design of Analog Lowpass Filters

The first step in the design of any of these filters is the determination of the filter order N and the

appropriate cutoff frequency ΩC. These parameters can be determined using the MATLAB commands

buttord for the Butterworth filter, cheb1ord for the Type 1 Chebyshev filter, cheb2ord for the Type 2

Chebyshev filter, and ellipord for the elliptic filter. ΩC is the 3-dB cutoff frequency for the Butterworth

filter, the passband edge for the Type 1 Chebyshev filter, the stopband edge for the Type 2 Chebyshev

filter, and the passband edge for the elliptic filter. For the design of filters MATLAB commands are

butter for the Butterworth filter, cheby1 for the Type 1 Chebyshev filter, cheby2 for the Type 2

Chebyshev filter, and ellip for the elliptic filter.

Program P7 4 can be used for the design of the Butterworth low pass filter.

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

48

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

49

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?

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

50

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 multi-

rate system. You will then investigate their use in designing more complex systems, such as

interpolators and decimators, and filter banks.

Basic Sampling Rate Alteration Devices The objective of this section is to investigate using MATLAB the operations of the up-sampler and

the down-sampler both in the time domain and in the frequency domain.

Input-Output Relations in the Time-Domain

Program P10_1 can be used to study the operation of a up-sampler.

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

51

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.

Decimator Design and Implementation

Program P10_3 illustrates the use of the M-function decimate in the design and implementation of a

decimator with an integer-valued decimation factor M. In the option utilized in this program, decimate

designs and uses a lowpass decimation filter with a stopband edge.

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

52

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

53

Interpolator Design and Implementation

Interpolator Design and Implementation

Program P10_4 illustrates the use of the M-function interp in the design and implementation of an

interpolator with an integer-valued interpolation factor L. interp designs and uses a lowpass

interpolation filter with a stopband edge satisfying Eq. (10.1).

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

54

Fractional-Rate Sampling Rate Alteration

Program P10_5 illustrates the use of the M-function resample in the design and implementation of an

interpolator with a fractional-rate interpolation factor L/M. Resample designs and uses a lowpass

interpolation filter with a stopband edge.

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

55

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?

3. Modify Program P10_1 to study the operation of an up-sampler on a ramp sequence.

4. Program P10_2 can be used to study the operation of a down-sampler

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. How is the down-sampling operation implemented in Program P10_2?

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. Run Program P10_3 for M = 4 and comment on the results.

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?

11. Run Program P10_4 for L = 2 and comment on the results.

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.

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

56

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.

Realization of FIR Transfer Functions

Cascade Realization

The factored form of a causal FIR transfer function H (z) of order M — 1, as given in Eq. (8.1) can be

determined from its polynomial form representation given by Eq. (8.2) which can then be utilized to

realize H (z) in a cascade form. To this end, a modified form of Program P8 1 that uses the function

zp2sos can be employed.

Realization of IIR Transfer Functions

Cascade and Parallel Realizations

The factored form of a causal IIR transfer function H (z) of order N as given in Eq. (8.3) can be

determined from its rational form representation given by Eq. (8.4), which then can be used to realize H

(z) in a cascade form. To this end, Program P8 1 can be employed.

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

57

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

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

58

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

59

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

Sketch the block diagram of the cascade realization

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

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

60

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.

IIR Filter Design The most common method of IIR filter design is based on the bilinear transformation of a

prototype analog transfer function. The analog transfer function is usually one of the following

types: Butterworth, Type 1 Chebyshev, Type 2 Chebyshev, and elliptic transfer functions. The

difference between these filter types can be explained by considering the analog lowpass filter.

The Butterworth lowpass transfer function has a maximally-flat magnitude response at dc, that

is, Ω = 0, and a monotonically decreasing magnitude response with increasing frequency.

The Type 1 Chebyshev lowpass transfer function has an equiripple magnitude response in the

pass band and a monotonically decreasing magnitude response with increasing frequency

outside the pass band.

The Type 2 Chebyshev lowpass transfer function has a monotonically decreasing magnitude

response in the pass band with increasing frequency and an equiripple magnitude response in

the stop band.

Finally, the elliptic low pass transfer function has equiripple magnitude responses both in the

pass band and in the stop band.

Estimation of Order of IIR Filter

The first step in the filter design process is to choose the type of filter approximation to be

employed and then to estimate the order of the transfer function from the filter specifications.

The MATLAB command for estimating the order of a Butterworth filter is

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

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

61

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

Finally, in the case of an elliptic filter design, the command 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.

IIR Filter Design

After the filter type has been selected and its order estimated the next step is to determine the

transfer function of the filter. To this end MATLAB provides functions for all four types of filters.

For designing Butterworth digital low pass or band pass filters, the command is

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

Whereas, the command

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

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

62

For designing a Type 2 Chebyshev digital filter, the commands are

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

FIR Filter Design Conceptually the simplest approach to FIR filter design is to simply truncate to a finite number of

terms the infinite-length impulse response coefficients obtained by computing the inverse discrete-

time Fourier transform of the desired ideal frequency response. However, a simple truncation

results in an oscillatory behavior in the respective magnitude response of the FIR filter, which is

more commonly referred to as the Gibbs phenomenon.

The Gibbs phenomenon can be reduced by windowing the infinite-length impulse response coefficients

by an appropriate finite-length window function. The functions fir1 and fir2 can be employed to design

windowed FIR digital filters in MATLAB. Both functions yield a linear-phase design. The function fir1 can

be used to design conventional low pass, high pass, band pass, and band stop linear-phase FIR filters.

The command

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

63

returns in vector b the impulse response coefficients, arranged in ascending powers of z—1 , of a

lowpass or a bandpass filter of order N for an assumed sampling frequency of 2 Hz. For low pass design,

the normalized cutoff frequency is specified by a scalar Wn, a number between 0 and 1. For band pass

design, Wn is a two-element vector [Wn1, Wn2] containing the specified pass band edges where 0 <

Wn1 < Wn2 < 1. The command

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.

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

64

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?

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

65

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)

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

66

Filter Design & Analysis Tool.

FDATOOL launches the Filter Design & Analysis Tool (FDATool). FDATool is a Graphical User

Interface (GUI) that allows you to design or import, and analyze digital FIR and IIR filters. If the

Filter Design Toolbox is installed, FDATool seamlessly integrates advanced filter design methods

and the ability to quantize filters.

Now we will design a LPF on fdatool, the specifications for the filter are shown in respective

columns of FDA tool

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

67

Lab Tasks

1. Design IIR butter worth filter with following speci fications -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

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

68

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 L-

point 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 abs(M) > length(x) M = rem(M,length(x)); end if M < 0 M = M + length(x); end y = [x(M+1:length(x)) x(1:M)]; end

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

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

69

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

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

70

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 zeros(1,length(g2)-1)]; g2e = [g2 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)

0 2 4 6 80

20

40

60

80Magnitude of DFT of Original Sequence

0 2 4 6 80

20

40

60

80Magnitude of DFT of Circularly Shifted Sequence

0 2 4 6 8-4

-2

0

2

4Phase of DFT of Original Sequence

0 2 4 6 8-4

-2

0

2

4Phase of DFT of Circularly Shifted Sequence

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

71

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

Parseval’s relation can be verified using the following program.

% Program P13_6 % Parseval's Relation x = [(1:128) (128:-1:1)]; XF = fft(x); % Take square of vector x and then add all its % entries and save in “a” . Do yourself b = round(sum(abs(XF).^2)/256)

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

72

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.

12.1 Lab Outline The goal of this lab is to generate and graph a sine wave through the following procedure.

1. Getting acquainted with DSK6713 and Code Composer Studio

2. Build and load a program onto the DSK6713

3. Run the program and examine the results

4. Use the CCS graphing feature to verify the results

12.2 Theoretical Background Digital Signal Processors (DSPs) are fast microprocessors with both the architecture and the instruction

set designed to suit different signal processing applications. In this course, we will use the Texas

Instruments (TI) DSP TMS320C6713 to implement various exercises for real time digital signal

processing. The family of C6x processors is the TI’s most powerful DSP since it is based on Very Long

Instruction Word (VLIW) architecture.

12.3 Digital Signal Processing In the real world phenomenon, the signals encountered are analog (i.e., continuous in time and

amplitude) in general. To process this analog signal in digital domain, the first step is converting it into a

digital signal (i.e., discrete in both time and amplitude) achieved by sampling and quantizing the

corresponding analog signal through an Analog-to-Digital Converter (ADC). Digital Signal Processing

(DSP) involves the manipulation of such digital signals in a useful manner. After the processing has been

done, the resultant digital signal is converted back to the analog form through a Digital-to-Analog

Converter (DAC). Fig.11. 1 shows the main components of a DSP system, consisting of ADC, DSP and DAC

devices. A few reasons behind processing the digital signals instead of the original analog signals are:

1. Unlike analog signals, digital signals can be reproduced exactly. All that that has to be done is make

sure that a zero does not get turned into a one or vice versa, which can be achieved by making the

physical signals for zero and one quite different and by building in redundancy. Therefore, digital

circuits provide more stable and tolerant output than analog signals under various environmental

conditions.

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.

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

73

Fig. 12.1 A DSP system comprising of ADC, DSP and DAC

3. Digital Signal Processors are programmable, i.e., the same hardware can be used for different

application by writing a different code.

12.4 TMS320C6713 DSP

Main features of TMS320C6713 DSP are the following.

• It is based on VLIW architecture suitable for computation intensive applications

• A total of 8 instructions can be fetched every cycle

• 264kB of internal memory (8kB as L1P and L1D Cache and 256kB as L2 memory shared between

program and data space)

• 8 execution units composed of 6 Arithmetic Logic Units (ALU) and 2 multiplier units

• 32-bit address bus

• Two sets of 32-bit general-purpose registers

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

74

12.4.1 TMS320C6713 DSP Support Kit (DSK)

Figure 12. 2: TMS320C6713 DSK

The TMS320C6713 DSK board, shown in Figure 12.2 consists of the following components.

• TMS320C6713 floating-point DSP

• 32 bit stereo codec TLV320AIC23 (AIC23) for I/O providing ADC and DAC, which connects to a 12 MHz

system cock and can sample the data from 8 to 96 KHz

• Two 80 pin connectors for external peripheral and external memory interfaces (EMIF)

• 16 MB of Synchronous Dynamic Random Access Memory (SDRAM)

• 256 KB of flash memory

• Four connectors for I/O: MIC IN for microphone input, LINE IN for line input, LINE OUT for line output,

and HEADPHONE for a headphone output (multiplexed with the line output)

• Four dip switches for feedback control interface

• Voltage regulators providing 1.26V for C6713 and 3.3V for memory and peripherals

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

75

FIGURE 12. 3: A block diagram for C6713

12.5 Code Composer Studio (CCS)

The Code Composer Studio (CCS) provides an Integrated Development Environment (IDE) to

incorporate all the software tools for DSP development. CCS includes

1. Tools for code generation such as C compiler, assembler and linker: The C compiler compiles a C

source program with extension .c to produce an assembly source file with extension .asm. The

assembler assembles the .asm source file to produce a machine language object file with extension

.obj. The linker combines object files and object libraries as input producing an executable file with

extension .out. This executable file can be loaded and directly run on the C6713 processor.

2. Real time debugging: The program being run on the C6713 processor can be debugged in real time

by the help of features included in CCS such as setting breakpoints and watching variables in a

window, viewing the processor memory and registers, stepping in, out and over the program, etc.

When Real Time Data eXchange (RTDX) is used for data transfer between the target DSK and the host

PC, CCS helps in monitoring the key statistics and performance in real time.

3. Graphical capabilities: The results of the program can be graphed and execution time of the program

can be monitored using CCS. In short, it is a complete user friendly software tool to build, debug and

monitor the programs for the DSPs. Figure 15.4 shows a snapshot of actual CCS window on the

startup.

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

76

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

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

77

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.

6. Window below will open

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

78

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

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

79

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.

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

80

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.

a. Title Name of variable

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

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

81

f. Sampling Rate As required

CCS supports many graphing features such as time frequency, FFT magnitude, dual-time,

constellation, etc.

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

82

Lab # 13

Performing Linear Convolution on TMS320C6713 DSK

13.1 Create new Project:

1. To create project, go to Project and Select New.

2. Give project name and click on finish.

( Note: Location must be c:\CCStudio_v3.1\MyProjects ).

3. Click on File NewSource File, To write the Source Code.

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

83

13.2 Aim: Linear Convolution of the two given sequence

13.3 Mathematical Formula: The linear convolution of two continuous time signals x(t) and h(t) is defined by

For discrete time signals x(n) and h(n), is defined by

Where x(n) is the input signal and h(n) is the impulse response of the system.

13.4 C Program:

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

84

13.5 Output: 1, 4, 10, 20, 25, 24, 16.

4. Enter the source code and save the file with “.C” extension.

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

85

5.Right click on source, Select add files to project and Choose “.C “ file Saved before.

6. Right Click on libraries and select add files to Project.. and choose

C:\CCStudio_v3.1\C6000\cgtools\lib\rts6700.lib and click open.

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

86

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.

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

87

8. Go to Debug and click on run to run the program.

9. Observe the output in output window.

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

88

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.

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

89

11. Green line is to choose the point, Value at the point can be seen (Highlighted by circle at the left

corner).

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

90

Lab # 14

Performing Circular Convolution on TMS320C6713 DSK

14.1 Create new Project:

1. To create project, go to Project and Select New.

2. Give project name and click on finish.

( Note: Location must be c:\CCStudio_v3.1\MyProjects ).

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

91

3. Click on File NewSource File, To write the Source Code.

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

92

14.2 AIM: To implement circular convolution of two sequences

14.3 Circular Convolution: Let x1(n) and x2(n) are finite duration sequences both of length N with DFT’s X1(k) and X2(k). Convolution of two

given sequences x1(n) and x2(n) is given by the equation,

14.4 Program:

On Next Page

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

93

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

94

14.5 Output:

enter the length of the first sequence

4

enter the length of the second sequence

4

enter the first sequence

4 3 2 1

enter the second sequence

1 1 1 1

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.

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

95

5. Right Click on libraries and select add files to Project.. and choose

C:\CCStudio_v3.1\C6000\cgtools\lib\rts6700.lib and click open.

7. a) Go to Project to Compile .

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

96

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.

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

97

9. Enter the input data to calculate the circular convolution.

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

98

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

99

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

100

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.

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

101

11. Green line is to choose the point, Value at the point can be seen (Highlighted by circle at the left

corner).

LAB MANUAL| DIGITAL SIGNAL PROCESSING

Page

102

Lab No 15

Interfacing TMS320C6713 DSK with MATLAB