Beruflich Dokumente
Kultur Dokumente
LAB MANUAL
DEPARTMENT OF ELECTRICAL
ENGINEERING,
FAST-NU, LAHORE
Lab manual of Digital Signal Processing
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|Page
Lab manual of Digital Signal Processing
List of Equipment
2 USB Cable
4 AC Power Cord(s)
3|Page
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.
Software Tools
1. MATLAB R2016a
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:
4|Page
Lab manual of Digital Signal Processing
The output of the above code looks like the Figure 1.2 shown below:
1. Write the function in MATLAB. Briefly explain what you understand by the command
‘find’.
5|Page
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 𝑧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 ).
𝑥(𝑛 + 𝑁)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
7|Page
Lab manual of Digital Signal Processing
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:
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
Objective
In this experiment you will become familiar with a development system for programming DSP
hardware in order to implement DSP operations.
Equipment
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.
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.
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
10 | P a g e
Lab manual of Digital Signal Processing
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.
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.
11 | P a g e
Lab manual of Digital Signal Processing
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
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.
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
13 | P a g e
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 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
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:
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()
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
DSK6713_LED_off(3);
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
3. Load the source file led.c by going on File> Source. See Figure 2.6.
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.
20 | P a g e
Lab manual of Digital Signal Processing
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:
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
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
𝑥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
Exercise2:
𝑥1 (𝑡) = cos(2π10)t
𝑥2 (𝑡) = 2𝑐os(2π50)𝑡
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:
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 𝐹𝑠 .
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)
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
Question 1:
and
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
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
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;
Plot (SNR)
Table-1
30 | P a g e
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.
Software Tools
1. MATLAB R2016a
Introduction
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……}, 𝑵 = 𝟒
31 | P a g e
Lab manual of Digital Signal Processing
where,
𝒙𝒏 − 𝒊𝒏𝒑𝒖𝒕 𝒗𝒆𝒄𝒕𝒐𝒓 𝒊𝒏 𝒕𝒊𝒎𝒆 𝒅𝒐𝒎𝒂𝒊𝒏
𝑪𝒌 − 𝑭𝒐𝒖𝒓𝒊𝒆𝒓 𝒄𝒐𝒆𝒇𝒇𝒊𝒄𝒊𝒆𝒏𝒕𝒔
Exercise 3:
function y = IDTFS(Ck, N)
where,
𝑪𝒌 − 𝑭𝒐𝒖𝒓𝒊𝒆𝒓 𝒄𝒐𝒆𝒇𝒇𝒊𝒄𝒊𝒆𝒏𝒕𝒔
𝑵 − 𝑭𝒖𝒏𝒅𝒂𝒎𝒆𝒏𝒕𝒂𝒍 𝒑𝒆𝒓𝒊𝒐𝒅 𝒐𝒇 𝒓𝒆𝒑𝒆𝒕𝒊𝒕𝒊𝒐𝒏
Exercise 4:
Exercise 5:
Exercise 6:
Linearity property
32 | P a g e
Lab manual of Digital Signal Processing
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
𝑥(𝑛)=[3 2 1 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
𝑥(𝑛)=[3 2 1 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)
𝑥(𝑛)=[3 2 1 0]
33 | P a g e
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 𝒙(𝒏) 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
𝑋(𝑤) = ∑ 𝑥(𝑛)𝑒 −𝑗𝜔𝑛 .
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?
34 | P a g e
Lab manual of Digital Signal Processing
Exercise 3:
Exercise 4:
𝟏 +𝝅
𝒙[𝒏] = ∫ 𝑿(𝒆𝒋𝝎 )𝒆𝒋𝝎𝒏 𝒅𝝎
𝟐𝝅 −𝝅
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.
𝟏 𝟐𝝅
𝟐 𝟐
𝑬 = ∑|𝒙(𝒏)| = ∫ |𝑿(𝒆𝒋𝝎 )| 𝒅𝝎 , −∞ < 𝑛 < +∞
𝟐𝝅 𝟎
𝜔 = 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.
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.
𝒙∗ (𝒏) → 𝑿∗ (−𝝎)
36 | P a g e
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.
Equipment
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:
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:
𝒏=+∞
Exercise 3:
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]
38 | P a g e
Lab manual of Digital Signal Processing
Convolution is important because it relates the three signals of interest: the input signal, the
output signal, and the impulse response.
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;
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.
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
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
𝑋(𝑘) is obtained by sampling the DTFT i.e 𝑋(𝜔) after every 2𝜋/𝑁 interval.
𝟏
𝒙(𝒏) = ∑ 𝑿(𝒌). 𝒆𝒋𝟐𝝅𝒌(𝒏/𝑵) , 𝒌 = 𝟎: 𝑵 − 𝟏; 𝒏 = 𝟎: 𝑵 − 𝟏
𝑵
𝒌
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:
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.
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
Write your own MATLAB function to circularly shift a sequence (do not use circshift built in
function). Your code must be generic.
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.
𝑵−𝟏
% N buffer size
% fold one sequence to get 𝒙(−𝒏)and then multiply it’s shifted version with the
unfolded sequence accordingly to get 𝒚(𝟏), 𝒚(𝟐), … . . 𝒚(𝑵)
44 | P a g e
Lab manual of Digital Signal Processing
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.
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.
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:
Find DFT and DTFS of the above signal and plot them on MATLAB.
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 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:
𝑥2 = [3 7] for 𝑛2 =[0 1]
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;
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
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.
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.
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
𝑁
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:
Exercise 1:
Write a script to implement the equation 𝑋(𝑘) = 𝐺1 (𝑘) + 𝑊𝑛𝑘 𝐺2 (𝑘) in MATLAB given only
the following two vectors of size N/2 each.
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)
function y = fft_2pt(x,N)
% x : input vector of length 2
% if N == 2
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.
Inverse z-Transform
𝒏=+∞
Inspection Method:
1 1 𝑛
The inverse z-transform of 𝑋(𝑧) = 1 −1
is 𝑥(𝑛) = (2) 𝑢(𝑛)
1− 𝑧
2
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
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=
[]
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:
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
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 𝐺(𝑧).
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 )
MATLAB has a function freqz to plot the magnitude and phase response of a system in the
Z-Domian.
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.
Example:
1
𝐻(𝑧) = ; |𝑧| > 0.9
(1 − 0.9𝑧 −1 )
Pole-zero plot is made first:
[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:
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)
Exercise 7:
1. x(n) = en
2. 𝐟 = 𝐬𝐢𝐧(𝐤)
3. 𝐟 = 𝐚𝐧 , 𝐰𝐡𝐞𝐫𝐞 𝐚 𝐢𝐬 𝐚𝐧𝐲 𝐜𝐨𝐧𝐬𝐭𝐚𝐧𝐭
f1 (n) = an
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
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
𝑛 is the order of filter. 𝑊𝑃 is normalized pass-band edge frequency. 𝑅is the p-p ripple, usually
0.5dB.
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.
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
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.
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.
57 | P a g e
Lab manual of Digital Signal Processing
EXPERIMENT 12
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
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,
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:
58 | P a g e
Lab manual of Digital Signal Processing
Note that all math here is floating point. Filter coefficients are also assumed to be floating
point
Exercise 1:
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)
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 ( )
𝜋𝑛−𝜋𝑛𝑑
60 | P a g e
Lab manual of Digital Signal Processing
ℎ(𝑛) = 𝑠𝑖𝑛𝑐(𝜔𝑐 ∗ 𝑛)
𝑥(𝑛) = cos(𝜔𝑛)
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(ω-π)
61 | P a g e
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.
62 | P a g e
Lab manual of Digital Signal Processing
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
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.
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.
64 | P a g e
Lab manual of Digital Signal Processing
Observe good housekeeping practices. Work areas should be kept clean and
tidy at all times.
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
1. Introduction: Introduce the new commands being used, and their significance.
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
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:
%|---------------------------------|
%|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
67 | P a g e
Lab manual of Digital Signal Processing
v = u;
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:
Applications:
69 | P a g e