Sie sind auf Seite 1von 70

EL-302 DIGITAL SIGNAL PROCESSING

LAB MANUAL

DEPARTMENT OF ELECTRICAL
ENGINEERING,
FAST-NU, LAHORE
Lab manual of Digital Signal Processing

Created by: Mr. Khawaja Humble Hassan

Date: December, 2013

Last Updated by: Sara Kiran

Date: August, 2019

Approved by HOD:

Date:

1|Page
Lab manual of Digital Signal Processing

Table of Contents

Sr.
Description Page
No

1 List of Equipment 3

2 Experiment No. 1, Operations on Discrete Time Signals 4

Experiment No. 2, Introduction to TMS320C6713DSP Starter Kit (DSK)


3 9
Digital Signal Processing board

4 Experiment No. 3, Sampling 24

5 Experiment No. 4, Quantization and SNR 29

6 Experiment No. 5, Discrete Time Fourier Series and its Properties 31

7 Experiment No. 6, Discrete Time Fourier Transform and its Properties 34

Experiment No. 7,Linear and circular convolution on TMS320C6713 and


8 37
MATLAB

9 Experiment No. 8,Discrete Fourier Transform and its Properties 42

10 Experiment No. 9, Linear and Circular Convolution 45

11 Experiment No. 10, Fast Fourier Transform (FFT) and Z Transform 47

12 Experiment No. 11, Digital Filters 55

13 Experiment No. 12, Implementation of FIR Filters on TMS320C6713 58

14 Appendix A, Lab Evaluation Criteria 62

15 Appendix B, Safety around Electricity 63

16 Appendix C, Guidelines on Preparing Lab Report 66

2|Page
Lab manual of Digital Signal Processing

List of Equipment

Sr. No. Description

1 C6713 DSP Development Board

2 USB Cable

3 Universal Power Supply

4 AC Power Cord(s)

3|Page
Lab manual of Digital Signal Processing

EXPERIMENT 1

Various Operations on Discrete Time Signals

Objective

To learn how to add, subtract and multiply two vectors of different lengths, how to shift a signal
left or right by some factor along the horizontal axis and how to rotate your signal around a
fixed center point.

Software Tools

1. MATLAB R2016a

Exercise1: Signal Addition

To add two functions in MATLAB we simply use ‘+’ operator. To add two functions in
MATLAB the sequences must be of the same length. If the sequences are of unequal lengths
or if the sample positions are different then we cannot directly use the operator ‘+’. For the
signals of unequal length or different positions we first augment 𝑥1 (𝑛) and 𝑥2 (𝑛)with zeros so
that they have the same position vector n. Only then the sequences can be directly added.
Code to augment and add two signals of unequal length is shown in Figure 1.1 below:

Figure 1.1: Code to add signals of unequal length

4|Page
Lab manual of Digital Signal Processing

The output of the above code looks like the Figure 1.2 shown below:

Figure 1.2: Addition of two unequal length signals

1. Write the function in MATLAB. Briefly explain what you understand by the command
‘find’.

2. Let 𝑧1 (𝑛1 )= {0,3,2,1}, 𝑧2 (𝑛2 )= {1,2,3,0}, 𝑛1 ={1,2,3,4}, 𝑛2 ={-1,0,1,2). Plot 𝑧1 (𝑛1 ),


𝑧2 (𝑛2 ) and 𝑧1 (𝑛1 ) + 𝑧2 (𝑛2 ) on the same graph.(Hint: You will need to use command
‘subplot’)

Figure 1.3: (a) 𝑧1 (𝑛1 ) (b) 𝑧2 (𝑛2 ) (c) 𝑧1 (𝑛1 ) + 𝑧2 (𝑛2 )

5|Page
Lab manual of Digital Signal Processing

Exercise 2: Signal Multiplication

Similar restrictions apply for multiplication as for addition.

1. Using your understanding of the function ‘signal addition’ write a function for
multiplying two signals of unequal lengths.
2. Let 𝑧1 (𝑛1 )= {0,3,2,1} , 𝑧2 (𝑛2 ) = {1,2,3,0} , 𝑛1 ={1,2,3,4}, 𝑛2 = {-1,0,1,2}. Multiply
the two sequences 𝑧1 (𝑛1 ) and 𝑧2 (𝑛2 ).

Figure 1.4: (a) 𝑧1 (𝑛1 ) (b) 𝑧2 (𝑛2 ) (c) 𝑧1 (𝑛1 ) ∗ 𝑧2 (𝑛2 )

Exercise 3: Signal Shift

𝑥(𝑛 + 𝑁)Implies 𝑥(𝑛)is shifted to the left by N; 𝑥(𝑛 − 𝑁) implies 𝑥(𝑛) is shifted to the right
by 𝑁. The Figure 1.5 shows sequence 𝑥(𝑛) and its shifted version:

6|Page
Lab manual of Digital Signal Processing

Figure 1.5: (a) 𝑥(𝑛) (b) 𝑥(𝑛 − 𝑘)

1. Write a function that generates a shifted sequence.


2. By how much is 𝑥(𝑛) shifted in Figure 1.6?

Figure 1.6: (a) 𝑥(𝑛) (b) 𝑥(𝑛 − 𝑘)

7|Page
Lab manual of Digital Signal Processing

Exercise 4: Signal Flip

1. Use the MATLAB function fliplr to define 𝑥(−𝑛). Let𝑥(𝑛) = {1,2,5,8,3,2}, plot 𝑥(𝑛)
and 𝑥(−𝑛) on the same figure. Given 𝑥(0) = 5

Note: Since the fliplr function flips the terms of x about its center proper indexing is required
i.e. keep a check on n.

Exercise5:

Write a MATLAB code for the question below:

1. Let 𝑎(𝑛) = {1,2,3,4,5,6,7,6,5,4,3,2,1}. Determine and plot the following sequence.


Where 𝑎(0) = 7 and 𝑎(𝑛) = 3𝑎(𝑛) + 𝑎(𝑛 − 4)𝑎(𝑛)

Exercise 6:

Let 𝑥(𝑛) = {0,7,5,4,8,2,6,3,8,9,10}. Sum the samples of 𝑥(𝑛). Write a MATLAB code.
(Hint: You will need to use the command ‘sum’. Type sum in the help of MATLAB to understand
its use)

8|Page
Lab manual of Digital Signal Processing

EXPERIMENT 2

Introduction to Texas Instruments TMS320C6713 DSP


STARTER KIT (DSK) Digital Signal Processing Board

Objective

In this experiment you will become familiar with a development system for programming DSP
hardware in order to implement DSP operations.

You will study:

 Code Composer Studio


 TMS320C6713 DSP chip and supporting chip set (DSK) architecture
 The C programming language

Equipment

1. Software (Code Composer Studio)


2. C6713 DSP Development Board
3. USB Cable
4. Universal Power Supply
5. AC Power Cord(s)

1.1 Code Composer Studio

CCS consists of a set of software tools and libraries for developing DSP programs, compiling
and linking them into machine code, and writing them into memory on the DSP chip and on-
board external memory. It has graphical capabilities and supports real-time debugging. It
provides an easy-to-use software tool to build and debug programs.

It also contains diagnostic tools for analyzing and tracing algorithms as they are being
implemented on-board. In this lab we will always use the CCS to develop, compile, and link
the programs that are downloaded from the computer to DSP hardware.

1.2 TMS320 DSP Chips

In this lab we will be using C6713 which is a 225MHz processor having the ability to run 8 32-
bit parallel instructions in one 4.4ns instruction cycle, for the instruction rate of 1800
millioninstructions per second.

9|Page
Lab manual of Digital Signal Processing

The different families of TMS320 series are used for different applications. C2000 and C5000
series of chips are used in the portable devices because they consume very little power, and are
primarily used for the digital control. C2000 and C5000 series chips are used in 3G mobile
phones, GPS receivers, portable medical equipment and digital music players. The C6000
series of chips provides both fixed and floating point processors that are used in systems that
require high performance. These chips are not power efficient, so they are not used in the
portable devices instead they are used in the high quality digital audio applications, broadband
infrastructure and digital imaging.

1.3 DSP Starter Kit (DSK)

For the development of the programs in the TMS320 DSP chip we need a supporting
architecture that store the programs and data and bring signals on and off the board. In order to
use this DSP chip the Spectrum Digital, Inc, has manufactured a circuit board containing
appropriate components. The C6713 DSK allows you to download and step through code
quickly and uses Real Time Data Exchange (RTDX™) for improved Host and Target
communications. The full contents of the kit include:

 512K of non-volatile FLASH memory with 16MB of on-board SDRAM


 16-bit stereo codec
 Four 3.5-mm audio jacks
 Standard JTAG interface with 8-pin connector
 Plug-and-play JTAG support via USB
 Expansion port connectors for plug-in modules
 +5-volt universal power supply
 Three power cords (standard US, UK, & European)
 Code Composer Studio IDE, version 3.1
 Fast simulators enabling cache analysis and multi-event profiling
 Power Analyzer support
 MATLAB
 Support for third party daughter cards
 DSK quick start guide and technical reference

1.4 Programming Languages

Programming of the DSP chip is done in C using the Code Composer Studio (CCS) integrated
development environment. Assembly language was once the most commonly used
programming language for DSP chips and microprocessors because it enables the programmer
to manage the CPU core registers and schedule events in the CPU core. Assembly language is
most time consuming and is specific to the given architecture. Most of the programs created in
this course will be coded in C. In CCS, the C compiler has four optimization levels. The highest
level of optimization will not achieve the same level of optimization that programmer-
optimized assembly programs will, but Texas Instrument has done a good job in making the

10 | P a g e
Lab manual of Digital Signal Processing

optimized C compiler produce code that is comparable to programmer- optimized assembly


code.

1.5 Codec

A codec is a device capable of encoding or decoding a digital data stream or signal. It is a chip
located on-board DSK which interfaces with the analog world like signal generators and stereo
headphones. The codec contains a coder, or analog-to-digital converter (ADC), and a decoder
or digital-to-analog converter (DAC). Both coder and decoder run at sample rates which can
be set from 8 KHz to 96 KHz and support data word lengths of 16b, 20b, 24b, and 32b at the
digital interfaces.

1.6 C6713 DSP Chip

The C6713 DSP chip is a 225 MHz floating point processor that has a CPU, internal memory
(L1/L2 Memory Architecture), 1 32-bit external memory interface (EMIF), 2 32-bit general
purpose timers, 2 Multi-channel buffered serial ports McBSP, 2 McASP, Host port interface
(HPI), interrupt selector, Flexible phase lock loop (PLL) based block generator module along
with hardware for the Boot Configuration and Power Down Logic.

1.7 Timing

The DSP chip must be able to establish communication links between the CPU (DSP core), the
codec, and memory. The two McBSPs, serial port 0 (SP0) and serial port 1 (SP1), are used to
establish bidirectional asynchronous links between the CPU and the codec. SP0 is used to send
control data between the codec and CPU, SP1 plays a similar role for digital audio data.

1.8 Support Files

The following support files located in the folder support (except the library files) are used:

 C6713dskinit.c: contains functions to initialize the DSK, the codec, the serial
ports, and for I/O. It is not included with CCS.
 C6713dskinit.h: header files with function prototypes. Features such as those
used to select the mic input in lieu of line input (by default), input gain, and so
on are obtained from this header file (modified from a similar file included with
CCS).
 C6713dsk.cmd: sample linker command file. This generic file can be changed
when using external memory in lieu of internal memory.

11 | P a g e
Lab manual of Digital Signal Processing

 Vectors intr.asm: a modified version of a vector file included with CCS to


handle interrupts. Twelve interrupts, INT4 through INT15, are available, and
INT11 is selected within this vector file. They are used for interrupt-driven
programs.
 Vectors_poll.asm: vector file for programs using polling.
 rts6700.lib, dsk6713bsl.lib, csl6713.lib: run-time, board, and chip support
library files, respectively. These files are included in the CCS are located in
C6000\cgtools\lib, C6000\dsk6713\lib, and c6000\bios\lib, respectively
In this folder u:\DSP\Lab 07\ copy the file named led.c. Now you have support files and files
required to our first project.

2. Creating the First Project on the DSK

2.1 Creating the Project File Lab7.pjt

In CSS, select ‘Project’ and then ‘New’. A window named ‘Project Creation’ will appear. Fill
all the fields according to the figure given below. Finally, click on ‘Finish’. CCS has now
created a project file Lab7.pjt, which will be used to build an executable program. This file is
stored on your u:\ drive in the path

u:\DSP\lab07. See Figure 2.1 below.

Figure 2.1: Project creation window

2.2 Adding Support Files to a Project

The next step in creating a project is to add the appropriate support files to the file lab7.pjt. In
the CCS window, go to ‘Project’ and then ‘Add Files to Project . . .’. In the window that
appears, click on the folder next to where it says ‘Look In:’. Make sure that you are in the path
u:\DSP\Support. You should be able to see the file c6713dskinit.c. Notice that the ‘Files of
type’ field is ‘C source code’. Click on c6713dskinit.c and then click on ‘Open’. Repeat this

12 | P a g e
Lab manual of Digital Signal Processing

process two more times adding the files Vectors intr.asm and c6713dsk.cmd to the project file
lab7.pjt. For field, ‘Files of type’, select ‘Asm Source Files (*.a*)’. Click on Vectors intr.asm
and then click on ‘Open’. For field, ‘Files of type’, select ‘Linker Command File (*.cmd)’.
Click on c6713dsk.cmd and then click on ‘Open’. You have now charged your project file
u:\DSP\Lab 07\Lab7{lab7.pjt}.

The C source code file contains functions for initializing the DSP and peripherals. The Vectors
file contains information about what interrupts (if any) will be used and gives the linker 9
information about resetting the CPU. This file needs to appear in the first block of program
memory. The linker command file (c6713dsk.cmd) tells the linker how the vectors file and the
internal, external, and flash memory are to be organized in memory. In addition, it specifies
what parts of the program are to be stored in internal memory and what parts are to be stored
in the external memory. In general, the program instructions and local/global variables will be
stored in internal random access memory or IRAM.

2.3 Adding Appropriate Libraries to a Project

In addition to the support files that you have been given, there are pre-compiled files from TI
that need to be included with your project. For this project, we need run-time support libraries.
For the C6713 DSK, there are three support libraries needed: csl6713.lib, dsk6713bsl.lib, and
rts6700.lib. The first is a chip support library, the second a board support library, and the third
is a real-time support library. Besides the above support libraries, there is a GEL (general
extension language) file (dsk6211 6713.gel) used to initialize the DSK. The GEL file was
automatically added when the project file lab7.pjt was created, but the other libraries must be
explicitly included in the same manner as the previous files. Go to ‘Project’ and then ‘Add
Files to Project’. F or ‘Files of type’, select ‘Object and Library Files (*.o*,*.l*)’. Navigate to
the path u:\DSP\Support and select the files csl6713.lib,. .... In the left sub-window of the CCS
main window, double-click on the folder ’Libraries’ to make sure the file was added correctly.

These files, along with our other support files, form the black box that will be required for
every project created in this class. The only files that change are the source code files that code
a DSP algorithm and possibly a vectors file.

2.4 Adding Source Code Files to a Project

The last file that you need to add to led.pjt is your C source code file. This file will contain the
code that is needed to control the leds through the DIP switch. Go back to ‘Project’ and then
‘Add Files to Project . . .’, but this time browse to the path u:\DSP\Lab 07\. Click on the file
led.c and add it to your project by clicking on ‘Open’.

You may have noticed that the .h files cannot be added – there is no ’Files of type’ entry for .h
files. Instead, they are added in the following manner: go to ‘Project’ and select ‘Scan All

13 | P a g e
Lab manual of Digital Signal Processing

Dependencies’. In CCS, double-click on ‘led.pjt’ and then double-click on ‘Include’. You


should see any header files on an #include line in your source files (including c6713dskinit.c)
plus approximately 14 other header files found by the scan step. The latter files are supplied
with the Code Composer Studio software and are used to configure the DSP chip and board.
CCS automatically found and included all needed header files starting from the header files
included in the source files. Open c6713dskinit.c and observe that it includes c6713dskinit.h;
this header and dsk6713 aic23.h (included in led.c) include other header files which in turn
include others, leading to the list observed. Note that some include files are prefixed csl; these
are chip-support header files supplied by TI. The file dsk6713.h is a top level header file
supplied by the DSK board manufacturer, Spectrum Digital, Inc. The project file lab7.pjt has
now been charged with all of the files required to build the first executable .out file.

2.5 Build Options

The next objective is to customize the compiler and linker options so that the executable file
gets built correctly. Also, the compiler will first convert the C coded programs into DSP
assembly programs before it compiles them into machine code. By selecting the appropriate
options as shown in Figure 2.2 and 2.3, we can keep these intermediate assembly files.

Figure 2.2

14 | P a g e
Lab manual of Digital Signal Processing

Figure 2.3

3. Building and Running the Project

Now you must build and run the project. To build the first project, go to ‘Project’ pull down
menu in the CCS window, then select ‘Build’ (or press the button with three red down arrows
on the top toolbar in the CCS window). A new sub-window will appear on the bottom of the
CCS window. When building is complete, you should see the following message in the new
sub-window:

 Build Complete,
 0 Errors, 2 Warnings, 0 Remarks.

When CCS “built” your project, it compiled the C coded source files and header files into
assembly code, using a built-in compiler. Then it assembled the assembly code into a COFF
(common object file format) file that contains the program instructions, organized into
modules. Finally, the linker organized these modules and the run-time support library
(rts6701.lib) into memory locations to create the executable .out file led.out. The executable
file, led.out, may be downloaded onto the DSK. When led.out is loaded onto the DSK, the

15 | P a g e
Lab manual of Digital Signal Processing

assembled program instructions, global variables, and runtime support libraries are loaded to
their linker-specified memory locations.

The following steps builds and runs the LED project on our DSP board.

In order to test the program led.out on the DSK (DSP starter kit), it must first be loaded onto
the DSP board. Before a new program is loaded onto the board, it is good practice to reset the
CPU. To reset the CPU, click on the ‘Debug’ pull-down menu and select ‘Reset CPU’.

STEPS:

1. First of all, run the 6713DSK Diagnostics to check the diagnostic status of DSP Board.
2. Then start CCS_v3.1 code composer studio software. Click on the ‘Project’ pull down
menu and selectOpenProject from where you select led.pjt.Thisled.pjt project now
appears under the projects heading on the left-hand side.
3. After that you create your led.c source file which has the relevant C code for running
your LEDs project. (File > New > Source)
4. Then you build your led.c Program to check for any errors and warning and for creating
the led.out file which will be stored in Debug folder.
5. Then you load your program led.out file onto the DSP starter kit. (File > Load Program)
and then build your Program to recheck for any errors or warnings. This will download
the executable file led.out onto the DSK.
6. In the end, you run your led.pjt project by pressing the F5 key or ‘running man’ icon
on the left-hand side toolbarto show the result of your program on DSP board.
7. Verify by pressing down the DIP switch # 3 that which led turns ON. After you have
completed this task, go to the ‘Debug’pull down menu to select ‘Halt’ to stop the
execution of the program.

Exercise 1:

Task on LEDs operation on DSP Board:

In this Lab, we will study the blinking sequence of LEDs on DSP Board by running the
project led.pjt which shows the sequence of LEDs operation.

This task blinks LED #0 at a rate of about 2 times per second using the LED module of the
DSK6713 Board Support Library (bsl). The example also reads the state of DIP switch #3
and lights LED #3 if the switch is depressed or turns it off if the switch is not depressed.

The Board Support Library is divided into several modules, each of which has its own
include file. The file dsk6713.h must be included in every program that uses the BSL.

This task also includes dsk6713_led.h and dsk6713_dip.h because it uses the LED and DIP
switches modules.

16 | P a g e
Lab manual of Digital Signal Processing

#include "dsk6713.h"

#include "dsk6713_led.h"

#include "dsk6713_dip.h"

void main()

/* Initialize the board support library, must be first BSL call */

DSK6713_init();

/* Initialize the LED and DIP switch modules of the BSL */

DSK6713_LED_init();

DSK6713_DIP_init();

while(1)

/* Toggle LED #0 */

DSK6713_LED_toggle(0);

/* Check DIP switch #3 and light LED #3 accordingly, 0 = switch pressed */

if (DSK6713_DIP_get(3) == 0)

/* Switch pressed, turn LED #3 on */

DSK6713_LED_on(3);

else

/* Switch not pressed, turn LED #3 off */

DSK6713_LED_off(3);

DSK6713_waitusec(200000);/* Spin in a software delay loop for about 200ms */

The steps to perform the LED blinking sequence on DSP Board are shown pictorially
below:

17 | P a g e
Lab manual of Digital Signal Processing

1. Run the 6713DSK diagnostics as shown in Figure 2.4 to check the diagnostic status of
DSP Board.

Figure 2.4

2. Load the project led.pjt as shown in Figure 2.5 by going on Project > Open.

18 | P a g e
Lab manual of Digital Signal Processing

Figure 2.5: Loading the project led.pjt

3. Load the source file led.c by going on File> Source. See Figure 2.6.

Figure 2.6: Loading the source file led.c

19 | P a g e
Lab manual of Digital Signal Processing

4. Compile your File (led.c project) as shown in Figure 2.7 to check for any errors or
warnings.

Figure 2.7: Compiling led.c file

5. Load Program led.out on the DSP Board as shown in Figure 2.8.

Figure 2.8: Loading program led.out

20 | P a g e
Lab manual of Digital Signal Processing

6. Then, build your project as shown in Figure 2.9.

Figure 2.9

7. In the end, run your project (See Figure 2.10) and observe the blinking sequence of LEDs.

Figure 2.10

21 | P a g e
Lab manual of Digital Signal Processing

The Figure 2.11 and Figure 2.12 below show the LED blinking sequence. First, LED 1 blinks
and then LED 3 lights up if DIP switch 3 is depressed.

Figure 2.11

Figure 2.12

Exercise 2:

Write a C code that performs the following operation on LEDs on DSP Board:

1. LED # 2 toggles (blinks) for the first 30 seconds. Then, the DSP Board monitors the
state of DIP switches on DSP Board.

22 | P a g e
Lab manual of Digital Signal Processing

If Switch # 1 is ON and Switch # 3 is OFF, it will turn LED # 1 and LED # 2 ON,
otherwise all LEDs will be in OFF state.

2. The following LEDs turn ON for 5 seconds in the following sequence 3, 2, 1 (LED #
3 turns ON for 5secs and then turns OFF, then LED # 2 turns ON for 5 secs and then
turns OFF, then LED # 1 turns ON for 5secs and then turns OFF).

After that LED # 0 blinks for 15 secs and then this loop or sequence is repeated.

Post-Lab Question:

Write a report on TMS320C6713 DSP board.

What are the important peripherals and important features of this board and what are the
applications it can be used in, so the main points to focus in the report are:

I. TMS320C6713 DSP board main components

II. Features

III. Importance

IV. Applications

V. Latest TMS320C6XXX board available

23 | P a g e
Lab manual of Digital Signal Processing

EXPERIMENT 3

Sampling

Objective

The objective of this lab is to study the sampling of continuous-time signals to get discrete-
time signals and the effect of aliasing caused by reconstruction of discrete-time signals when
sampling frequency is below the Nyquist rate.

Software Tools

1. MATLAB R2016a

SAMPLING:

In many applications analog signals are converted into discrete signals using sampling and
quantization operations (collectively called analog to digital conversion or ADC).

These discrete signals are processed using digital signal processors and then the processed
signals are converted into analog signals using a reconstruction operation.

The analog signal can be sampled by multiplying it with a train of equidistance impulses.

Let 𝑥𝑎 (𝑡) be an analog signal, we now sample it at 𝑇𝑠 seconds to obtain discrete time signal
𝑥(𝑛).

𝑥(𝑛) = 𝑥𝑎 (𝑛𝑇𝑠 )

Exercise1:
Consider the analog signal given below

𝑥(𝑡) = 3 cos(2,000π) 𝑡 + 5 sin(6,000π) 𝑡 + 10 cos(12,000π) t

𝑥1 (𝑡) = 3 cos(2,000π) 𝑡

𝑥2 (𝑡) = 5 sin(6,000π) 𝑡

𝑥3 (𝑡) = 10 cos(12,000π) 𝑡
Where,𝑠𝑡𝑒𝑝 𝑠𝑖𝑧𝑒 = 1; 𝐹𝑠 = 12000 𝑠𝑎𝑚𝑝𝑙𝑒𝑠/𝑠𝑒𝑐 and0 ≤ 𝑛 ≤ 12

a. Write code in MATLAB to plot the figures of 𝑥1 (𝑡), 𝑥2 (𝑡), 𝑥3 (𝑡) and 𝑥(𝑡).

b. Write code in MATLAB to plot the figures of 𝑥1 (𝑛), 𝑥2 (𝑛), 𝑥3 (𝑛) and 𝑥(𝑛).

24 | P a g e
Lab manual of Digital Signal Processing

Use subplot commands.

Exercise2:
𝑥1 (𝑡) = cos(2π10)t

𝑥2 (𝑡) = 2𝑐os(2π50)𝑡

where, step size is 𝐷𝑡 = 10𝑚𝑠𝑒𝑐, 0 ≤ 𝑡 ≤ 1𝑠𝑒𝑐

1. Write code in MATLAB to plot the figure of 𝑥1 (𝑡)and 𝑥2 (𝑡).


2. Sample the signal 𝑥1 (𝑡)and 𝑥2 (𝑡) and plot 𝑥1 (𝑛)and 𝑥2 (𝑛) on MATLAB. Sampling
frequency is 𝐹𝑠 =40 samples /sec and the range of n is given as:
0 ≤ 𝑛 ≤ 15

RECONSTRUCTION OF SIGNALS:

If we sample a band-limited signal above its Nyquist Rate, then we can reconstruct that signal
from its samples.
First the samples are converted into weighted impulse train.
Then the impulse train is filtered through an ideal analog low pass filter.
This two step procedure can be described using the reconstruction formula given by:
𝒏=∞

𝒙𝒂 (𝒕) = ∑ 𝒙(𝒏)𝒔𝒊𝒏𝒄[𝑭𝒔(𝒕 − 𝒏𝑻𝒔 )]


𝒏=−∞

Where:

𝑥𝑎 (𝑡) is an analog signal sampled at sampling interval Ts

x(n) is discrete-time signal

Fs is the sampling frequency

Dt is the step size


sin 𝜋𝑥
and 𝑠𝑖𝑛𝑐(𝑥) = 𝜋𝑥

function [t,x]=reconst(xn,n,Fs,Dt)
%Fs is the frequency at which the analog signal is sampled
%xn is the sampled signal and n are the indices
%Dt is the step size for time interval of analog signal
Ts=1/Fs;
t=min(n)*Ts:Dt:max(n)*Ts;
nTs=n*Ts;
x=xn*sinc(Fs*(ones(length(n),1)*t-nTs'*ones(1,length(t))));

25 | P a g e
Lab manual of Digital Signal Processing

3. Reconstruct the signal x1 (t) and x2 (t) from its samples x1 (n) and x2 (n) generated
above and also find the error in estimation.
Plot the original signal, analog signal and the reconstructed signals side by side. Use
sampling frequency of Fs = 40 𝑠𝑎𝑚𝑝𝑙𝑒𝑠/𝑠𝑒𝑐𝑜𝑛𝑑. Where step size is 𝐷𝑡 = 10 msec
and 0 ≤ t ≤ 1sec

4. Are the two signals obtained after reconstruction the same as their original ones? If not
why ?

5. Are the two signals obtained after reconstruction is same to each other? If yes then
why?

6. According to sampling theorem what sampling frequency must be used to avoid the
problem of aliasing? Calculate 𝐹𝑠 .

7. Use the calculated Fs to sample

x1 (t) = cos(2π10)t

x2 (t) = 2cos(2π50)t

Write code in MATLAB and plot the figures of x1 (n) and x2 (n)

Where step size= 1. 0 ≤ n ≤ 15


Reconstruct the signal 𝑥1 (𝑡) and 𝑥2 (𝑡) using the calculated sampling frequency 𝐹𝑠 .
Plot the original signal, analog signal and the reconstructed signal side by side
Where step size is 𝐷𝑡 = 10𝑚𝑠𝑒𝑐. 0 ≤ 𝑡 ≤ 1𝑠𝑒𝑐

8. Are the two signals obtained after reconstruction the same as the original ones?

26 | P a g e
Lab manual of Digital Signal Processing

DOWN-SAMPLING

Down-sampling is easy in MATLAB. Simply, do not index the sample that must be deleted so
that some of the samples are omitted the original signal sequence.

For example, given a vector 𝒙 of integers from 1 to 9, we can down-sample the vector by a
factor of 2 (preserving every other sample) to obtain all odd numbers from 1 to 9.

x = [1 2 3 4 5 6 7 8 9 0];

x=1 2 3 4 5 6 7 8 9

x(1:2:length(x))

>>ans = 1 3 5 7 9

Exercise 3:

Using the above example and the sinc function, implement a code in MATLAB to obtain the
plot shown below in Figure 3.1(b).
(Note that the horizontal axis ranges from 𝟎 𝒕𝒐 𝟐𝝅, in step size of 0.1).

0.5

-0.5
0 1 2 3 4 5 6 7

0.5

-0.5
0 1 2 3 4 5 6 7
Figure 3.1: (a)𝒙(𝒏) (b) down-sampled 𝒙(𝒏)

27 | P a g e
Lab manual of Digital Signal Processing

Post Lab Questions:

Question 1:

Let us consider two continuous-time signals:

𝑥(𝑡) = cos(2𝜋𝐹𝑜 𝑡) 𝑤𝑖𝑡ℎ 𝐹𝑜 = 350𝐻𝑧

and

𝑦(𝑡) = cos(2𝜋𝐹1 𝑡) 𝑤𝑖𝑡ℎ 𝐹1 = 1150𝐻𝑧

Both sampled at same frequency of 𝐹𝑠 = 800 𝐻𝑧.

Write a MATLAB code to generate 𝑥(𝑡) and 𝑦(𝑡) and its samples as shown in the figure
above.
Will the two signals obtained after reconstruction be the same as the original ones?

28 | P a g e
Lab manual of Digital Signal Processing

EXPERIMENT 4

Quantization and SNR

Objectives

Study of sampling, quantization and effect on SNR by decreasing the number of levels

Software Tools

1. MATLAB R2016a

Quantization

Quantization makes the range of a signal discrete, so that the quantized signal takes on only a
discrete and finite set of values. Quantization is generally irreversible and results in loss of
information. It therefore introduces distortion into the quantized signal that cannot be
eliminated.

Question-1

 Read and plot the audio signal (audio.wav), using audioread() command. For reading
use FS (sampling frequency)of 16000Hz.
 Find the unknowns for writing the code
o Number of samples contained in the audio.wav file.
o Number of bits used to encode these samples
o Default sampling rate of audio files in MATLAB

 Write a MATLAB code to induce quantization noise in audio.wav by reducing the


number of levels(i-e by reducing the number of bits)
 Using MATLAB, generate the plots of audio.wav file for different values of b.
Where b is the number of bits.

 Investigate and research about Quantization noise and explain its effect on the audio
signal using the output of above code.

Post Lab
Using the code given below calculate SNR of audio signal for different values of b(number of
bits) and maintain a table as Table-1:
/**MATLAB code for calculating SNR**/

max = 0;

for m = 1:1:2*Fs

29 | P a g e
Lab manual of Digital Signal Processing

if max<y(m)

max = y(m);

end

energy = sum(y.*y);

B = 16;

P = energy/(2*Fs);

a = 9264;

SNR = 6.02*B + 10.81 -20*log(a) + 20*log(sqrt(P));

Plot (SNR)

Table-1

Number of bits Voice Quality SNR(dB)


16 Excellent 23.34
15 No perceptual difference 17.34
14 No perceptual difference 11.34
13 Minor noise is present 5.34
12 Minor noise is present -0.34
11 Quiet noisy -6.34
10 Quiet noisy -12.34
9 Quiet noisy -18.34
8 Quiet noisy -24.34
7 Poor Quality -30.34
6 Poor Quality -36.34
5 Poor Quality -42.34
4 Poor Quality -48.34
3 Poor Quality -54.34
2 Poor Quality -60.34
1 Poor Quality -66.34

30 | P a g e
Lab manual of Digital Signal Processing

EXPERIMENT 5

Discrete Time Fourier Series and its Properties

Objective

In this experiment you will study how to decompose a periodic signal into a sum of sinusoidal
signal components and obtain a pictorial representation for the frequency components that are
contained in the signal.

Software Tools

1. MATLAB R2016a

Introduction

This discrete-time Fourier series representation provides notions of frequency content of


discrete time signals, and it is very convenient for calculations involving linear, time-invariant
systems.

For a signal 𝒙(𝒏) with fundamental period N, the DTFS equations are given by:
𝑁−1

𝑥(𝑛) = ∑ 𝑎𝑘 𝑒 𝑗𝑘(2𝜋/𝑁)𝑛
𝑘=0

𝑁−1
1
𝑎𝑘 = ∑ 𝑥(𝑛)𝑒 −𝑗𝑘(2𝜋/𝑁)𝑛
𝑁
𝑛=0

Exercise 1:

Write a function to compute the discrete time Fourier series as described below

function y = DTFS(x, N)

where,
𝒙 − 𝒊𝒏𝒑𝒖𝒕 𝒗𝒆𝒄𝒕𝒐𝒓
𝑵 − 𝑭𝒖𝒏𝒅𝒂𝒎𝒆𝒏𝒕𝒂𝒍 𝒑𝒆𝒓𝒊𝒐𝒅

Exercise 2:

Given 𝒙(𝒏)={3,2,1,0,3,2,1,0,3,2,1,0……}, 𝑵 = 𝟒

Find DTFS and sketch its spectrum (magnitude and phase).


Find power by Parseval’s theorem, make a function for Parseval’s theorem as described below:

31 | P a g e
Lab manual of Digital Signal Processing

function [pow_xn, pow_Ck] = parsevals(xn,Ck)

where,
𝒙𝒏 − 𝒊𝒏𝒑𝒖𝒕 𝒗𝒆𝒄𝒕𝒐𝒓 𝒊𝒏 𝒕𝒊𝒎𝒆 𝒅𝒐𝒎𝒂𝒊𝒏
𝑪𝒌 − 𝑭𝒐𝒖𝒓𝒊𝒆𝒓 𝒄𝒐𝒆𝒇𝒇𝒊𝒄𝒊𝒆𝒏𝒕𝒔

Exercise 3:

Write a function of IDTFS ( ) as described below:

function y = IDTFS(Ck, N)

where,
𝑪𝒌 − 𝑭𝒐𝒖𝒓𝒊𝒆𝒓 𝒄𝒐𝒆𝒇𝒇𝒊𝒄𝒊𝒆𝒏𝒕𝒔
𝑵 − 𝑭𝒖𝒏𝒅𝒂𝒎𝒆𝒏𝒕𝒂𝒍 𝒑𝒆𝒓𝒊𝒐𝒅 𝒐𝒇 𝒓𝒆𝒑𝒆𝒕𝒊𝒕𝒊𝒐𝒏

Exercise 4:

Make 𝒙(𝒏) = {“your roll no” }


e.g if your roll no is 4455 than your 𝒙(𝒏)= [4 4 5 5] with N=4
Find:
I. DTFS
II. Sketch spectrum (magnitude and phase)
III. Find power using Parseval’s theorem

Exercise 5:

Given that 𝒙(𝒏) = [1 1 1 0 0]


Find:
I. DTFS
II. Sketch spectrum (magnitude and phase)
III. Find power using Parseval’s theorem
IV. Also find inverse discrete time Fourier series to get x(n)

PROPERTIES OF DISCRETE TIME FOURIER SERIES

Exercise 6:

Linearity property

Prove the following linearity property using:

𝑥(𝑛) = [1 1 1 0] 𝑎𝑛𝑑 𝑦(𝑛) = [2 1 2 4]

32 | P a g e
Lab manual of Digital Signal Processing

A=2 and B=3

𝐴𝑥(𝑛) + 𝐵𝑦(𝑛) → 𝐴𝑋(𝑘) + 𝐵𝑌(𝑘)

HINT (For this question you have to once find DTFS of ‘𝐴𝑥(𝑛) + 𝐵𝑦(𝑛)’ and plot it and then
find the DTFS of 𝑥(𝑛) and 𝑦(𝑛) separately and multiply them with A and B respectively. Plot
the results)

Exercise 7:
Time Shifting property

Prove the following property for:

𝑥(𝑛)=[3 2 1 0]

𝑥(𝑛 − 𝑛0 ) → 𝑋(𝑘). 𝑒 −2𝜋𝑗𝑘(𝑛0 /𝑁)

HINT (For this question you have to once find DTFS of ‘𝑥(𝑛 − 𝑛0 )’ and plot it and then find
the DTFS of 𝑥(𝑛) and multiply it with 𝑒 −2𝜋𝑗𝑘(𝑛0 /𝑁) . Plot the results)

Exercise 8:
Frequency Shifting property

Prove the following property for:

𝑥(𝑛)=[3 2 1 0]

𝑥(𝑛)𝑒 2𝜋𝑗𝑘(𝑛0 /𝑁) → 𝑋(𝑘 − 𝑘0 )

HINT (For this question you have to once find DTFS of 𝑥(𝑛) 𝑒 2𝜋𝑗𝑘(𝑛0 /𝑁) and plot it and then
find the DTFS of 𝑥(𝑛) and shift it 𝑘0 units and plot the result)

Post Lab Question:

Frequency Shifting property


Prove the following property for:

𝑥(𝑛)=[3 2 1 0]

𝑥(𝑛)𝑒 2𝜋𝑗𝑘(𝑛0 /𝑁) → 𝑋(𝑘 − 𝑘0 )

33 | P a g e
Lab manual of Digital Signal Processing

EXPERIMENT 6

Discrete Time Fourier Transform and its Properties

Objective

In this experiment you will study how to transform a signal into frequency domain and after
decomposition how to get the signal back in time domain. Further on you will also observe
how the spectrum of DTFT differs from that of DTFS.

If 𝒙(𝒏) is absolutely sum-able then its discrete time Fourier transform (DTFT) is given by
𝑿(𝝎) = ∑ 𝒙(𝒏). 𝒆−𝒋𝝎𝒏

Software Tools

1. MATLAB R2016a

MATLAB Implementation

If 𝑥(𝑛) is of infinite duration then MATLAB cannot be used to directly compute 𝑋(𝑒 𝑗𝜔 ) for
𝑥(𝑛). We can use MATLAB to evaluate its expression over the given duration. However, if
𝑥(𝑛) is of finite duration then the above equation can be used to compute 𝑋(𝑒 𝑗𝜔 ). It can be
implemented as a matrix-vector multiplication operation. Let us assume the sequence has M
𝜋
equally spaced samples and we want to evaluate 𝑋(𝑒 𝑗𝜔 ) at 𝜔 = 𝑀 𝑘, 𝑘 = 0,1,2, … , 𝑀. We can
easily obtain a linear algebraic representation of the Fourier transform function
𝑋(𝑤) = ∑ 𝑥(𝑛)𝑒 −𝑗𝜔𝑛 .

Let 𝑥(𝑛) be a sequence of length 𝑁 and ω be a sequence of length M. Algebraically Y = xW,


where x is a row vector representing the discrete-time signal 𝑥(𝑛), Y is a row vector
representing the Fourier transform function 𝑋(𝑒 𝑗𝜔 ) and W is a matrix representing the complex
exponential harmonic 𝑒 −𝑗𝜔𝑛 . The size of x is 1 × 𝑁 (one row and N columns).

Exercise 1:

Define a function to estimate the discrete-time Fourier transform of a signal.

function y = DTFT(x, n, w)

Exercise 2:

Write the MATLAB expression for W (W = exp(-j*n’*ω)); in terms of the vectors n and w.
What will be the size of W?

34 | P a g e
Lab manual of Digital Signal Processing

Exercise 3:

Let 𝑥(𝑛) = {1 2 3 4} for 𝑛 = [0 1 2 3]. Find 𝑋(𝜔):


ω = 0 : 0.01/pi : 2*pi;
Use subplot to plot the magnitude (use the function abs) and phase (use the function angle) of
the function 𝑋(𝜔).

Exercise 4:

Generate a sinc pulse (Assume 𝑓 = 1/8 and 𝑛 = −40: 40)


I. Find its DTFT ( Assume ω = -pi: pi, dω = 0.001/pi)
II. Then reconstruct the original signal using the formula:

𝟏 +𝝅
𝒙[𝒏] = ∫ 𝑿(𝒆𝒋𝝎 )𝒆𝒋𝝎𝒏 𝒅𝝎
𝟐𝝅 −𝝅

PROPERTIES OF DTFT:

Exercise 5: Linearity

Let 𝑥1 (𝑛) and 𝑥2 (𝑛) be two random sequences of size 11. Let 𝑛=[0:10] and 𝜔=[0:500]*pi/500,
𝛼 = 3, 𝛽 = 2. First take individual DTFT of x1 and x2 and plot their sum (𝛼𝑋1 (𝜔) +
𝛽𝑋2 (𝜔)). Then add 𝛼𝑥1 (𝑛)and 𝛽𝑥2 (𝑛), take their DTFT and plot it. Your plots should be on
the same figure.
Write a code on MATLAB. Also use the DTFT function defined previously.

Exercise 6: Parseval’s Theorem

𝟏 𝟐𝝅
𝟐 𝟐
𝑬 = ∑|𝒙(𝒏)| = ∫ |𝑿(𝒆𝒋𝝎 )| 𝒅𝝎 , −∞ < 𝑛 < +∞
𝟐𝝅 𝟎

𝜔 = 0:pi/100:2*pi;

𝑥 = [1 1 1]; 𝑛=[-1:1];
Write a script that separately uses the signal and its Fourier transform (i.e. the left- and right-
hand sides of the above equation) to estimate energy E of a signal 𝑥(𝑛). Use the trapz function
to estimate the integral.

Exercise 7: Time shifting


Prove the following theorem given that the Fourier transform of 𝑥(𝑛) is 𝑋(𝑒 𝑗𝑤 )
i.e. 𝑥(𝑛)<->𝑋(𝑒 𝑗𝜔 ).

𝒙(𝒏 − 𝒅) → 𝒆−𝒋𝝎𝒅 𝑿(𝒆𝒋𝝎 )

35 | P a g e
Lab manual of Digital Signal Processing

Plot the signal 𝑥(𝑛) shown in Figure 6.1 and its shifted version, shifted by -4 .Their magnitude
and phase spectra.

Figure 6.1: Unshifted and shifted signals

Post Lab Question:

Conjugation property of DTFT

𝑥 = [1/3, 1/3, 1/3 ] , 𝑛 = [ 0 1 2 ] , 𝜔 = -pi : pi/100 : pi

Prove the conjugation property given below:

𝒙∗ (𝒏) → 𝑿∗ (−𝝎)

36 | P a g e
Lab manual of Digital Signal Processing

EXPERIMENT 7

Linear and Circular Convolution on TMS320C6713 and


MATLAB

Objective

To study the effects of convolution and correlation of two discrete-time signals and observe
the difference between the two. Moreover, you will implement the linear and circular
convolution using code composer studio on TMS320C6713 and MATLAB.

Equipment

1. Software (MATLAB R2016a, Code composer Studio)


2. C6713 DSP Development Board
3. USB Cable
4. Universal Power Supply
5. AC Power Cord(s)

 Part 1: Implementation on MATLAB

Convolution is a mathematical way of combining two signals to form a third signal. The
definition of convolution in discrete time domain is given by:
𝒌=+∞

𝒚[𝒏] = 𝒙[𝒏] ∗ 𝒉[𝒏] = ∑ 𝒙[𝒌] . 𝒉[𝒏 − 𝒌]


𝒌=−∞

Exercise 1:

Write a generic function for the convolution of two sequences which takes the sequences and
their indices as input and plots the convolved sequence.

function [y,n]=(x1,x2,n1,n2)

Exercise 2:

Prove the convolution property stated below:

𝒚(𝒏) = 𝒙(𝒏) ∗ 𝒉(𝒏) → 𝒀(𝒆𝒋𝝎 ) = 𝑿(𝒆𝒋𝝎 ) . 𝑯(𝒆𝒋𝝎 )

Convolution operation can also be implemented using Fourier domain multiplication and the
inverse transform afterwards. In fact, this property makes analysis of LTI systems easier in
Fourier domain than in time domain.
37 | P a g e
Lab manual of Digital Signal Processing

Show, by plotting the spectra 𝑌(𝑒 𝑗𝜔 ) and 𝐻(𝑒 𝑗𝜔 ).* 𝑋(𝑒 𝑗𝜔 ), that these spectra, obtained from
the signals 𝒚(𝒏) = 𝒄𝒐𝒏𝒗(𝒙(𝒏), 𝒙(𝒏)) and 𝑥(𝑛)=[1 1 1] for 𝑛 = [0 1 2] are the same.

Correlation:

The correlation between the sequences is given by:


𝒏=+∞

𝒓𝒙𝒚 (𝒍) = ∑ 𝒙(𝒏)𝒚(𝒏 − 𝒍), 𝒍 = 𝟎, ±𝟏, ±𝟐, ±𝟑, … . .


𝒏=−∞

𝒏=+∞

𝒓𝒙𝒚 (𝒍) = ∑ 𝒙(𝒏 − 𝒍)𝒚(𝒏), 𝒍 = 𝟎, ±𝟏, ±𝟐, ±𝟑, … . .


𝒏=−∞

Similarly, the auto-correlation is given by


𝒏=+∞

𝒓𝒙𝒙 (𝒍) = ∑ 𝒙(𝒏)𝒙(𝒏 − 𝒍) = 𝒓𝒙𝒙 (−𝒍) 𝒍 = 𝟎, ±𝟏, ±𝟐, ±𝟑, …


𝒏=−∞

Exercise 3:

Write a MATLAB code to find the auto-correlation of the sequence 𝑥(𝑛) = [1 2 3 4]

I. Plot the original and correlated sequence.


II. Prove the property that |𝑟𝑥𝑥 (𝑙)| ≤ 𝑟𝑥𝑥 (0) = 𝐸𝑥
III. Check if the auto-correlated sequence is 𝑟𝑥𝑥 (𝑙) an even function or not

Hint: (Use “xcorr()” function in MATLAB for the correlation)

Exercise 4:

Write a MATLAB code to find the cross-correlation of the sequences 𝑥1 (𝑛) = [1 2 3 4] and
𝑥2 (𝑛) = [4 3 2 1]

I. Plot the original and correlated sequence.


II. Prove the property that 𝑟𝑥𝑦 (𝑙) = 𝑟𝑦𝑥 (−𝑙)
III. Also show that the maximum value in cross-correlated sequence is than 𝑠𝑞𝑟𝑡 (𝐸𝑋 𝐸𝑌 )
that is

|𝑟𝑥𝑦 (𝑙)| ≤ √𝑟𝑥𝑥 (0)𝑟𝑦𝑦 (0) = √𝐸𝑥 𝐸𝑦

38 | P a g e
Lab manual of Digital Signal Processing

 Part 2: Implementation on TMS320C6713

Convolution is important because it relates the three signals of interest: the input signal, the
output signal, and the impulse response.

Procedure

 Open code composer studio and select C6713 as simulator.


 Make a new project using ‘Project→New pull down menu and save it in a
separate directory with file name linearconv.pjt.
 Create a new source file named as “linear.c” using File→New→Sourcefile and
save it to the project folder.
 Add source file to the project using Project→Add files to the project→linear.c
menu.
 Add the linker command file hello.cmd.
 (path: C:\CCstudio\tutorial\dsk6713\hello\hello.cmd)
 Add the run time support library file rts6700.lib
 (path: C\CCStudio\cgtools\lib\rts6700.lib)
 Compile the program using project →Compile menu or by Ctrl+F7
 Build the program using project→ Build menu or by F7
 Load the linear.out file (from project folder linearconv\Debug) using File
→Load Program
 Run the program using Debug→ Run or F5
 To view the output graphically
 Select View→ Graph→ Time and Frequency
 Repeat the steps 2 to 11 for circular convolution

Program:

Linear Convolution

#include<stdio.h>
#define LENGTH1 6
#define LENGTH2 4

int x[LENGTH1+LENGTH2-1]={4,3,2,1,5,6,0,0,0};
int h[LENGTH1+LENGTH2-1]={1,2,1,4,0,0,0,0,0};
int y[LENGTH1+LENGTH2-1];
main()
{
inti=0,j;
for(i=0;i<LENGTH1 + LENGTH2-1;i++)
{
y[i]=0;

39 | P a g e
Lab manual of Digital Signal Processing

for(j=0;j<=i;j++)
y[i]+=x[j]*h[i-j];
}
for(i=0;i<LENGTH1 + LENGTH2-1;i++)
printf("%d\n",y[i]);
}

RESULT
The convoluted sequence is obtained as
4 11 12 24 21 25 21 26 24

Circular convolution

#include<stdio.h>
intm,n,x[30],h[30],y[30],i,j,temp[30],k,x2[30],a[30];
void main()
{
printf("Enter the length of 1st sequence\n");
scanf("%d",&m);
printf("Enter the length of 2nd sequence\n");
scanf("%d",&n);
printf("Enter the 1st sequence\n");
for(i=0;i<m;i++)
scanf("%d",&x[i]);
printf("Enter the 2nd sequence\n");
for(j=0;j<n;j++)
scanf("%d",&h[j]);
if(m-n!=0)
{
if(m>n)
{
for(i=n;i<m;i++)
h(i)=0;
n=m;
}
for(i=m;i<n;i++)
x[i]=0;
m=n;
}
y[0]=0;
a[0]=h[0];
for(j=1;j<n;j++)
a[j]=h[n-j];
for(i=0;i<n;i++)
y[0]+=x[i]*a[i];
for(k=1;k<n;k++)
{

40 | P a g e
Lab manual of Digital Signal Processing

y[k]=0;
for(j=1;j<n;j++)
x2[j]=a[j-1];
x2[0]=a[n-1];
for(i=0;i<n;i++)
{
a[i]=x2[i];
y[k]+=x[i]*x2[i];
}
}
printf("The circular convolution is \n");
for(i=0;i<n;i++)
printf("%d\t",y[i]);
}

RESULT
Enter the length of 1st sequence 4
Enter the length of 2nd sequence 4
Enter the 1st sequence 1 2 3 1
Enter the 2nd sequence 4 3 2 2
The circular convolution is 17 19 22 19

Exercise 1:

Modify the code for circular convolution to give correct results even if the length of the two
sequences is different such that you need to enter the length of both the sequences.

Post Lab Question:

Write a code in MATLAB for performing the convolution of two signals. You are not allowed
to use any built in function for performing the convolution.

41 | P a g e
Lab manual of Digital Signal Processing

EXPERIMENT 8

Discrete Fourier Transform and its Properties

Objective

To learn how to compute the discrete Fourier transform, inverse discrete Fourier transform and
circular convolution using MATLAB. Moreover, to study the effect of increasing the number
of samples on the resultant signal and to understand the subtle details in the relationship
between DTFT and DFT.

Software Tools

1. MATLAB R2016a

Introduction

The discrete Fourier transform is defined as:

𝑿(𝒌) = ∑ 𝒙(𝒏). 𝒆−𝒋𝟐𝝅𝒌(𝒏/𝑵) , 𝒌 = 𝟎: 𝑵 − 𝟏; 𝒏 = 𝟎: 𝑵 − 𝟏


𝒏

𝑋(𝑘) is obtained by sampling the DTFT i.e 𝑋(𝜔) after every 2𝜋/𝑁 interval.

The inverse of the DFT is IDFT which is defined as:

𝟏
𝒙(𝒏) = ∑ 𝑿(𝒌). 𝒆𝒋𝟐𝝅𝒌(𝒏/𝑵) , 𝒌 = 𝟎: 𝑵 − 𝟏; 𝒏 = 𝟎: 𝑵 − 𝟏
𝑵
𝒌

Exercise 1:

Make a function of DFT in which you have to implement the formula of DFT. Pass 𝑥(𝑛) and
𝑛 as parameters to the function and the function should return the values of 𝑋(𝑘).

(Hint: Use the vector multiplication method to implement this function. Do not use loops.)

Exercise 2:

Make a function of IDFT in which you have to implement the formula of IDFT. Pass 𝑋(𝑘) and
𝑘 as parameters to the function and the function should return the values of 𝑥(𝑛).

(Hint: Use the vector multiplication method to implement this function. Do not use loops.)

42 | P a g e
Lab manual of Digital Signal Processing

Exercise 3:
Let 𝑥(𝑛) be a 4-point sequence such that 𝑥(𝑛) = 1; … … . . 𝑓𝑜𝑟 0 ≤ 𝑛 ≤ 3 and 0 otherwise.
Find out its discrete time Fourier transform and plot its magnitude. Also compute its 4-point
DFT using MATLAB. Plot the figures on MATLAB.

Exercise 4:

Sampling should be done at dense frequencies i.e. you should increase N. Now take the 8-point
DFT i.e. 𝑁 = 8; append four zeros at the end of the sequence 𝑥(𝑛) defined above. Show its
DFT in your MATLAB plots. How many non-zero values does it contain now?

Exercise 5:

Now append 12 zeros at the end of the sequence 𝑥(𝑛) defined above and take 16-point DFT.
Show its DFT in your MATLAB plots. How many non-zero values does it contain now?

PROPERTIES OF DFT:

Exercise 6: Circular Folding

If an 𝑁-point sequence is folded, then the result 𝑥(−𝑛) would not be an 𝑁-point sequence, and
it would not be possible to compute its DFT. Therefore, we use circular folding.

Figure 8.1: Circular folding of signal 𝑥(𝑛)

I. Write a MATLAB function for circular folding of a signal 𝑥(𝑛) which gives the result
𝑥(−𝑛):
𝒇𝒖𝒏𝒄𝒕𝒊𝒐𝒏 𝒙𝒇 = 𝒄𝒊𝒓𝒄𝒇𝒐𝒍𝒅𝒅 (𝒙)

II. Prove the property of time reversal stated bellow for signal 𝑥(𝑛) = [3 2 1 6 5 4]

𝑫𝑭𝑻[𝒙(−𝒏)𝑵 ] = 𝑿(−𝒌)𝑵

43 | P a g e
Lab manual of Digital Signal Processing

Exercise 7: Circular Shift of a sequence:

Write your own MATLAB function to circularly shift a sequence (do not use circshift built in
function). Your code must be generic.

Exercise 8: Circular Convolution

A linear convolution between two N-point sequences will result in a longer sequence. Once
again we have to restrict our interval to 𝟎 ≤ 𝒏 ≤ 𝑵 − 𝟏. Therefore, instead of linear shifting
you should consider circular shifting.
A convolution operation that contains a circular shift is called the circular convolution.

𝑵−𝟏

𝒙𝟏 (𝒏) 𝒙𝟐 (𝒏) = ∑ 𝒙𝟏 (𝒎)𝒙𝟐 ((𝒏 − 𝒎))𝑵


𝒎=𝟎

The DFT property for circular convolution is


𝐃𝐅𝐓 [𝐱 𝟏 (𝐧) 𝐱 𝟐 (𝐧)] = 𝑿𝟏 (𝒌) . 𝑿𝟐 (𝒌)

Write MATLAB function to compute the circular convolution of two sequences.


Take, 𝑥1 (𝑛)={1,2,2} and 𝑥2 (𝑛)={1,2,3,4} and 𝑁 = 4.

Your function must be generic.

function y=circconv [x1,x2,N]

% x1 and x2 two sequences

% N buffer size

% perform zero padding in case the length of sequence is less than N

% fold one sequence to get 𝒙(−𝒏)and then multiply it’s shifted version with the
unfolded sequence accordingly to get 𝒚(𝟏), 𝒚(𝟐), … . . 𝒚(𝑵)

Post Lab Question:


Exercise 1:
Write MATLAB code that determines which number (Telephone Number) was dialed from the
.wav file. The caller may press the phone keys for a variable length of time.

44 | P a g e
Lab manual of Digital Signal Processing

EXPERIMENT 9

Linear and Circular Convolution

Objective

To study the relationship between DFT and DTFS, properties of circular convolution and to
study how we can compute linear convolution using circular convolution.

Software Tools

1. MATLAB R2016a

Introduction

DFT and DTFS are related to each other, the result of which you will observe after performing
exercise 1. You will understand how you can compute linear convolution using circular
convolution.

Relationship between DFT and DTFS

Exercise 1:

Find the DFT and DTFS of the signal and plot the results. Explain the difference in two plots
and explain the relationship between DFT and DTFS.
𝑛
𝑥 = cos (2𝜋𝑘0 ) , 𝑘0 = 1, 𝑛 = 𝑁 − 1 𝑎𝑛𝑑 𝑁 = 8
𝑁
Exercise 2:

Now take 𝑥 = [1 2 3 4 5 6 7] for 𝑛 = 0: 7 and 𝑁 = 8.

Find DFT and DTFS of the above signal and plot them on MATLAB.

Circular Convolution Property

Circular convolution is defined as


𝑵−𝟏

𝒙𝟏 (𝒏) 𝒙𝟐 (𝒏) = ∑ 𝒙𝟏 (𝒎)𝒙𝟐 ((𝒏 − 𝒎))𝑵 , … … . 𝟎 ≤ 𝒏 ≤ 𝑵 − 𝟏


𝒎=𝟎
Circular convolution of two discrete-time signals corresponds to multiplication of their DFTs:

𝒙𝟏 (𝒏) 𝒙𝟐 (𝒏) → 𝑿(𝒌)𝑯(𝒌)

45 | P a g e
Lab manual of Digital Signal Processing

Exercise 3:

Prove the above stated property with 𝑥1 = [1, 3, −2, 1] and ℎ = [1, 1] and 𝑁 = 4.

Linear Convolution using Circular Convolution

Linear convolution of two signals can be implemented using the circular convolution for
example if you have two signals 𝑥1 and 𝑥2 of length three and two respectively:

𝑥1 =[4 5 6] for 𝑛1 =[0 1 2]

𝑥2 = [3 7] for 𝑛2 =[0 1]

Then the result of the linear convolution will be:

conv(x1,x2)= [12 43 53 42] defined for n=[0 1 2 3]

Remember the length of the result is four here, so if we append one zero in 𝑥1 and two zeros
in 𝑥2 and take their circular convolution, then the result of such a circular convolution will be
the same as the linear convolution.

Exercise 4:

Find out the linear convolution of the two signals using circular convolution:

𝑥1 = [1 4 1 3 1 5 2]; 𝑛1 =0:6;

𝑥2 = [3 2 1 6 3 5 3 6 7 8]; 𝑛2 =0:9;

Post Lab Question:

Find out the linear convolution of the two signals using circular convolution:

𝑥1 = [1 4 1 3 1 5 2]; 𝑛1 =0:6;

𝑥2 = [3 2 1 6 3 5 3 6 7 8]; 𝑛2 =0:9;

46 | P a g e
Lab manual of Digital Signal Processing

EXPERIMENT 10

Fast Fourier Transform and Z-Transform

Objective

To study the fast and efficient way of computing the discrete Fourier transform, difference
between this Fast Fourier transform and Discrete Fourier transform and to learn how to find
the Z-Transform using MATLAB.

Software Tools

1. MATLAB R2016a

Introduction

The Fast Fourier Transform is an efficient algorithm for computing the Discrete Fourier
Transform.

Difference in DFT and FFT

FFT (Fast Fourier Transform) is a faster version of the DFT that can be applied when the
number of samples in the signal is a power of two. FFT computation takes approximately
O(Nlog2(N)) operations, whereas a DFT takes approximately O(N2) operations, so the FFT is
significantly faster.

To obtain one sample of 𝑋(𝑘) we need 𝑁 complex multiplications and (𝑁 − 1) complex


additions. Clearly, the number of DFT computations for an 𝑁-point sequence depends
quadratically on 𝑁. The quadratic dependence on 𝑁 can be reduced by realizing that most of
the computations can be eliminated using the periodicity property and the symmetry property.

Let 𝑋(𝑘) = ∑3𝑛=0 𝑥(𝑛). 𝑊4𝑛𝑘 , 0 ≤ 𝑘 ≤ 3,

This computation can be written in matrix form as:

𝑋(0) 𝑊40 𝑊40 𝑊40 𝑊40 𝑥(0)


𝑋(1) 𝑊40 𝑊41 𝑊42 𝑊43 𝑥(1)
[ ]= .[ ]
𝑋(2) 𝑊40 𝑊42 𝑊44 𝑊46 𝑥(2)
𝑋(3) [𝑊40 𝑊43 𝑊46 𝑊49 ] 𝑥(3)

which requires 16 (N2) complex multiplications.

MATLAB Implementation

MATLAB provides a function called fft to compute the DFT of a vector 𝑥. If length of 𝑥 is less
than 𝑁, then 𝑥 is padded with zeros. This fft function is written in machine language therefore

47 | P a g e
Lab manual of Digital Signal Processing

it executes very fast. If 𝑁 is a power of 2 then a high speed radix-2 FFT algorithm is employed.
If 𝑁 is not a multiple of 2, then 𝑁 is decomposed into prime factors and a slower mixed radix
FFT algorithm is used.

There are many algorithms to compute FFT, a few are listed below:

 Radix-2 FFT algorithm


 Split-radix FFT algorithm
 Prime-factor FFT algorithm
 Bruun's FFT algorithm
 Rader's FFT algorithm
 Bluestein's FFT algorithm

Radix-2-FFT Algorithm
𝑁
Let 𝑁 be a multiple of 2 then we divide 𝑥(𝑛) into two 2 point sequences:

𝑵
𝒈𝟏 (𝒏) = 𝒙(𝟐𝒏); 𝟎≤𝒏≤ − 𝟏
𝟐
𝑵
𝒈𝟐 (𝒏) = 𝒙(𝟐𝒏 + 𝟏); 𝟎≤𝒏≤ − 𝟏
𝟐
Let 𝐺1 (𝑘) and 𝐺2 (𝑘) be 𝑁/2-point DFTs of 𝑔1 (𝑛) and 𝑔2 (𝑛)then we have:

𝑿(𝒌) = 𝑮𝟏 (𝒌) + 𝑾𝒌𝒏 𝑮𝟐 (𝒌), 𝟎≤𝒌≤𝑵−𝟏


This algorithm has a complexity of O(Nlog2(N)). The input sequence for the FFT is divided
into two sequences in the following way:

If 𝑥(𝑛) = [0 1 2 3 4 5 6 7], then

𝑥1 (𝑛1 ) = [0 2 4 6]% even samples of 𝑥(𝑛)

𝑥2 (𝑛2 ) = [1 3 5 7]% odd samples of 𝑥(𝑛)

Exercise 1:

Write a script to implement the equation 𝑋(𝑘) = 𝐺1 (𝑘) + 𝑊𝑛𝑘 𝐺2 (𝑘) in MATLAB given only
the following two vectors of size N/2 each.

𝑥1 (𝑛1 ) = [0 2 4 6]% even samples of 𝑥(𝑛)

𝑥2 (𝑛2 ) = [1 3 5 7]% odd samples of 𝑥(𝑛)


𝑘
𝑊𝑁𝑘 = 𝑒 −𝑗2𝜋(𝑁)

You may use the MATLAB function fft to check your results.

48 | P a g e
Lab manual of Digital Signal Processing

𝑘𝑚
(Hint: Use the symmetry property of 𝑊𝑁/2 )

Exercise 2:

𝑋(0) 1 1 𝑥(0)
2- point FFT can be found as [ ]=[ ].[ ]
𝑋(1) 1 −1 𝑥(1)

Write a MATLAB function to find 2-point FFT.

function y = fft_2pt(x,N)
% x : input vector of length 2
% if N == 2

% Calculate 2-point FFT of 𝒙


% else
% print ‘error’

Z-Transform
The Z-transform is simply a power series representation of a discrete-time sequence. The Z-
transform of a discrete time signal is defined as

𝑿(𝒛) = ∑ 𝒙(𝒏)𝒛−𝒏
𝒏=−∞

Where, z is the complex variable. This equation is sometimes called direct z-transform
because it transforms the time-domain signal 𝑥(𝑛) into its complex-plane representation
𝑋(𝑧). For convenience the z-transform of a signal 𝑥(𝑛) is denoted by 𝑋(𝑧) ≡ 𝑍 {𝑥(𝑛)}
The procedure of transforming z-transform to the time domain is called inverse z-transform.
The inversion formula for obtaining 𝑥(𝑛)from 𝑋(𝑧) is
𝟏
𝒙(𝒏) = ∮ 𝑿(𝒛)𝒛𝒏−𝟏 𝒅𝒛
𝟐𝝅𝒋
Z-transform gives us the complex domain information of a sequence. MATLAB provides us
with built-in functions to compute Z-transform as well as Inverse Z-transform. The region of
convergence can also be plotted using a function called z plane.

Objective:

The objective of this experiment is to learn how to find z-Transform and Inverse z-transform
from multiple methods using MATLAB. The pole-zero plot is found using zplane (num, den).

49 | P a g e
Lab manual of Digital Signal Processing

Exercise 1:
1 𝑛
If ℎ(𝑛) = 5 (4) 𝑢(𝑛)
Write 𝐻(𝑧) and also sketch its pole-zero plot.

num=[5]; den=[1, -1/4];


zplane (num,den)
[r,p,c]=residue (num,den)

Inverse z-Transform

The analysis equation of z-transform is given by:

𝒏=+∞

𝑿(𝒛) = ∑ 𝒙(𝒏) 𝒛−𝒏


𝒏=−∞
The inverse z-transform can be found by
1. Inspection Method
2. Partial Fraction Expansion Method
3. Power Series Expansion
4. Residue function in MATLAB

Inspection Method:
1 1 𝑛
The inverse z-transform of 𝑋(𝑧) = 1 −1
is 𝑥(𝑛) = (2) 𝑢(𝑛)
1− 𝑧
2

Partial Fraction Expansion Method:

Express 𝐺(𝑧) in a partial fraction expansion form and then determine 𝑔(𝑛) by summing the
inverse transform of the individual simpler terms in the expansion.

Example:
1 1
𝑋(𝑧) = , 𝑅𝑂𝐶: |𝑧| >
(1 −
1 −1
𝑧 ) (1 −
1 −1
𝑧 ) 2
4 2

−1 2 1
𝑋(𝑧) = + , 𝑤𝑖𝑡ℎ |𝑧| >
(1 −
1 −1
𝑧 ) (1 −
1 −1
𝑧 ) 2
4 2
1 𝑛 1 𝑛
The inverse z-transform is given by: 𝑥(𝑛) = 2 ( ) 𝑢(𝑛) − ( ) 𝑢(𝑛).
2 4
And, this is a right sided sequence.

Exercise 2:

Find all possible sequences (which is inverse z-transforms) for this 𝑋(𝑧).

50 | P a g e
Lab manual of Digital Signal Processing

𝑧
𝑋(𝑧) =
3𝑧 2 − 4𝑧 + 1

Partial Fraction Expansion Using MATLAB

The MATLAB function [r, p, c] = residue (num, den) computes the partial fraction expansion
of a rational z-transform with numerator and denominator coefficients given by vectors num
and den.
1. Vector r contains the residues
2. Vector p contains the poles
3. Vector c contains the constants

Example:
𝑧
𝑋(𝑧) =
3𝑧 2 − 4𝑧 + 1

(0 + 𝑧 −1 )
𝑋(𝑧) =
(3 − 4𝑧 −1 + 𝑧 −2 )

num=[0,1];den=[3,-4,1];
zplane(num,den)
[r,p,c]=residue(num,den)

r=
0.5000
-0.5000

p=
1.0000
0.3333
c=
[]

So from above, we obtain


1 1
2 2
𝑋(𝑧) = −
(1 − 𝑧 −1 ) (1
1
− 3 𝑧 −1 )
1 1 1 𝑛
𝑥(𝑛) = ( − ( ) ) 𝑢(𝑛)
2 2 3

Exercise 3:
Find inverse z-transform by using MATLAB and by the method of partial fractions
expansion for the following z-transforms.
1)

51 | P a g e
Lab manual of Digital Signal Processing

(1 − 𝑧 −1 − 4𝑧 −2 + 4𝑧 −3 )
𝑋(𝑧) = 11 −1 13 −2 1
(1 − 𝑧 + 𝑧 − 4 𝑧 −4 )
4 8
2)
𝑧
𝑋(𝑧) =
(𝑧 3 + 2𝑧 2 + 1.25𝑧 + 0.25)
3)
(𝑧 3 − 3𝑧 2 + 4𝑧 + 1)
𝑋(𝑧) =
(𝑧 3 − 4𝑧 2 + 𝑧 − 0.16)

The denominator polynomial can also be calculated using MATLAB’s built-in function poly,
which computes the polynomial coefficients when roots are given.

Example:

1
𝑋(𝑧) =
(1 − 0.9𝑧 −1 )2 (1 + 0.9𝑧 −1 )
num = [1]; den = poly ([0.9, 0.9, -0.9]);
[r, p, c] = residue (num, den);

Exercise 4:

Find 𝑥(𝑛) sequence for the above example.

Inverse z-transform by Power Series Expansion Method

1. The z-transform 𝑋(𝑧) of a causal sequence 𝑥[𝑛] can be expanded in a power series form.
2. In the series expansion, the coefficient multiplying the term 𝑧 −𝑛 is the n-th sample of 𝑥[𝑛].
3. The power series expansion can be obtained by long division for a rational z-transform
expressed as a ratio of polynomials in 𝑧 −1 .

Example:
1 + 2𝑧 −1
𝐻(𝑧) =
1 + 4𝑧 −1 − 0.12𝑧 −2

Long division of the numerator by the denominator results in

𝐻(𝑧) = 1 + 1.6𝑧 −1 − 0.52𝑧 −2 + 0.4𝑧 −3 − 0.224𝑧 −4 + … … … ..


This gives us

ℎ[𝑛] = [1, 1.6, −0.52, 0.4, −0.2224, … … ], 𝑓𝑜𝑟 𝑛 ≥ 0

52 | P a g e
Lab manual of Digital Signal Processing

1. The MATLAB function impz is used to find the inverse of a rational z-transform
𝐺(𝑧).
2. This function computes the coefficients of the power series expansion of 𝐺(𝑧).

num = [1 2]; den = [1 0.4 -0.12];


[h, t] = impz (num, den);
figure (1); stem (t, h)

Exercise 5:

Use Power Series Expansion method and MATLAB to calculate the inverse z-transform of
the following and plot the output sequence.
(1 − 𝑧 −1 − 4𝑧 −2 + 4𝑧 −3 )
𝑋(𝑧) = 11 13 1
(1 − 4 𝑧 −1 + 8 𝑧 −2 − 4 𝑧 −4 )

Representation of a system in Z-Domain:

MATLAB has a function freqz to plot the magnitude and phase response of a system in the
Z-Domian.

1. [H, w] = freqz (b, a, N);

It returns the 𝑁-point frequency vector 𝑤 and the 𝑁-point complex frequency response vector
𝐻 of the system, given its numerator and denominator coefficients in vectors 𝑏 𝑎𝑛𝑑 𝑎. It is
evaluated at 𝑁-points equally spaced around the upper half of the unit circle.

2. [H, w] = freqz (b, a, N, ‘whole’)


It uses 𝑁 points around the whole unit circle for computation of the frequency response.

Example:
1
𝐻(𝑧) = ; |𝑧| > 0.9
(1 − 0.9𝑧 −1 )
Pole-zero plot is made first:

b=[1 0]; a=[1 -0.9];


zplane(b,a);

Plotting magnitude and phase of 𝐻(𝑒 𝑗𝑤 )

[H,w]= freqz(b,a,100)
figure
magH=abs(H); phaH= angle(H);

53 | P a g e
Lab manual of Digital Signal Processing

subplot(211)
plot(w/pi,magH)
xlabel('frequency in pi units'); ylabel('Magnitude');
subplot(212)
plot(w/pi,phaH/pi)
xlabel('frequency in pi units'); ylabel('Phase in pi units');

Exercise 6:

Draw the frequency response plots for the above example


To compute the Z-transform of an arithmetical expression, use the ztrans function. For
example, compute the Z-transform of the following expression:

syms n

S = ztrans(sinh(n))

𝑧 sin ℎ(1)
𝑧 2 − 2 cosh(1) 𝑧 + 1
If you know the Z-transform of an expression, you can find the original expression or a
mathematically equivalent form by computing the inverse Z-transform. To compute the
inverse Z-transform, use the iztrans function. For example, compute the inverse Z-transform
of the expression S:

iztrans(S)

answer: sinh (n)

Exercise 7:

Find the Z-transform and inverse Z-transform of following expressions:

1. x(n) = en

2. 𝐟 = 𝐬𝐢𝐧(𝐤)
3. 𝐟 = 𝐚𝐧 , 𝐰𝐡𝐞𝐫𝐞 𝐚 𝐢𝐬 𝐚𝐧𝐲 𝐜𝐨𝐧𝐬𝐭𝐚𝐧𝐭

Post Lab Question:

Prove the property of linearity for the following functions:

f1 (n) = an

f2 (n) = sin (n)

Z[ax[n] + by[n]] = a X(z) + bY(z)

where, a=2 and b=2.

54 | P a g e
Lab manual of Digital Signal Processing

EXPERIMENT 11

Digital Filters

Objective

To study the method of giving delay in a signal and then adding or multiplying it with another
signal such that data of both signals remain intact. Moreover, to understand chebyshev,
butterworth and elliptic techniques for obtaining higher, lower or a band of frequencies of a
signal.

Software Tools

1. MATLAB R2016a

Introduction

A fundamental aspect of signal processing is filtering. Filtering involves the manipulation of


the spectrum of a signal by passing or blocking certain portions of the spectrum, depending on
the frequency of those portions. Filters are designed according to what kind of manipulation of
the signal is required for a particular application. Digital filters are implemented using three
fundamental building blocks: an adder, a multiplier, and a delay element.

With the basic building blocks at hand, the two different filter structures can easily be
implemented. These two structures are Infinite Impulse Response (IIR) and Finite Impulse
Response (FIR), depending on the form of the system’s response to a unit pulse input. IIR
filters are commonly implemented using a feedback (recursive) structure, while FIR filters
usually require no feedback (non-recursive).

Using MATLAB, a low pass digital filter is designed using various analog prototypes:
Chebyshev, Butterworth, and Elliptic. The optimum filter type is chosen on the basis of
implementation complexity, magnitude response, and phase response.

55 | P a g e
Lab manual of Digital Signal Processing

Chebyshev Filter

[b,a] = cheby1(n,R,Wp,'ftype') designs a highpass, lowpass, or bandstop filter, where the


string 'ftype' is 'high', 'low', or 'stop'.

𝑛 is the order of filter. 𝑊𝑃 is normalized pass-band edge frequency. 𝑅is the p-p ripple, usually
0.5dB.

MATLAB Code Chebyshev:

wp = 0.125*2*pi; % digital passband frequency in Hz (normalized)


ws = 0.1375*2*pi; % digital stopband frequency in Hz (normalized)
Rp = 0.5; % passband ripple in dB
As = 20; % stopband attenuation in dB

[b, a] = cheby1(8, Rp,wp, 'low');


[db,w] = freqz(b,a);
plot(w/pi,abs(db));
xlabel('frequency (Hz)'); ylabel('decibels'); title('Magnitude in dB');

Exercise 1:

Run the code given above for low and high pass filter prototype and show the absolute and
phase plots on MATLAB.

Butterworth Filter

[b,a] = butter(n,Wn,'ftype') designs a highpass, lowpass or bandstop filter, where the string
'ftype' is 'high', 'low', or 'stop', as described below.

𝑛 is the order of filter and 𝑊𝑛 is normalized cutoff frequency.

MATLAB Code Butterworth:

wp = 0.125*2*pi; % digital passband frequency in Hz (normalized)


ws = 0.1375*2*pi; % digital stopband frequency in Hz (normalized)
Rp = 0.5; % passband ripple in dB
As = 20; % stopband attenuation in dB

[b, a] = butter(8,wp, 'low');


[db,w] = freqz(b,a);
plot(w/pi,abs(db));
xlabel('frequency (Hz)'); ylabel('decibels'); title('Magnitude in dB');

56 | P a g e
Lab manual of Digital Signal Processing

Exercise 2:

Run the code given above for low and high pass filter prototype and show the absolute and
phase plots on MATLAB.

Elliptic Filter

[b,a] = ellip(n,Rp,Rs,Wp,'ftype') designs a highpass, lowpass, or bandstop filter, where the


string 'ftype' is 'high', 'low', or 'stop'.

Here, 𝑛 is the order of filter. 𝑊𝑃 is normalized pass-band edge frequency. 𝑅𝑃 is the p-p
ripple, usually 0.5dB.
NB: stop-band ripple must be greater than pass-band ripple.

MATLAB Code Elliptical


wp = 0.125*2*pi; % digital passband frequency in Hz (normalized)
ws = 0.1375*2*pi; % digital stopband frequency in Hz (normalized)
Rp = 0.5; % passband ripple in dB
As = 20; % stopband attenuation in dB

[b, a] = ellip(5,Rp,1.0,wp, 'low');


[db,w] = freqz(b,a);
plot(w/pi,abs(db));
xlabel('frequency (Hz)'); ylabel('decibels'); title('Magnitude in dB');

Exercise 3:

Run the code given above for low and high pass filter prototype and show the absolute and
phase plots on MATLAB.

Distinguish between the responses of the three filters.

Post Lab Question:

Design a Band-pass Butterworth filter of order 32. Choose the band frequencies yourself.
Show the absolute and phase plots and your code for this Band-pass filter in MATLAB.

57 | P a g e
Lab manual of Digital Signal Processing

EXPERIMENT 12

Implementation of FIR Filters on MATLAB and TMS320C6713

Objective

In this lab you will learn how to implement the FIR filter in MATLAB and how to implement
an FIR (finite impulse response) filter on C6713 DSP Board.

Equipment

1. Software (MATLAB R2016a)


2. C6713 DSP Development Board
3. USB Cable
4. Universal Power Supply
5. AC Power Cord(s)

Introduction

FIR filters are frequently used in the real time DSP systems. They are simple to implement,
stable and have property of linear phase. Input and output relationship is given by:
𝑴−𝟏

𝒚[𝒏] = ∑ 𝒉[𝒎]. 𝒙[𝒏 − 𝒎]


𝒎=𝟎

Where,

𝑥 = 𝑖𝑛𝑝𝑢𝑡, 𝑦 = 𝑜𝑢𝑡𝑝𝑢𝑡, ℎ = 𝑓𝑖𝑙𝑡𝑒𝑟 𝑐𝑜𝑒𝑓𝑓𝑖𝑐𝑖𝑒𝑛𝑡𝑠, 𝑀 = 𝑛𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝑓𝑖𝑙𝑡𝑒𝑟 𝑐𝑜𝑒𝑓𝑓𝑖𝑐𝑖𝑒𝑛𝑡𝑠.

1. Implementation of FIR filter on C6713 DSP Board

1.1 Quantization Consideration:

The key choice in Quantization consideration is between the floating points and fixed point.

As we are using C6713 in our lab which is a floating point processor and allows using the C
language, so it is our ultimate choice. Advantages of the floating point math are:

 Less quantization error


 Don’t have to worry about scaling factors
 Less likelihood of overflow/underflow
 Much easier to code

58 | P a g e
Lab manual of Digital Signal Processing

1.2 Code for filter realization:


Direct-Form 1 implies the direct realization of the convolution equation:
𝑴−𝟏

𝒚[𝒏] = ∑ 𝒉[𝒎]. 𝒙[𝒏 − 𝒎]


𝒎=𝟎

Allocate buffer of length 𝑀 for input samples.

1.3 Sample code

Interrupt void serial PortRcvISR()


{
union {Uint32 combo; short channel[2];} temp;
inti = 0;
float result = 0.0;
temp.combo = MCBSP_read(DSK6713_AIC23_DATAHANDLE);
// Update array samples (move data - this is the slow way)
for(i = N-1; i>= 1; i-- )
samples[i] = samples[i-1];
samples[0] = (float)temp.channel[0]; // store right channel
// Filtering
for(i = 0 ; i< N ; i++ )
result += fir_coeff[i]*samples[i];
temp.channel[0] = (short)result; // output to right channel
MCBSP_write(DSK6713_AIC23_DATAHANDLE, temp.combo);
}

Note that all math here is floating point. Filter coefficients are also assumed to be floating
point

Exercise 1:

Create an FIR filter with the following specifications:

 Band pass
 8th order

59 | P a g e
Lab manual of Digital Signal Processing

 Direct Form I
 Least-squares design
 44100Hz sampling rate
 Fstop1=3000Hz
 Fpass1=4000Hz
 Fpass2=8000Hz
 Fstop2=12000Hz
 Equal weighting in all bands
 All floating point math (single or double precision)

2. Implementation of FIR filter in MATLAB

Finite impulse response (FIR) filters can be characterized by a linear, constant-coefficient


difference equation (N is an integer):

y(n) = b0x(n)+ b1x(n-1)+ b2x(n-2)+...+ bLx(n-N+1)

The ideal impulse response for frequency-selective filters is noncausal and infinite-
durational. Perhaps the simplest way to design an FIR filter is to truncate the ideal impulse
response to obtain a causal, finite impulse response. The window function is the signal which,
when multiplied with the infinite impulse response, renders the latter finite i.e.
𝜔𝑐𝑛−𝜔𝑐𝑛𝑑
Ideal impulse response:sin ( )
𝜋𝑛−𝜋𝑛𝑑

Ideal impulse response: hlp(n) = sin(ωcn-ωcnd)/(πn-πnd) (–∞<n<∞)


1, 0 ≤ n < N
Windowing function: w(n) = {
0, otherwise
Finite impulse response: hfirlp(n) = w(n)*hlp(n) = sin(ωcn-ωcnd)/(πn-πnd)
(0<=n<N)
1 0 ≤ |ω| < ωc
Hlp(𝑒 𝑗𝜔 ) = {
0 ωc < ω ≤ π
Figure 12.1 shows the ideal filter response.

Figure 12.1 - Ideal low-pass filter frequency response

60 | P a g e
Lab manual of Digital Signal Processing

a) Write a script that implements a low-pass FIR filter,where:

ℎ(𝑛) = 𝑠𝑖𝑛𝑐(𝜔𝑐 ∗ 𝑛)

𝑥(𝑛) = cos(𝜔𝑛)

𝑦(𝑛) = ℎ(𝑛) ∗ 𝑥(𝑛)

Plot h(n),H(w),x(n),X(w) and Y(w),where Y(w)=H(w)*X(w).

Fs=32000 samples/sec, Fc=4000Hz, n=-20:20.

b) Prove, analytically, the following theorems given that the Fourier transform of x(n) is
X(ejw) (i.e. x(n) <-> X(ejw)).

𝑥(𝑛 − 𝑑) = 𝑒 −𝑗𝜔𝑑 𝑋(𝑒 𝑗𝜔 )

d=5

c) If h(n)lp denotes the impulse response of low pass filter with frequency response of a low
pass Hlp(w), a high pass filter cab be obtained by translating Hlp(w)by π radians.

Hhp(ω)=Hlp(ω-π)

Transform the above low pass filter to high pass filter

61 | P a g e
Lab manual of Digital Signal Processing

Appendix A: Lab Evaluation Criteria


Labs with projects

1. Experiments and their report 50%


a. Experiment 60%
b. Lab report 40%
2. Quizzes (3-4) 15%
3. Final evaluation 35-%
a. Project Implementation 60%
b. Project report and quiz 40%

Labs without projects

1. Experiments and their report 50%


a. Experiment 60%
b. Lab report 40%
2. Quizzes (3-4) 20%
3. Final Evaluation 30%
a. Experiment. 60%
b.Lab report, pre and post
experiment quiz 40%

Notice:

Copying and plagiarism of lab reports is a serious academic misconduct. First instance of
copying may entail ZERO in that experiment. Second instance of copying may be reported to
DC. This may result in awarding FAIL in the lab course.

62 | P a g e
Lab manual of Digital Signal Processing

Appendix B: Safety around Electricity


In all the Electrical Engineering (EE) labs, with an aim to prevent any unforeseen accidents
during conduct of lab experiments, following preventive measures and safe practices shall be
adopted:

 Remember that the voltage of the electricity and the available electrical
current in EE labs has enough power to cause death/injury by electrocution. It
is around 50V/10 mA that the “cannot let go” level is reached. “The key to
survival is to decrease our exposure to energized circuits.”

 If a person touches an energized bare wire or faulty equipment while


grounded, electricity will instantly pass through the body to the ground,
causing a harmful, potentially fatal, shock.

 Each circuit must be protected by a fuse or circuit breaker that will blow or
“trip” when its safe carrying capacity is surpassed. If a fuse blows or circuit
breaker trips repeatedly while in normal use (not overloaded), check for shorts
and other faults in the line or devices. Do not resume use until the trouble is
fixed.

 It is hazardous to overload electrical circuits by using extension cords and


multi-plug outlets. Use extension cords only when necessary and make sure
they are heavy enough for the job. Avoid creating an “octopus” by inserting
several plugs into a multi-plug outlet connected to a single wall outlet.
Extension cords should ONLY be used on a temporary basis in situations
where fixed wiring is not feasible.

 Dimmed lights, reduced output from heaters and poor monitor pictures are all
symptoms of an overloaded circuit. Keep the total load at any one time safely
below maximum capacity.

 If wires are exposed, they may cause a shock to a person who comes into
contact with them. Cords should not be hung on nails, run over or wrapped
around objects, knotted or twisted. This may break the wire or insulation.
Short circuits are usually caused by bare wires touching due to breakdown of
insulation. Electrical tape or any other kind of tape is not adequate for
insulation!

 Electrical cords should be examined visually before use for external defects
such as: Fraying (worn out) and exposed wiring, loose parts, deformed or
missing parts, damage to outer jacket or insulation, evidence of internal

63 | P a g e
Lab manual of Digital Signal Processing

damage such as pinched or crushed outer jacket. If any defects are found the
electric cords should be removed from service immediately.

 Pull the plug not the cord. Pulling the cord could break a wire, causing a short
circuit.

 Plug your heavy current consuming or any other large appliances into an outlet
that is not shared with other appliances. Do not tamper with fuses as this is a
potential fire hazard. Do not overload circuits as this may cause the wires to
heat and ignite insulation or other combustibles.

 Keep lab equipment properly cleaned and maintained.

 Ensure lamps are free from contact with flammable material. Always use
lights bulbs with the recommended wattage for your lamp and equipment.

 Be aware of the odor of burning plastic or wire.

 ALWAYS follow the manufacturer recommendations when using or installing


new lab equipment. Wiring installations should always be made by a licensed
electrician or other qualified person. All electrical lab equipment should have
the label of a testing laboratory.

 Be aware of missing ground prong and outlet cover, pinched wires, damaged
casings on electrical outlets.

 Inform Lab engineer / Lab assistant of any failure of safety preventive


measures and safe practices as soon you notice it. Be alert and proceed with
caution at all times in the laboratory.

 Conduct yourself in a responsible manner at all times in the EE Labs.

 Follow all written and verbal instructions carefully. If you do not understand a
direction or part of a procedure, ASK YOUR LAB ENGINEER / LAB
ASSISTANT BEFORE PROCEEDING WITH THE ACTIVITY.

 Never work alone in the laboratory. No student may work in EE Labs without
the presence of the Lab engineer / Lab assistant.

 Perform only those experiments authorized by your teacher. Carefully follow


all instructions, both written and oral. Unauthorized experiments are not
allowed.

 Be prepared for your work in the EE Labs. Read all procedures thoroughly
before entering the laboratory. Never fool around in the laboratory.
Horseplay, practical jokes, and pranks are dangerous and prohibited.

64 | P a g e
Lab manual of Digital Signal Processing

 Always work in a well-ventilated area.

 Observe good housekeeping practices. Work areas should be kept clean and
tidy at all times.

 Experiments must be personally monitored at all times. Do not wander around


the room, distract other students, startle other students or interfere with the
laboratory experiments of others.

 Dress properly during a laboratory activity. Long hair, dangling jewelry, and
loose or baggy clothing are a hazard in the laboratory. Long hair must be tied
back, and dangling jewelry and baggy clothing must be secured. Shoes must
completely cover the foot.

 Know the locations and operating procedures of all safety equipment including
fire extinguisher. Know what to do if there is a fire during a lab period; “Turn
off equipment, if possible and exit EE lab immediately.”

65 | P a g e
Lab manual of Digital Signal Processing

Appendix C: Guidelines on Preparing Lab Reports


Each student will maintain a lab notebook for this lab course. You will write a report for each
experiment you perform in your notebook.

DSP Lab Report Format

The format of the report will be as given below:

1. Introduction: Introduce the new commands being used, and their significance.

2. Objective: What are the learning goals of the experiment?

3. Design: If applicable, draw the flow chart for the program. How do the new
constructs facilitate achievement of the Objective; if possible, a comparison in
terms of efficacy and computational tractability with the alternate constructs?

(Hardware: If the experiment involves the usage of DSP board than include this heading.
Explain which BSL modules and files were included)

4. Issues: The bugs encountered and the way they were removed.

5. Conclusions: What conclusions can be drawn from experiment?

6. Application: Suggest a real world application where this exercise may apply.

7. Answers to post lab questions (if any).

Note: Your report should be of maximum 3 pages. Write your roll number and section on top.

Sample Lab Report for DSP Lab

Introduction

The ability to control the flow of the program, letting it make decisions on what code to execute,
is important to the programmer. The if-else statement allows the programmer to control if a
program enters a section of code or not based on whether a given condition is true or false. If-
else statements control conditional branching.

if expression

statement1

else

statement2

end

66 | P a g e
Lab manual of Digital Signal Processing

If the value of expression is nonzero, statement1 is executed. If the optional else is present,
statement2 is executed if the value of expression is zero. In this lab, we use this construct to
select an action based upon the user's input, or a predefined parameter.

Objective:

To use if-else statements for facilitation of programming Objective: A function which sorts the
vector in both ascending and descending order without using the MATLAB built in functions
for sorting . We have written a MATLAB function that reads in an arbitrary length vector and
sorts in ascending and descending order.A second, string, variable which can take the value of
‘d’ for decreasing order or ‘i’ for increasing order

Measurements:

The objective was achieved with the following code:

function [v] = MySort(u,itype)

%|---------------------------------|

%|This function sorts vector u in increasing order, returning the sorted vector as v. |

%|If itype= 'd', decreasing order & If itype = 'i', increasing order |

%|---------------------------------|

%Determine length of vector

n = length(u);

%Copy vector u to v9

67 | P a g e
Lab manual of Digital Signal Processing

v = u;

%Start sorting process

ifitype == 'i'

fori = 1:n-1

for j = i+1:n

if v(i)>v(j)

temp = v(i);

v(i) = v(j);

v(j) = temp;

end

end

end

else

fori = 1:n-1

for j = i+1:n

if v(i)<v(j)

temp = v(i);

v(i) = v(j);

v(j) = temp;

end

end

end

end

Result:

» u = round(10*rand(1,10))

u=8074857432

68 | P a g e
Lab manual of Digital Signal Processing

EDU» MySort(u,'i')

ans = 0 2 3 4 4 5 7 7 8 8

EDU» MySort(u,'d')

ans = 8 8 7 7 5 4 4 3 2 0

The conditional statement made this implementation possible; without conditional branching,
it is not possible to achieve this objective.

Issues:

Encountered bugs and issues; how were they identified and resolved.

Conclusions:

The output indicates correct execution of the code.

Applications:

If-else statements are a basic construct for programming to handle decisions.

69 | P a g e

Das könnte Ihnen auch gefallen