DSP Lab Manual Updated - August2018
DSP Lab Manual Updated - August2018
LAB MANUAL
DEPARTMENT OF ELECTRICAL
ENGINEERING,
FAST-NU, LAHORE
Lab manual of Digital Signal Processing
Page|1
Lab manual of Digital Signal Processing
Table of Contents
Sr.
Description Page
No
1 List of Equipment 3
Page|2
Lab manual of Digital Signal Processing
List of Equipment
2 USB Cable
4 AC Power Cord(s)
Page|3
Lab manual of Digital Signal Processing
EXPERIMENT 1
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.
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 x 1 (n) and x 2 (n)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 below:
The output of the above code looks like the figure shown below:
Page|4
Lab manual of Digital Signal Processing
1. Write the function in MATLAB. Briefly explain what you understand by the
command ‘find’.
Page|5
Lab manual of Digital Signal Processing
1. Using your understanding of the function ‘signal addition’ write a function for
multiplying two signals of unequal lengths.
2. Let z 1 (n1 )= {0,3,2,1} , z 2 (n2 ) = {1,2,3,0} , n1={1,2,3,4}, n2 = {-1,0,1,2}. Multiply the
two sequences z 1 ( n1 )∧z 2 ( n2 ) .
x ( n+ N )Implies x (n)is shifted to the left by N; x ( n−N ) implies x ( n ) is shifted to the right by
N . The figure shows sequencex (n) and its shifted version:
Page|6
Lab manual of Digital Signal Processing
Page|7
Lab manual of Digital Signal Processing
1. Use the MATLAB function fliplr to define x (−n). Letx (n)={1,2,5,8,3,2}, plot x (n)
and x (−n) on the same figure. Given x ( 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:
Exercise 6:
EXPERIMENT 2
Objective
In this experiment you will become familiar with a development system for programming
DSP hardware in order to implement DSP operations.
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.
Page|8
Lab manual of Digital Signal Processing
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.
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.
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.
Page|9
Lab manual of Digital Signal Processing
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:
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 optimized C compiler produce code that is comparable to
programmer- optimized assembly code.
P a g e | 10
Lab manual of Digital Signal Processing
1.5 Codec
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.
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.
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
P a g e | 11
Lab manual of Digital Signal Processing
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.
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
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 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,
P a g e | 12
Lab manual of Digital Signal Processing
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.
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.
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 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.
P a g e | 13
Lab manual of Digital Signal Processing
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, we can keep these intermediate assembly files.
P a g e | 14
Lab manual of Digital Signal Processing
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
assembled program instructions, global variables, and runtime support libraries are loaded to
their linker-specified memory locations.
P a g e | 15
Lab manual of Digital Signal Processing
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:
P a g e | 16
Lab manual of Digital Signal Processing
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
"include "dsk6713.h#
"include "dsk6713_led.h#
"include "dsk6713_dip.h#
)(void main
;)(DSK6713_init
;)(DSK6713_LED_init
;)(DSK6713_DIP_init
while(1)
/* Toggle LED #0 */
;DSK6713_LED_toggle(0)
if (DSK6713_DIP_get(3) == 0)
;DSK6713_LED_on(3)
else
P a g e | 17
Lab manual of Digital Signal Processing
;DSK6713_LED_off(3)
The steps to perform the LED blinking sequence on DSP Board are shown pictorially
:below
.Run the 6713DSK diagnostics to check the diagnostic status of DSP Board .1
P a g e | 18
Lab manual of Digital Signal Processing
.Compile your File (led.c project) to check for any errors or warnings .4
P a g e | 19
Lab manual of Digital Signal Processing
P a g e | 20
Lab manual of Digital Signal Processing
.In the end, run your project and observe the blinking sequence of LEDs .7
The figures below show the LED blinking sequence. First, LED 1 blinks and then LED 3
.lights up if DIP switch 3 is depressed
P a g e | 21
Lab manual of Digital Signal Processing
Exercise 2:
P a g e | 22
Lab manual of Digital Signal Processing
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.
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:
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:
II. Features
III. Importance
IV. Applications
P a g e | 23
Lab manual of Digital Signal Processing
EXPERIMENT 3
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
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 x a ( t ) be an analog signal, we now sample it at T s seconds to obtain discrete time signal
x. n( )
x n( =) x a (nT s)
:Exercise1
Consider the analog signal given below
x (t=) soc
3 000,2( π ) t+ n5000,6
is ( π )t+01soc
000,21( π )t
x 1 ( t)= soc
3 000,2( π )t
x 2 ( t)= n5000,6
is ( π )t
x 3 (t=01
) soc
000,21( π )t
a. Write code in MATLAB to plot the figures of x 1 (t), x 2 (t), x 3 (t) and x (t) .
b. Write code in MATLAB to plot the figures of x 1 (n), x 2 (n), x 3 (n) and x (n) .
P a g e | 24
Lab manual of Digital Signal Processing
:Exercise2
x 1 (t=
soc
) (2 π01 ) t
D =01
t cesm ,0≤ t≤ces
1 where, step size is
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:
n=∞
x a ( t )= ∑ x ( n ) sinc [Fs(t−nT s )]
n=−∞
Where:
is discrete-time signalx n( )
nis xπ
cnis x( =) and
xπ
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))))
3. Reconstruct the signal x 1 ( t ) and x 2 ( t ) from its samples x 1 ( n ) and x 2 ( n ) generated above
and also find the error in estimation.
P a g e | 25
Lab manual of Digital Signal Processing
Plot the original signal, analog signal and the reconstructed signals side by side. Use
sampling frequency of F s=40 samples /second . Where step size is D t =10 msec and
0 ≤ t ≤1 sec
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 F s.
x 1 (t=
soc
) (2 π01 ) t
x 2 (t=) soc
2 (2 π05 ) t
8. Are the two signals obtained after reconstruction the same as the original ones?
P a g e | 26
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 vectorx 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 1.
(Note that the horizontal axis ranges from 0 ¿ 2 π , 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 1
P a g e | 27
Lab manual of Digital Signal Processing
1. Load a voice file already present in MATLAB using the following command:
Load mtlb. You may play the file using the soundsc function.
2. How many voice samples are contained in the mtlb file? How many bits have been used to
encode these samples? What is the default sampling rate of audio files assumed to be in
MATLAB?
3. Write a down-sampling code for your voice. Record your voice with Fs=16000 using the
command “wavrecord( )” and play it using “soundsc( )”.
4. Then down-sample it by a factor of 2,4,6,8 and again play it. Also explain the effect of this
down-sampling on audio.
Question 1:
and
The following figure shows the above mentioned continuous-time signals and their respective
samples.
P a g e | 28
Lab manual of Digital Signal Processing
Write a MATLAB code to generate x (t ) and y (t) and its samples as shown in the figure
.above
?Will the two signals obtained after reconstruction be the same as the original ones
Question 2:
Write a MATLAB program that takes two .wav files, one is a voice file and the other is a
song file.
The program plays the song in background. The intensity of background song is increased or
decreased according to intensity of voice of person speaking.
For example when the person is speaking with full intensity, the intensity of background song
is very low and as the person becomes quiet, the song is played with full intensity.
Write a report that shows the plots of both voice and song files and the output file.
P a g e | 29
Lab manual of Digital Signal Processing
EXPERIMENT 4
Objective
To study sampling, quantization and the effect of decreasing the number of levels on signal to
noise ratio.
Introduction
Quantization makes the range of a signal discrete, so that the quantized signal takes on only a
discrete, usually 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.
Procedure:
Step 1:
Using the audio recorder( ) function in MATLAB, make a recording of your voice. Use a
sampling rate of 8kHz, 16 bits per sample, and aim to record around 2 seconds worth.
Step 2:
Quantize the audio samples down from the original 16 bits by removing the least-significant
bit (LSB) from the waveform, to make a 15 bit recording. Repeat for 14, 13, 12 bits down to
1 bit. Explain how you would do this in MATLAB and implement your approach.
Step 3:
Listen to the recordings and make a table with the number of bits and the corresponding
quality assessment. This can simply be a subjective assessment; use terms such as ‘no
perceptual difference’, ‘minor noise present’, ‘quite noisy’, ‘poor quality’ etc.
Step 4:
Calculate the signal-to-noise ratio in each case, and add that to your table. Explain how
SNR was calculated?
/****Start speaking into the Microphone and keep on speaking when u write the following
code also keep the speakers on***/
P a g e | 30
Lab manual of Digital Signal Processing
Fs = 8000;
y = wavrecord(2*Fs,Fs,'int16');
wavplay(y,Fs);
(Part a)
j=2;
fori = 1:1:2*Fs
y1(i) = y(i)/j;
end
wavplay(y1,Fs);
/****MATLAB code for making it (16-k) bit signal, where k varies from 1 to 15
************************/
j=2
for k=1:1:15
fori = 1:1:2*Fs
y1(i) = y(i)/j;
end
j=j*2
16-k
wavplay(y1,Fs);
Calculating SNR:
SNR is being calculated by first finding the maximum value, then finding the average value
of energy and then by implementing the SNR formula in dB
P a g e | 31
Lab manual of Digital Signal Processing
max = 0;
for m = 1:1:2*Fs
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)
Exercise 1:
Write a C code to generate a sine wave of 10kHz and use TMS320C6713 to perform the
quantization as done above. Your function should calculate SNR and display the results.
P a g e | 32
Lab manual of Digital Signal Processing
EXPERIMENT 5
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.
Introduction
For a signal x (n) with fundamental period N, the DTFS equations are given by:
N− 1
x n( =)∑ a ke kj (2 π /N )n
k= 0
N− 1
1
x (n )e− kj (2 π /N )n
a=
k ∑
N n= 0
Exercise 1:
Write a function to compute the discrete time Fourier series as described below
function y = DTFS(x, N)
where,
x−input vector
N−Fundamental period
Exercise 2:
where,
x n−input vector ∈timedomain
C k−Fourier coefficients
P a g e | 33
Lab manual of Digital Signal Processing
Exercise 3:
function y = IDTFS(Ck, N)
where,
C k−Fourier coefficients
N−Fundamental period of repetition
Exercise 4:
Exercise 5:
Exercise 6:
Linearity property
x ( n )=[ 11 1 0 ] ∧ y ( n )=[21 2 4]
Ax ( n ) + By ( n ) → AX ( k ) + BY (k )
HINT (For this question you have to once find DTFS of ‘ Ax ( n ) + By(n)’ and plot it and then
find the DTFS of x (n) and y ( n ) separately and multiply them with A and B respectively. Plot
the results)
P a g e | 34
Lab manual of Digital Signal Processing
Exercise 7:
x (n)=[3 2 1 0]
HINT (For this question you have to once find DTFS of ‘ x (n−n0 )’ and plot it and then find
the DTFS of x ( n ) and multiply it with e−2 πjk (n /N ) . Plot the results)
0
Exercise 8:
x (n)=[3 2 1 0]
x ( n ) e2 πjk (n / N) → X (k −k 0 )
0
HINT (For this question you have to once find DTFS of x (n) e2 πjk (n / N) and plot it and then
0
find the DTFS of x (n) and shift it k 0 units and plot the result)
x (n)=[3 2 1 0]
x ( n ) e2 πjk (n / N) → X (k −k 0 )
0
P a g e | 35
Lab manual of Digital Signal Processing
EXPERIMENT 6
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 x (n) is absolutely sum-able then its discrete time Fourier transform (DTFT) is given by
X ( ω )=∑ x ( n ) . e− jωn
MATLAB Implementation
Exercise 1:
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?
Exercise 3:
P a g e | 36
Lab manual of Digital Signal Processing
Exercise 4:
PROPERTIES OF DTFT:
Exercise 5: Linearity
Let x 1 (n) and x 2 (n) be two random sequences of size 11. Let n=[0:10] and ω
=[0:500]*pi/500, α =3 , β=2. First take individual DTFT of x 1 and x2 and plot their sum (
α X 1 (ω)+ β X 2 (ω)). Then add α x 1 (n)and βx 2 (n), 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.
ω = 0:pi/100:2*pi;
x = [1 1 1];n=[-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 x ¿). Use the trapz function
to estimate the integral.
P a g e | 37
Lab manual of Digital Signal Processing
Prove the following theorem given that the Fourier transform of x (n) is X (e jw )
i.e. x (n)<-> X ( e jω ) .
x ( n−d ) → e− jωd X (e jω )
Plot the signal x (n) shown below and its shifted version – shifted by 4 –Their magnitude and
phase spectra.
x ¿ ( n ) → X ¿ (−ω)
P a g e | 38
Lab manual of Digital Signal Processing
EXPERIMENT 7
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.
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:
k=+∞
y [ n ] =x [ n ]∗h [ n ] = ∑ x [ k ] . h[n−k ]
k=−∞
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:
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.
Show, by plotting the spectra Y ( e jω ) and H ( e jω ).* X ( e jω ) ,that these spectra, obtained from the
signals y (n)=conv ( x (n), x (n)) and x (n)=[1 1 1] for n = [0 1 2] are the same.
Correlation:
P a g e | 39
Lab manual of Digital Signal Processing
n=+∞
r xy ( l ) = ∑ x ( n−l ) y ( n ) ,l=0 ,± 1 ,± 2 , ±3 , … ..
n=−∞
Exercise 3:
Exercise 4:
Write a MATLAB code to find the cross-correlation of the sequences x 1 ( n )=[1 23 4] and
x 2 ( n )=[4 3 21]
Convolution is important because it relates the three signals of interest: the input signal, the
output signal, and the impulse response.
P a g e | 40
Lab manual of Digital Signal Processing
Procedure
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;
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]);
}
P a g e | 41
Lab manual of Digital Signal Processing
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++)
{
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];
P a g e | 42
Lab manual of Digital Signal Processing
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.
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.
EXPERIMENT 8
Objective
P a g e | 43
Lab manual of Digital Signal Processing
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.
Introduction
1
x ( n )= ∑ X ( k ) . e j 2 πk(n / N) , k =0 : N−1 ; n=0: N −1
N k
Exercise 1:
Make a function of DFT in which you have to implement the formula of DFT. Pass x (n) and
n as parameters to the function and the function should return the values of X (k ).
(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 X (k )
and k as parameters to the function and the function should return the values of x (n).
(Hint: Use the vector multiplication method to implement this function. Do not use loops.)
Exercise 3:
Let x (n) be a 4-point sequence such that x ( n )=1 ; … … .. for 0 ≤ n ≤3and0otherwise. 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:
P a g e | 44
Lab manual of Digital Signal Processing
Sampling should be done at dense frequencies i.e. you should increase N. Now take the 8-
point DFT i.e. N=8; append four zeros at the end of the sequence x (n) 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 x (n) 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:
If an N-point sequence is folded, then the result x (−n)would not be an N-point sequence,
and it would not be possible to compute its DFT. Therefore, we use circular folding.
I. Write a MATLAB function for circular folding of a signal x (n) which gives the result
x (−n):
function xf =circfoldd (x )
II. Prove the property of time reversal stated bellow for signal x ( n )=[3 2 16 5 4]
Write your own MATLAB function to circularly shift a sequence (do not use circshift built in
function). Your code must be generic.
P a g e | 45
Lab manual of Digital Signal Processing
A linear convolution between two N-point sequences will result in a longer sequence. Once
again we have to restrict our interval to 0 ≤ n ≤ N −1. Therefore, instead of linear shifting you
should consider circular shifting.
A convolution operation that contains a circular shift is called the circular convolution.
N−1
x 1 ( n ) x 2 ( n )= ∑ x 1 ( m ) x 2 ( ( n−m )) N
m =0
% N buffer size
% fold one sequence to get x (−n)and then multiply it’s shifted version with the
unfolded sequence accordingly to get y ( 1 ) , y ( 2 ) , … .. y ( N )
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.
EXPERIMENT 9
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.
P a g e | 46
Lab manual of Digital Signal Processing
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.
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.
n
(
x=cos 2 π k 0
N )
, k 0=1 , n=N−1∧N =8
Exercise 2:
Find DFT and DTFS of the above signal and plot them on MATLAB.
x 1 ( n ) x 2 (n)→ X (k ) H ( k)
Exercise 3:
Prove the above stated property with x 1=[1 , 3 ,−2 , 1] and h=[1 ,1] and N=4.
Linear convolution of two signals can be implemented using the circular convolution for
example if you have two signals x 1 and x 2 of length three and two respectively:
x 2= [3 7] for n2 =[0 1]
P a g e | 47
Lab manual of Digital Signal Processing
Remember the length of the result is four here, so if we append one zero in x 1 and two zeros
in x 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:
x 1= [1 4 1 3 1 5 2]; n1=0:6;
x 2= [3 2 1 6 3 5 3 6 7 8]; n2 =0:9;
Find out the linear convolution of the two signals using circular convolution:
x 1= [1 4 1 3 1 5 2];n1=0:6;
x 2= [3 2 1 6 3 5 3 6 7 8];n2 =0:9;
EXPERIMENT 10
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.
Introduction
P a g e | 48
Lab manual of Digital Signal Processing
The Fast Fourier Transform is an efficient algorithm for computing the Discrete Fourier
Transform.
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.
0
X (0) W 4 W 04 W 04 W 04 x( 0)
[ ][ = 0
0
X (1) W 4
X (2) W 4
X (3) W 04
W 14
W 24
W 34
W 24
W 44
W 64
][ ]
W 34 x (1)
.
W 64 x (2)
W 94 x (3)
MATLAB Implementation
MATLAB provides a function called fft to compute the DFT of a vector x. If length of x is
less than N, then x is padded with zeros. This fft function is written in machine language
therefore it executes very fast. If N is a power of 2 then a high speed radix-2 FFT algorithm
is employed. If N is not a multiple of 2, then N 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
P a g e | 49
Lab manual of Digital Signal Processing
N
Let N be a multiple of 2 then we divide x (n) into two point sequences:
2
N
g1 ( n )=x ( 2n ) ; 0 ≤ n ≤ −1
2
N
g2 ( n )=x ( 2n+ 1 ) ; 0 ≤ n ≤ −1
2
X ( k )=G 1 ( k )+ W kn G 2 ( k ) , 0 ≤ k ≤ N −1
This algorithm has a complexity of O(Nlog2(N)). The input sequence for the FFT is divided
into two sequences in the following way:
Exercise 1:
Write a script to implement the equation X ( k )=G1 ( k )+ W kn G 2 ( k ) in MATLAB given only the
following two vectors of size N/2 each.
k
−j2π( )
W kN =e N
You may use the MATLAB function fft to check your results.
Exercise 2:
X (0) x ( 0)
=1 1 .
2- point FFT can be found as [ ][
X (1) ][ ]
1 −1 x ( 1 )
function y = fft_2pt(x,N)
% x : input vector of length 2
P a g e | 50
Lab manual of Digital Signal Processing
% if N == 2
% Calculate 2-point FFT of x
% 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
∞
X (z=) ∑ x n( )z− n
n=− ∞
Where, z is the complex variable. This equation is sometimes called direct z-transform
because it transforms the time-domain signal x (n) into its complex-plane representation X ( z)
X ( z)≡ Z {x (n )} . For convenience the z-transform of a signal x (n) is denoted by
The procedure of transforming z-transform to the time domain is called inverse z-transform.
The inversion formula for obtaining x (n)from X ( z) is
1
X (z )z n− zd
1
x n( =)
2jπ ∮
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)
:Exercise 1
1 n
h n( =) 5
4()u (n ) If
;num=[5]
;den=[1, -1/4]
zplane (num,den)
residue (num,den)=]r,p,c[
P a g e | 51
Lab manual of Digital Signal Processing
Inverse z-Transform
:Inspection Method
1
1 n X ( z )=
x n( =)
2()u (n ) The inverse z-transform of 1
1− z−1
2
is
Express G(z ) in a partial fraction expansion form and then determine g(n) by summing the
.inverse transform of the individual simpler terms in the expansion
:Example
1 1
X (z=) COR
, :|z|>
2
(1− 14 z )(1− 12 z )
−1 −1
−1 2 1
X (z=) + tiw
, h |z|>
1 1 2
( )(
1− z− 1 1− z− 1
4 2 )
n n
1 1
x n( =) 2 () ()
2
u n( −)
4
u n( ). :The inverse z-transform is given by
.And, this is a right sided sequence
:Exercise 2
z
X (z=) 2
3 z− 4 z+ 1
P a g e | 52
Lab manual of Digital Signal Processing
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
z
X (z=) 2
3 z− 4 z+ 1
0( + z− 1 )
X (z=)
3(− 4 z− 1+ z− 2 )
;num=[0,1];den=[3,-4,1]
zplane(num,den)
residue(num,den)=]r,p,c[
=r
0.5000
0.5000-
=p
1.0000
0.3333
=c
][
:Exercise 3
Find inverse z-transform by using MATLAB and by the method of partial fractions
.expansion for the following z-transforms
)1
1
1(− z−− 4 z− 2+ 4 z− 3 )
X (z=)
11 − 1 31 − 2 1 − 4
(1− z + z − z )
4 8 4
P a g e | 53
Lab manual of Digital Signal Processing
)2
z
X (z=) 3 2
(z + 2 z52.1
+ 52.0
z+ )
)3
3
(z− 3 z 2+ 4 z+ 1 )
X (z=) 3
(z− 4 z 2+ 6z−1.0 )
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
X (z=) −1 2 −1
1(−9.0 z ) 1( +
9.0 z )
;num = [1]
den = poly ([0.9, 0.9, -0.9])
;residue (num, den) = ]r, p, c[
:Exercise 4
.The z-transform X ( z) of a causal sequence x [n] can be expanded in a power series form .1
x. [n ] In the series expansion, the coefficient multiplying the term z−n is the n-th sample of .2
The power series expansion can be obtained by long division for a rational z-transform .3
−1
z . expressed as a ratio of polynomials in
:Example
1+ 2 z− 1
H (z=) 1
1+ 4 z−21.0
− z− 2
h n[ =] 1[6.1
, 25.0
−, 4.0
, 4222.0
−, …
, … rof
] , n≥ 0
P a g e | 54
Lab manual of Digital Signal Processing
1. The MATLAB function impz is used to find the inverse of a rational z-transform
G(z ).
2. This function computes the coefficients of the power series expansion of G(z ).
;num = [1 2]
;den = [1 0.4 -0.12]
;impz (num, den) = ]h, t[
;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(− z−− 4 z− 2+ 4 z− 3 )
X (z=)
11 − 1 31 − 2 1 − 4
(1− z + z − z )
4 8 4
MATLAB has a function freqz to plot the magnitude and phase response of a system in the
.Z-Domian
It returns theN-point frequency vector w and the N-point complex frequency response vector
H of the system, given its numerator and denominator coefficients in vectorsb∧a. It is
.evaluated at N -points equally spaced around the upper half of the unit circle
:Example
1
H (z=) ;|z|9>.0
1(−9.0 z− 1 )
:Pole-zero plot is made first
P a g e | 55
Lab manual of Digital Signal Processing
freqz(b,a,100) =]H,w[
figure
;magH=abs(H); phaH= angle(H)
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
syms n
S = ztrans(sinh(n))
nis
z h (1 )
2
z−hsoc
2 1( )z+ 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)
:Exercise 7
1. x ( n )=e n
2. f =sin( k )
3. f =a n , where a is any constant
f 1 n( =) a n
P a g e | 56
Lab manual of Digital Signal Processing
f 2 n( =)nis (n )
Zxa[ n[ +]yb [n =
] ] aX (z +Yb
) (z )
EXPERIMENT 11
Objective
To study the effect of reducing the harmonics from a recorded voice signal on the quality of
the original voice signal recorded.
P a g e | 57
Lab manual of Digital Signal Processing
Introduction
Let x (n) be a DT periodic signal, with period N 0. You can think of the collection
x [ 0 ] , x [ 1 ] , . … . , x [ N−1] as the entries of a vector v=( v 0 , v 1 , v 2 , … … v N −1 ) ∈ RN . Therefore, if
we want to define x (n) we just need to describe v. The discrete-time Fourier
series representation provides notions of frequency content of this discrete time signal which
is given by:
N− 1
x n( =)∑ a ke kj (2 π /N )n
k= 0
Exercise 1:
Record your voice with F s=16,000 using the command x=wavrecord( ). Plot this signal.
Now compute the DTFS using D=fft ( x). Plot the magnitude of the coefficients D[k ]. What
do you notice about these coefficients?
The terms corresponding to the D[k ] with small amplitude can be removed without much
loss.
Take a threshold value of 1, than take only the Fourier coefficients that have magnitude
greater than threshold. Find the inverse DTFS using x 2=ifft ( E) and plot both the original and
approximated signal.
Exercise 2:
Play with different threshold values i.e. 1, 2, 3, 4 so on to 10 and see what happens. How
many coefficients are you keeping in each case (i.e., how many of the elements of E are
non-zero)?
The concept of basis representation can be easily extended to two-dimensional signals that
are signals with two independent variables. An important such set of signals are images.
P a g e | 58
Lab manual of Digital Signal Processing
Consider the signal x [ n , m ] , where n , m=0 , 1 , … … , N −1.This signal can represent a digital
image, where x [n , m] is the intensity of the pixel with coordinates n and m.
Load a cameraman.mat file in the MATLAB which is a gray-scale image and display it. Now
take the DTFS of this signal by using D=fft 2 ( x ) . Notice that the D[k , l] matrix has the same
dimensions as x .
Look at the magnitude of D[k , l] matrix by displaying it, if is not visible than use log scale.
Also plot the phase of D[k , l]matrix. Organize all the coefficients in a vector and plot their
magnitudes and sort this vector. Construct a coefficient matrix D 2 where you zero-out the
smallest 90 percent coefficients. D 2has roughly only 10% of the non-zero entries. Now
compute the inverse DTFS by using ifft 2( D2).
Comment on the results. Is the reconstructed image relatively good? Note that the above
procedure is indeed compressing the image quite dramatically as instead of N 2 real numbers
you only have to store N 2 /10 complex numbers
EXPERIMENT 12
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.
P a g e | 59
Lab manual of Digital Signal Processing
Introduction
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.
Chebyshev Filter
P a g e | 60
Lab manual of Digital Signal Processing
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
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
Here, n is the order of filter. W P is normalized pass-band edge frequency. R P is the p-p ripple,
usually 0.5dB.
NB: stop-band ripple must be greater than pass-band ripple.
P a g e | 61
Lab manual of Digital Signal Processing
Exercise 3:
Run the code given above for low and high pass filter prototype and show the absolute and
phase plots on MATLAB.
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.
EXPERIMENT 13
Objective
In this lab you will learn how to use the MATLAB’s filter design and analysis tool ‘fdatool’
and how to implement an FIR (finite impulse response) filter on C6713 DSP Board.
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:
P a g e | 62
Lab manual of Digital Signal Processing
M −1
y [ n ] = ∑ h [ m ] . x [n−m]
m=0
Where,
1.1. MATLAB:
1. Select the Filter Design including its Type, Order M and Desired Frequency
Response. Types of filters can be:
a. low pass
b. high pass
c. band pass
d. band stop, ...
2. Decide on the realization structure.
3. Decide how the coefficients will be quantized and compute the quantized
coefficients.
1.2. CCS:
Launch the MATLAB. Then navigate to Filter Design & Analysis Tool (fdatool). Here
follow all the steps given in section 1.1above.
P a g e | 63
Lab manual of Digital Signal Processing
Direct form I, Direct form II, Transposed forms, Cascade, Parallel, Lattice, …
All have same input/output relationship
Choice of structure affects the computational complexity and how the
quantization errorsare manifested through the filter.
P a g e | 64
Lab manual of Digital Signal Processing
P a g e | 65
Lab manual of Digital Signal Processing
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:
P a g e | 66
Lab manual of Digital Signal Processing
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:
Band pass
8th order
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)
P a g e | 67
Lab manual of Digital Signal Processing
EXPERIMENT 14
Objective
In this lab, you will learn to implement a butterworth low pass order 2 IIR (Infinite impulse
response) filter on C6713.
Introduction
Where x (n)∧ y (n) is the input and output data, and a (k )andb (k ) are the filter coefficients.
The a (k )are auto-regressive (AR) coefficients (poles of the transfer function). The b (k ) are
moving-average (MA) coefficients (zeros of the transfer function). IIR filters generally have
nonlinear phase responses, but can meet the magnitude response specifications with much
lower orders than FIR filters. However, due to their nature of instability, care must be taken
in their design to meet the stability criteria. The prototype and requirements of the IIR
function follows:
x points to a floating point array of length nx which holds the input samples.
b points to a floating point array of length 3 which holds the MA coefficients:
b[0], b[1], and b[2]. b must be double-word aligned.
a points to a floating point array of length 2 which holds the AR coefficients:
a[0] and a[1]. a must be double-word aligned.
delay points to a floating point array of length 2 which holds the delay
coefficients: d[0] and d[1]
r points to a floating point array of length nx which holds the output samples.
nx is the length of the coefficient array. nx must be greater than or equal to 4.
P a g e | 68
Lab manual of Digital Signal Processing
This example demonstrates the use of the C67x DSPLIB IIR filtering capabilities.
First, filter coefficients are generated in MATLAB using the Filter Design and Analysis Tool
(MATLAB command: fdatool) with filter specifications listed below. The frequency response
of this FIR filter is shown in the Figure below:
Input data to the IIR filter are generated in floating point format as follows:
Where F 1∧F 2 are the two input data frequencies and F s is the sampling frequency (44,100
Hz). Figure 2 and Figure 3 show the results of the IIR filter.
Figure 2 shows a sinusoidal input described earlier where F 1=370 Hzand F 2=18,500 Hz .
Since 18,500 Hz is above the cut-off frequency, this frequency is attenuated and only a
370 Hz sinusoidal wave remains as shown in Figure 3.
P a g e | 69
Lab manual of Digital Signal Processing
P a g e | 70
Lab manual of Digital Signal Processing
With the data in the L2 SRAM, the observed cycle count is very similar to the formula cycle
count. The discrepancy is realized when call overhead, L1D read misses, and L1D write
misses are taken into account.
Exercise 1:
2. There are four different filter coefficients saved in four *.dat files. Provide the time and
frequency plots for each.
3. Apply a signal from MATLAB and show the effect on the signal after it passes through
each of these filter(s).
P a g e | 71
Lab manual of Digital Signal Processing
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
P a g e | 72
Lab manual of Digital Signal Processing
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.”
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.
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
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.
P a g e | 73
Lab manual of Digital Signal Processing
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.
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 missing ground prong and outlet cover, pinched wires, damaged
casings on electrical outlets.
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.
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.
Observe good housekeeping practices. Work areas should be kept clean and
tidy at all times.
P a g e | 74
Lab manual of Digital Signal Processing
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.”
P a g e | 75
Lab manual of Digital Signal Processing
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.
6. Application: Suggest a real world application where this exercise may apply.
Note: Your report should be of maximum 3 pages. Write your roll number and section on top.
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
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.
P a g e | 76
Lab manual of Digital Signal Processing
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:
%|---------------------------------|
%|This function sorts vector u in increasing order, returning the sorted vector as v. |
%|If itype= 'd', decreasing order & If itype = 'i', increasing order |
%|---------------------------------|
n = length(u);
%Copy vector u to v9
v = u;
ifitype == 'i'
P a g e | 77
Lab manual of Digital Signal Processing
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
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
P a g e | 78
Lab manual of Digital Signal Processing
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:
Applications:
P a g e | 79