EEE-314 Software Based
EEE-314 Software Based
(Software Based)
EEE-314-1 | P a g e
Introduction
Signal generation and visualization, transformations on signals. Convolution and correlation and their
application. Z-transformation, analysis systems using z-transformation. Fourier series and
transformation, analysis of signals and systems using Fourier series and transformation. Design of
digital filters.
1. Course Objectives
This course will introduce the basic concepts and techniques for processing signals. Students will be
familiar with the most important methods in DSP, including digital filter design and transform-
domain processing and analyzing. The computer-based experiments extend better understanding and
develop practical problem-solving skills.
2. Course Outcomes
Upon completion of this course students will be able to:
CO1: Use MATLAB to generate signals, describe systems, apply different types of signal
transformations such as shifting, scaling, folding and perform convolution and correlation.
CO2: Analyze discrete time systems in time and frequency domain using signal processing and
symbolic toolboxes of MATLAB.
CO3: Design different discrete time systems to meet specific practical requirements and limitations.
CO5: Communicate and share knowledge, data, information, results etc. with others
3. Text Book
1. John Proakis. G., Dimtris G Manolakis, Digital Signal Processing - Principles, Algorithms and
Application, PHI, 2009.
2.John G Proakis and Vinay K. Ingle, Digital Signal Processing Using MATLAB, PWS Publishing
Company, 1997.
4. References
[1] Michael Weeks, Digital Signal Processing Using MATLAB & Wavelets, Infinity Science
Press, 2007.
EEE-314-2 | P a g e
[2] Jose Maria Giron-Sierra, Digital Signal Processing with MATLAB Examples, Volume 1:
Signals and Data, Filtering, Non-stationary Signals, Modulation, Springer Singapore, 2018.
[3] Samuel D. Stearns, Digital Signal Processing with Examples in MATLAB, CRC Press, 2016.
5. Weekly Schedule
Expt. No. Experiment Name
Week No. Page No.
1 Review of MATLAB Week1
2 Generation and visualization of continuous-time Week2
and discrete-time signals
Generation of basic discrete-time signals and
3 inspection of discrete-time sinusoid frequency Week3
properties.
4 Operations on discrete-time signals Week4
5 Discrete-time convolution summation Week5
6 Discrete-time correlation Week6
Mid Exam
Week7
EEE-314-3 | P a g e
Experiment No. 01:
Name of the Experiment: Review of MATLAB
Objective:
The objectives of this experiment are to:
1) Get refamiliarized with the MATLAB environment.
2) learn about important functions needed for digital signal processing lab.
Domain /
Delivery
Corresponding level of Assessment
CO Statement methods and
PO learning tools
activities
taxonomy
CO1:Use
MATLAB to Lab tests
generate signals, Simulation Lab reports
describe systems,
apply different Application(PO Experiment Final lab
Affective test
types of signal 3) Practice lab
domain/
transformations Modern Tool Open ended
valuing level Group
such as shifting, Usage (PO5) lab
scaling, folding discussion
and perform Project
Tutorial
convolution and show& project
correlation. presentation
Theory:
Students are required to go through the steps explained below and then complete the exercises given
at the end of the lab. Remember, this is not an introductory course to MATLAB. You already have
been introduced to MATLAB in EEE 204 (Introduction to MATLAB). This is just to reengage you
with the environment.
Defining a scalar x =1
x=
1
Defining a column vector v = [1;2;3]
v=
1
2
3
Defining a row vector w = [1 0 1]
w=
101
Transpose a vector wT = w’
wT =
1
0
1
Defining a range for a X = 1:.5:5
vector X=
Columns 1 through 7
1.0000 1.5000 2.0000 2.5000 3.0000 3.5000 4.0000
Columns 8 through 9
4.5000 5.0000
Empty vector Y = []
Y=
[]
Defining a matrix M = [1 2 3; 3 2 1]
M=
1 2 3
3 2 1
Matrix of zeroes M = zeros(2,3) % 1st parameter is the number of row, 2nd
parameter is the number of column.
M=
0 0 0
0 0 0
Matrix of ones m = ones(2,3)
m=
EEE-314-5 | P a g e
1 1 1
1 1 1
The identity matrix I = eye(3)
I=
1 0 0
0 1 0
0 0 1
Define a random matrix R = rand(1,3)
or vector R=
0.9501 0.2311 0.6068
Access a vector or matrix R(3)
ans=
0.6068
R(1,2)
ans =
0.2311
Access a row or column I(2,:) %2nd row
of matrix ans =
0 1 0
I(1:2,1:2)
ans =
1 0
0 1
Size and length of matrix size(R)
ans =
13
length(R)
ans =
3
Arithmetic operations
x =[ 1 2 3 4 5]
x=
12345
x=2*x
x=
2 4 6 8 10
x=x/2
x=
12345
y=[12345]
y=
12345
z=x+y
z=
2 4 6 8 10
Matlab has a large number of built in functions, some operate on each point of avector/matrix:
log([1 2 3 4])
ans =
0 0.69311.0986 1.3863
a =[1 4 6 3]
EEE-314-7 | P a g e
a=
1 463
sum(a)
ans =
14
mean(a)
ans =
3.5000
std(a)
ans =
2.0817
max(a)
ans =
6
a = [1 2 3; 4 5 6]
mean(a) %mean of each column
max(a) %max of each column =20
max(max(a)) %to obtain max of matrix
Operator Description
== Equal to
~= Not equal to
< Less than
> Greater than
<= Less than or equal to
>= Greater than or equal to
Let
a = [1 1 3 4 1]
a=
11341
ind = (a == 1)
ind =
11001
ind = (a < 1)
ind =
EEE-314-8 | P a g e
00000
ind = (a > 1)
ind =
00110
ind = (a <= 1)
ind =
11001
ind = (a >= 1)
ind =
11111
ind = (a ~= 1)
ind =
00110
The commands between the forand endstatements are executed for all values stored in the array.
Suppose that one-need values of the sine function at eleven evenly spaced pointsn/10, for n = 0, 1,
…, 10. To generate the numbers in question one can use the for loop.
for n=0:10
x(n+1) = sin(pi*n/10);
end
x=
Columns 1 through 7
00.30900.58780.80900.95111.00000.9511
Columns 8 through 11
0.80900.58780.30900.0000
EEE-314-9 | P a g e
H = zeros(5);
for k=1:5
for l=1:5
H(k,l) = 1/(k+l-1);
end
end
H=
1.00000.50000.33330.25000.2000
0.50000.33330.25000.20000.1667
0.33330.25000.20000.16670.1429
0.25000.20000.16670.14290.1250
0.20000.16670.14290.12500.1111
q = pi;
while q > 0.01
q = q/2;
end
q=
0.0061
This construction is used if there is one alternative only. Two alternatives require the construction:
if expression
commands (evaluated if expression is true)
else
commands (evaluated if expression is false)
end
If there are several alternatives one should use the following construction:
EEE-314-10 | P a g e
if expression1
commands (evaluated if expression 1 is true)
elseif expression 2
commands (evaluated if expression 2 is true)
elseif
...
...
else
commands (executed if all previous expressions are false)
end
Note: use of the curly braces after the word case. This creates the so called cell array rather than the
one-dimensional array, which requires use of the square brackets.
Enter this code in the MATLAB editor and save it as firstgraph.m. This function call be
called from command line as
firstgraph
Here is an example of a function file
function [b, j] = descsort(a)
% Function descsort sorts, in the descending order, a real array a.
% Second output parameter j holds a permutation used to obtain
% array b from the array a.
[b ,j] = sort(-a);
b = -b;
Enter this code in the MATLAB editor and save it as descsort.m. This function call be called from
command line as
X=1:10
descsort(X)
Graphs in MATLAB
Plotting a single graph
Save the script file as graph1.m and the run it from the command window or clicking Run button
on the editor menu.
Here, we are plotting the graph of the rational function y = x/(1+x^2) using 50 values of x starting
from -2 and ending at 2. The linspace function is used here to generate the values of x.
N = 50;
x = linspace(-2,2,N);
y = x./(1+x.^2);
plot(x,y,'r')
title(sprintf('Graphbased upon %g points.',N))
axis([-2,2,-.8,.8])
xlabel('x')
ylabel('y')
EEE-314-12 | P a g e
grid
Fig. 1
for i = 1:4
N = i*5;
x = linspace(-2,2,N);
y = sin(x);
subplot(2,2,i)
plot(x,y,'r')
title(sprintf('Graph based upon %g points.',N))
axis([-2,2,-1,1])
xlabel('x')
ylabel('y')
grid
end
EEE-314-13 | P a g e
Fig. 2
EEE-314-14 | P a g e
b. Write a function: Create a new m file following the procedure of above. Type in the
commands:
function g = myfunction(x,y)
g = x + y;
and then save it as myfunction.m
ii. Run command clear all to remove all variables from memory
iii. Run the commands one by one:
x = 1:5;
y = 6:10;
myfunction
z = myfunction(x,y)
g
a = 1:10;
b = 2:11;
myfunction(a,b)
In each case observe and learn from the errors raised by MATLAB.
Precautions:
1) Follow the software instructions and lab manual for using the software.
2) Be careful while input the variables value before run the code.
3) Always work in the editor environment. This will you to edit the Matlab Code.
4) Do not turn off your pc or laptop while simulating the design.
5) Check your code with the desired input data.
6) Never hurry. Hurry can cause error in simulation.
7) After simulation collect all the data and graphs carefully, take screen shot if necessary.
Data Analysis:
Report:
1. Submit the complete data sheet with the screenshots of Matlab code and Output Graphs.
2. Using various variables value complete the data table, observe the output graphs and write a
report
References
EEE-314-15 | P a g e
1) Li Tan, Purdue University, Jean Jiang, Purdue University “Digital Signal Processing:
Fundamentals and Applications’’.
2) Website: https://www.mathworks.com/products/matlab.html
EEE-314-16 | P a g e
Experiment No.02
Name of the Experiment: Generation and Visualization of continuous-time and discrete-time
signals.
Objective:
The objectives of this experiment are to:
1. learn how to generate continuous and discrete-time signals.
2. inspect the relationship between continuous and discrete-time signals.
3. get familiarized with the concept of sampling.
Domain /
Delivery
Corresponding level of Assessment
CO Statement methods and
PO learning tools
activities
taxonomy
CO1:Use
MATLAB to Lab tests
generate signals, Simulation Lab reports
describe systems,
apply different Application Experiment Final lab
Affective test
types of signal (PO3) Practice lab
domain/
transformations Modern Tool Open ended
valuing level Group
such as shifting, Usage (PO5) lab
scaling, folding discussion
and perform Project
Tutorial
convolution and show & project
correlation. presentation
Theory:
Here, 𝑥𝑎 (𝑡) is the continuous-time signal (which is a function of time, 𝑡), 𝐴 is the amplitude, Ω is the
angular frequency (unit is 𝑟𝑎𝑑𝑖𝑎𝑛/𝑠𝑒𝑐), 𝐹 is the frequency (unit is 𝐻𝑧), 𝑡 is time and 𝜃 is the phase
(unit is 𝑟𝑎𝑑𝑖𝑎𝑛).
The number of cycles or oscillations per second is called the frequency (𝐹). In fig. 1 there are 2 cycles
in 1 𝑠𝑒𝑐, so the frequency is 2𝐻𝑧. The inverse of frequency is time period (𝑇𝑝 ), whose unit is 𝑠𝑒𝑐.
So, 𝑇𝑝 = 1⁄𝐹 . Time period is the time required for one complete cycle. Here in fig. 1 we can see that
EEE-314-17 | P a g e
one cycle takes 0.5 𝑠𝑒𝑐 to complete. So, in this case time period (𝑇𝑝 ) is 0.5 𝑠𝑒𝑐. Alternatively, as the
frequency is 2 𝐻𝑧 time period (𝑇𝑝 ) = 1⁄𝐹 = 1⁄2 = 0.5 𝑠𝑒𝑐.
In continuous-time signals time(𝑡) can take any value from −∞ to +∞. In other words, there will be
a 𝑥𝑎 (𝑡) for every value of 𝑡. You will get a value for 𝑥𝑎 (𝜋), 𝑥𝑎 (0.30874), 𝑥𝑎 (√2), etc.
Discrete-time signals have values only on fixed intervals of time. For example, fig. 2 depicts a
discrete-time signal which has values on 0 𝑠𝑒𝑐, 0.125 𝑠𝑒𝑐, 0.25 𝑠𝑒𝑐, 0.375 𝑠𝑒𝑐, 0.5 𝑠𝑒𝑐, 0.625 𝑠𝑒𝑐,
0.75 𝑠𝑒𝑐, 0.875 𝑠𝑒𝑐, 1 𝑠𝑒𝑐, etc. In this particular example the values are coming after a fixed interval
of 0.125 𝑠𝑒𝑐. It is called the sampling interval (𝑇). The signal in fig. 2 is actually created by taking
values or samples every𝑇 𝑠𝑒𝑐 from the signal in fig. 1.We do not know the value of the discrete-time
signal in fig. 2 at 𝑡 = 0.1 𝑠𝑒𝑐 because we didn’t take the value at that time from the signal in fig. 1.
Alternatively, we can say that we took 8 𝑠𝑎𝑚𝑝𝑙𝑒𝑠 per 𝑠𝑒𝑐 or took samples at the rate of 8 𝐻𝑧 from
the continuous-time signal in fig. 1 to create the discrete-time signal in fig. 2. It is called the sampling
rate or sampling frequency (𝐹𝑠 ). Sampling rate or frequency is the inverse of sampling interval.
where,𝑘 is an integer. Unit of 𝑓 is 𝑐𝑦𝑐𝑙𝑒𝑠 𝑝𝑒𝑟 𝑠𝑎𝑚𝑝𝑙𝑒. We can say that there is
1⁄8 𝑐𝑦𝑐𝑙𝑒𝑠 𝑝𝑒𝑟 𝑠𝑎𝑚𝑝𝑙𝑒. So, in this case frequency (𝑓) is 1⁄8. If we compare this to the time
equation above, we get 𝑘 = 1 and 𝑁 = 8.
In discrete-time signals time(𝑡) can take any value from −∞ to +∞. In other words, there will be a
𝑥𝑎 (𝑡) for every value of 𝑡. You will get a value for 𝑥𝑎 (𝜋), 𝑥𝑎 (0.30874), 𝑥𝑎 (√2), etc.
with eight samples marked, sequentially obtained every 0.125 second. Alternatively, we can say that
we took 8 samples per second and it is called the sampling frequency 𝐹𝑠 . For this particular example
𝐹𝑠 is 8 Hz.ThesignalvaluesinputtotheADCatsampletimes0, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75,
etc., are 0, 0.707, 1, 0.707, 0, -0.707, -1, etc.
The samples within a given sample sequence are normally indexed by the numbers 0, 1, 2, 𝑒𝑡𝑐.which
represent multiples of the sampling period or sampling interval𝑇. For example, in Fig. 1 we note that
the sample period is 0.125 second, and the actual sampling times are therefore 0 sec., 0.125 sec., 0.25
sec., etc. The continuous sine function shown has the value:
EEE-314-18 | P a g e
𝑥(𝑡) = sin(2𝜋𝐹𝑡)
Where 𝑡 is time, 𝐹is the continuous-time frequency, and in this particular case, 𝐹 = 1𝐻𝑧. Sampling
occurs at times 𝑛𝑇where 𝑛 = 0, 1, 2, … and 𝑇 = 0.125 𝑠𝑒𝑐𝑜𝑛𝑑. The sample values of the sequence
would therefore be 𝑠𝑖𝑛(0), 𝑠𝑖𝑛(2𝜋(𝑇)), 𝑠𝑖𝑛(2𝜋(2𝑇)), 𝑠𝑖𝑛(2𝜋(3𝑇)), 𝑒𝑡𝑐., and we would then say
that 𝑥(0) = 0, 𝑥(1) = 0.707, 𝑥(2) = 1.0, 𝑥(3) = 0.707, 𝑒𝑡𝑐. where 𝑥(𝑛)denotes the
𝑛𝑡ℎ sequence value, the amplitude of which is equal to the underlying continuous function at time
𝑛𝑇(note that brackets surrounding a function argument mean that the argument can only assume
discrete values, while parentheses surrounding an argument indicate that the argument’s domain is
continuous).
𝑥(𝑛) = sin(2𝜋𝐹𝑛𝑇)
Fig. 1: An analog or continuous-domain sine wave, with eight samples per second marked.
This sequence of values, the samples of the sine wave, can be used to completely reconstruct the
original continuous domain sine wave using a DAC. There are, of course, a number of conditions to
ensure that this is possible, and they are taken up in detail in the next lab. To compute and plot the
sample values of a 2-Hz sine wave sampled every 0.05 second on the time interval 0 to 1.1 second,
write the following MATLAB code in the command window:
t = [0:0.05:1.1];
figure;
stem(t, sin(2*pi*2*t))
where the 𝑡vector contains every sample time 𝑛𝑇with 𝑇 = 0.05. Alternatively, we might write:
EEE-314-19 | P a g e
T = 0.05;
n = 0:1:22;
figure;
stem(n*T, sin(2*pi*2*n*T))
Fig. 2: A plot of the samples of a sine wave having frequency 2 Hz, sampled every 0.05 second up
to time 1.1 second.
We saw above that a sine wave of frequency 𝐹 periodically sampled at the sampling interval𝑇 can
be represented as:
where, 𝑓 = 𝐹𝑇 = 𝐹 ⁄𝐹𝑠 and is called the discrete-time frequency. Once we have a sampled sine
wave, we can mathematically express it without reference to the sampling period by defining the
sequence length as𝑁.𝑁 is the discrete-time time period. We would then have, in general,
𝑥(𝑛) = sin(2𝜋𝑛(𝑘⁄𝑛))
where, 𝑓 = 𝑘/𝑁. 𝑛 is the sample index, which runs from 0 to 𝑁 − 1, and 𝑘 is the number of cycles
over the sequence length 𝑁. For the sample sequence marked in Fig. 1, we would have,
So, here the discrete frequency (𝑓) = 1⁄8 and the discrete time period (𝑁) = 8. Note that there are
two full cycles of the sine over 16 samples (the 17th sample is the start of the third cycle).
EEE-314-20 | P a g e
The correctness of this formula can be verified by noting that for the 17th sample, 𝑛 = 16, and
𝑥(16) = 0, as shown.
Picking another sample, for 𝑛 = 2, we get, 𝑥(2) = sin(2𝜋2(2⁄16)) = sin(𝜋⁄2) = 1, as shown.
A phase angle is sometimes needed, and is denoted 𝜃by in the following expression:
𝑥(𝑛) = sin(2𝜋𝑛(𝑘⁄𝑁) + 𝜃)
Note that, if we shift a sin wave by 𝜋/2 radians we get cosine wave.
We can illustrate this by generating and displaying a sine wave having three cycles over 18 samples
with a phase angle of 𝜋/2 radians, and finally a cosine wave having three cycles over 18 samples
and a zero phase angle. A suitable MATLAB code is given below, which results in Fig. 3.
n = 0:1:17;
x = sin(2*pi*n*(3/18) + pi/2);
subplot(2,1,1);
stem(n,x);
y = cos(2*pi*n*(3/18));
subplot(2,1,2);
stem(n,y);
Fig. 3: (a) sine wave with phase angle of 𝜋/2 radians, (b) cosine wave with phase angle 0 radians
Problem 01:
Write a MATLAB script to plot the signal 𝑥(𝑛) = cos(𝜔𝑜 𝑛) for 𝜔𝑜 = 0, 𝜋⁄16 , 𝜋⁄8, 𝜋⁄4, 𝜋⁄2
and 𝜋. The output should look like the Figure 4.
EEE-314-21 | P a g e
Fig. 4: Signal 𝑥(𝑛) = cos(𝜔𝑜 𝑛) for various values of angular frequency 𝜔𝑜 .
Problem 02:
Write a MATLAB script to plot the signal 𝑥(𝑛) = 𝐶𝑎𝑛 for,
(i) 𝐶 and 𝑎 are real for 𝑎 > 1, 0 < 𝑎 < 1, 𝑎 = 1, 𝑎 < −1,−1 < 𝑎 < 0 and 𝑎 = −1.
(ii) 𝐶iscomplex and 𝑎 is complex with unity magnitude. [𝐶 = 𝐴𝑒 𝑗𝜃 and 𝑎 = 𝑒 𝑗𝜔 ]
(iii) 𝐶 is complex and 𝑎 is complex with unity magnitude. [𝐶 = 𝐴𝑒 𝑗𝜃 and 𝑎 = 𝑒 𝜎+𝑗𝜔 ]
The output for (i) should look like the Figure 5.
Try (ii) and (iii) for yourself and comment on the output.
Precautions:
1) Follow the software instructions and lab manual for using the software.
2) Be careful while input the variables value before run the code.
EEE-314-22 | P a g e
3) Always work in the editor environment. This will you to edit the Matlab Code.
4) Do not turn off your pc or laptop while simulating the design.
5) Check your code with the desired input data.
6) Never hurry. Hurry can cause error in simulation.
7) After simulation collect all the data and graphs carefully, take screen shot if necessary.
Data Analysis:
Report:
1) Submit the complete data sheet with the screenshots of Matlab code and Output Graphs.
2) Using various variables value complete the data table, observe the output graphs and write a
report
References
1) Li Tan, Purdue University, Jean Jiang, Purdue University “Digital Signal Processing:
Fundamentals and Applications’’.
2) Website: https://www.mathworks.com/products/matlab.html
EEE-314-23 | P a g e
Experiment No. 03:
Objective:
The objectives of this experiment are to:
1. learn how to generate continuous and discrete-time signals.
2. inspect the relationship between continuous and discrete-time signals.
3. get familiarized with the concept of sampling.
Domain /
Delivery
Corresponding level of Assessment
CO Statement methods and
PO learning tools
activities
taxonomy
Lab tests
CO1: Analyze
discrete time Simulation Lab reports
systems in time Experiment Final lab
Application
and frequency Affective test
(PO3) Practice lab
domain using domain/
Modern Tool Open ended
signal processing valuing level Group
Usage (PO5) lab
and symbolic discussion
toolboxes of Project
MATLAB Tutorial
show & project
presentation
Theory:
EEE-314-24 | P a g e
Required Devices & Software:
Example 01: Write a MATLAB script to generate and plot a unit impulse sequence over the
duration −𝟓 ≤ 𝒏 ≤ 𝟓.
n = -5:5;
delta = n==0;
stem(n, delta);
Relational operators produce zero if the expression is false and one if the expression is true. The
expression𝑛 == 0impliesthevalueofnis0.Here,𝑛 = {−5, −4, −3, −2, −1,0,1,2,3,4,5}. So, there
are 11 values for n and the expression 𝑛 == 0is true for only one value of 𝑛and false for the rest
of the values of 𝑛. So, the expression 𝑛 == 0will produce 0 for 𝑛 = −5, 0 for𝑛 = −4,0for𝑛 =
−3,etc.Itwillproduce1onlyfor𝑛 = 0.Inthisway,thevaluesofdelta is{0,0,0,0,0,1,0,0,0,0,0}.
Practice Problem 01: Write a MATLAB script to generate and plot 𝛿(𝑛 − 3)over the
duration −10 ≤ 𝑛 ≤ 10.
[Hint: The value if delta will be 1 only at 𝑛 = 3.]
We can also create a MATLAB function to generate unit impulse sequence as it is a widely used
signal. We will have to use this signal a lot of times in future lab experiments. Creating a function
will allow us to generate impulse signal with a single line ofcode.
Create and save the code below as impseq.m. You can name it anything you want but there are a
few rules for naming i.e. names cannot contain empty spaces and a few special characters, the first
character cannot be a digit. And names should not be the same as any existing MATLAB function
names. For example, you should not name a function plot as there is already a function named
plot in MATLAB. Remember, the name of a function and the name of the file that contains the
function will have to be exactly the same. In this case, the name of the function is impseq. So, the
name of the saved file will have to be impseq.m. “.m” is the extension for MATLAB scripts and
function files.
Here, n1 is the starting index and n2 is the ending index. n0 is the index where the value of impulse
EEE-314-25 | P a g e
sequence is 1.
Once saved, you can call the function from the command window or any MATLAB script. The
function file will have to be on the current directory though.
For example, write the code below and observe that it does the same thing as the code in Example
01.
[delta, n] = impseq(-5,5,0);
stem(n, delta)
Unit Stepsequence:
Unit set signal is defined as:
1, 𝑛≥0
𝑢(𝑛) = {
0, 𝑛<0
A time shifted unit step signal can be defined as:
1, 𝑛 ≥ 𝑛0
𝑢(𝑛 − 𝑛0 ) = {
0, 𝑛 < 𝑛0
n = -10:10;
u = n>=3;
stem(n, u);
As we created MATLAB function for the unit impulse sequence, similar function for the unit step
signal can also be created. Try it yourself.
Practice Problem 02: Write a MATLAB script to generate and plot the signal provided
belowovertheduration−10≤n≤10. Useimpseqandstepseqfunctionstocompletethe task.
𝑥 (𝑛) = 𝑛(𝑢(𝑛) − 𝑢(𝑛 − 6)) + 3 𝛿(𝑛 − 3)
[Hint: Create and save the stepseq function and then just combine all the codes above.]
Exponential signal:
Any signals having the following general equation is called an exponential signal:
𝑥 (𝑛) = 𝑎 𝑛
a can have any value, real or complex. If a is real then the exponential signal itself will be real. The
shape of exponential signals can vary widely depending on the value of a.
EEE-314-26 | P a g e
Example 03: Write a MATLAB script to generate and plot the exponential signal provided
below over the duration −𝟓 ≤ 𝒏 ≤ 𝟓.
n = -5:5;
a = 0.9;
x = a.^n;
stem(n, x);
Practice Problem 04: Write a MATLAB script to plot the signal 𝑥(𝑛) = 𝑎𝑛 for 𝑎 =
𝑒 0.1𝑗 , 𝑎 = 𝑒 0.1 and 𝑎 = 𝑒 0.1+0.1𝑗 .
[Hint: As some of the values of a are complex, we will have to plot the real and imaginary parts
separately. Use the function real and imagin this cause.]
EEE-314-27 | P a g e
Non-sinusoidal periodic sequences:
Sinusoids are periodic sequences and we explored them in the previous lab. There are a lot of non-
sinusoidal periodic sequences too. For example, saw tooth, square, triangular, etc.
There are MATLAB functions for generating these signals. But we should try to code from scratch.
One approach is to create one period of a signal then just repeat it by copying. There is a MATLAB
function named repmatfor this particular task.
Write the following code in the command window and observe the value of B. B will be a matrix
created by copying the matrix A 3 times along the row axis and 2 times along the column axis.
A = [1 2;3 4];
B = repmat(A,3,2);
Example 04: Generate 10 periods of a discrete sawtooth wave with a fundamental frequency
of 1/8 cycles per sample and peaks of -1 and 1.
Frequency (f) is 1/8 so the period (N) must be 8 samples. So, over 8 samples the sample value will
rise from -1 to 1. We can use MATLAB function linspaceto create a linearly spaced vector of
specific length and range.
N = 8;
unit = linspace(-1,1,N);
x = repmat(unit,1,10);
n =-5*N:5*N-1;
stem(n, x)
title("Sawtooth wave");
xlabel("Index (n)");
ylabel("Amplitude");
Here, unit is one period of the signal. You can try and plot it for better understanding. Then, we
used repmatto repeat the period 10 times along the column axis. Lastly, index (n) is created from
the fact that one period runs from index 0 to 7 (total 8 samples), so, 10 periods will run from -40
to 39 or from 0 to 79. It is your choice to select the index range as none has been provided. See the
figure on the next page.
EEE-314-28 | P a g e
Fig. 2: Sawtooth signal with frequency 1/8 cycles per sample
Practice Problem 05: Generate 4 periods of a discrete triangular wave with a fundamental
frequency of 1/16 cycles per sample and peaks of 0 and 1.
[Hint: Generate the rising and the falling side of the signal separately. Calculate the number of
samples for each side. Then use linspaceor the colon (:) operator to create the sample values.]
Practice Problem 06: Generate three discrete-time sinusoids with frequencies𝑡 = √2, 1/8 and 9/8
to verify property 1 and 2. According to property 1, sinusoid with 𝑡 = √2will not be periodic,
which means values will not repeat. And according to property 2, sinusoids with t = 1/8 and 9/8
should be exactly the same because the difference between the frequencies is an integer (1 in this
case).
[Hint: Generation of the signals is very easy as we covered this topic in the previous lab. The main
task here is to observe and interpret the generated signals.]
Example05: Generate three discrete-time cosine wave with frequency t =1/2,1/4 and
4/5toverifyproperty3.Accordingtoproperty3, the maximum oscillation will occur at
EEE-314-29 | P a g e
t = 1/2. Decreasing tfrom 1/2 to 1/4 or increasing tfrom 1/2 to 4/5 will result in decreased
oscillation in both cases.
n = -15:15;
x1 = cos(2*pi*(1/2)*n);
x2 = cos(2*pi*(1/4)*n);
x3 = cos(2*pi*(4/5)*n);
subplot(3,1,1)
stem(n, x1)
title("Cosine wave with frequency 0.5");
xlabel("Index (n)");
ylabel("Amplitude");
subplot(3,1,2)
stem(n, x2)
title("Cosine wave with frequency 0.25");
xlabel("Index (n)");
ylabel("Amplitude");
subplot(3,1,3)
stem(n, x3)
title("Cosine wave with frequency 0.8");
xlabel("Index (n)");
ylabel("Amplitude");
Fig. 3: Figure generated from the execution of the code above. Observe how the oscillation
varies with frequency.
EEE-314-30 | P a g e
Lab Report:
Solve the practice problems and submit the solutions as the lab report. You do not have to write
down the theory section. The codes should be handwritten. Print the figures. If you face difficulties,
mention it in the discussion section.
Precautions:
8) Follow the software instructions and lab manual for using the software.
9) Be careful while input the variables value before run the code.
10) Always work in the editor environment. This will you to edit the Matlab Code.
11) Do not turn off your pc or laptop while simulating the design.
12) Check your code with the desired input data.
13) Never hurry. Hurry can cause error in simulation.
14) After simulation collect all the data and graphs carefully, take screen shot if necessary.
Data Analysis:
Report:
3) Submit the complete data sheet with the screenshots of Matlab code and Output Graphs.
4) Using various variables value complete the data table, observe the output graphs and write a
report
References
1. Li Tan, Purdue University, Jean Jiang, Purdue University “Digital Signal Processing:
Fundamentals and Applications’’.
2. Website: https://www.mathworks.com/products/matlab.html
EEE-314-31 | P a g e
EEE-314-32 | P a g e
Experiment No. 04
Name of the Experiment: Operations on discrete-time signals
Objective:
The objectives of this experiment are to:
3) Get familiarized with basic signal operations such as shifting, scaling, folding, even-odd
decomposition, etc.
4) Learn to perform basic operations on discrete signals using MATLAB.
Domain /
Delivery
Corresponding level of Assessment
CO Statement methods and
PO learning tools
activities
taxonomy
CO1: Use
MATLAB to Lab tests
generate signals, Simulation Lab reports
describe systems,
apply different Application Experiment Final lab
Affective test
types of signal (PO3) Practice lab
domain/
transformations Modern Tool Open ended
valuing level Group
such as shifting, Usage (PO5) lab
scaling, folding discussion
and perform Project
Tutorial
convolution and show& project
correlation. presentation
Theory:
EEE-314-33 | P a g e
and has time indices [-1,0,1,2,3,4,5].
These two ideas, that sequences to be added or multiplied must be of equal length, but also properly
time-aligned, lead us to write several MATLAB functions that will automatically perform the
needed adjustments and perform the arithmetic operation.
The script above will perform addition of offset sequences y1 and y2 that have respective time
indices n1 and n2 using the method of prepending and post pending zeros. The function [y,n] =
singed(y1, n1, y2, n2)works the same way, with the addition operator (+) in the final statement
being replaced with the operator for multiplying two vectors on a sample-by- sample basis, a period
following by an asterisk (.*). Try to write the functions for signal multiplication and subtraction.
Exercise 01: Let 𝑥(𝑛) = cos(0.05𝜋𝑛) and 𝑦(𝑛) = sin(0.1𝜋𝑛). Generate and plot the following
sequence over the duration −25 ≤ 𝑛 ≤ 25:
We will have to generate the signals 𝑥(𝑛) and 𝑦(𝑛) separately. Then we add them using the sigadd
function we’ve created earlier. Execute the following MATLAB code:
n = -25:25;
x = cos(0.05*pi*n);
y = sin(0.1*pi*n);
[z,n] = sigadd(5*x,n,-2*y,n);
stem(n,z);
title('Signal: z(n)=5cos(0.05{\pi}n)-2sin(0.1{\pi}n)')
xlabel('Index (n)')
ylabel('Amplitude')
EEE-314-34 | P a g e
Figure 01: Output signal for Exercise 01
Time shifting:
Time shifting of a signal or sequence is defined by the following system equation:
𝑦(𝑛) = 𝑥(𝑛 − 𝑘)
If 𝑛 is positive, the shifting operation is called “Time delaying”, likewise, if 𝑛 is negative, the
shifting operation is called “Time advancing”.
Practice problem 01: Let 𝑥(𝑛) = [1,-2 4,6,-5,8,10]. The sample at 𝑛 = 0 has been bolded.
Generate and plot the following sequence:
[Hint: Time shifting and signal addition and subtraction operations are present in this system. So,
combine the codes above. Generate individual sequences by time shifting, then perform the
addition or subtraction.]
EEE-314-35 | P a g e
Exercise 02: Let 𝑥(𝑛) = (0.9)n u(n). Generate and plot the following sequence over the duration
−10 ≤ 𝑛 ≤ 10:
𝑦(𝑛) = 𝑥(𝑛 + 5)
We will use the sigshift function defined above. Here, 𝑘 = −5. Execute the following MATLAB
code and observe the generated figure:
n = -10:10;
x = ((0.9).^n).*stepseq(-10,10,0);
[y,m] = sigshift(x,n,-5);
stem(m,y);
title('Signal: (0.9)^nu(n)')
xlabel('Index (n)')
ylabel('Amplitude')
Practice problem 02:Generate and plot the sequence below over the duration 0 ≤ 𝑛 ≤ 50:
[Hint: Use the knowledge gained on the previous two labs where you learned to generate and plot
sinusoids and basic signals. The rest is same as practice problem 01.]
Time folding/reversing/mirroring:
EEE-314-36 | P a g e
From time to time it is necessary to reverse a sequence in time, i.e., assuming that 𝑥(𝑛) = [1,2,3,4],
the folded sequence would be 𝑥(−𝑛) = [4,3,2,1], defined by the following equation:
𝑦(𝑛) = 𝑥(−𝑛)
The operation is essentially to flip the sequence from left to right around index zero. For example,
the sequence [1,2,3,4] that has corresponding sample indices [3,4,5,6], when folded, results in the
sequence [4,3,2,1] and corresponding indices [-6,-5,-4,-3]. To illustrate the above ideas, we can,
for example, let 𝑥(𝑛)= [1,2,3,4] with corresponding sample indices n = [3,4,5,6], and compute
𝑥(−𝑛)using MATLAB. We can write a simple script to accomplish the folding operation:
1
𝑥𝑒 (𝑛) = (𝑥(𝑛) + 𝑥(−𝑛))
2
1
𝑥𝑜 (𝑛) = (𝑥(𝑛) − 𝑥(−𝑛))
2
Practice problem 03: Write a MATLAB function that will decompose a given signal to its even
and odd components.
[Hint: Combine the signal addition, subtraction and time folding operations discussed earlier
according to the equations shown above.]
Practice problem 04: Decompose the signal 𝑦(𝑛) in the practice problem 01 into its even and odd
components. Plot the components and the original signal on the same figure.
[Hint: Use the function you wrote for practice problem 03 to generate the components.]
Time scaling:
EEE-314-37 | P a g e
Time scalingof a signal or sequence is defined by the following system equation:
𝑦(𝑛) = 𝑥(𝑎𝑛)
If 𝑎 > 1, the scaling operation is called “Downsampling” and 𝑎 will be an integer. If 𝑎 < 1, the
scaling operation is called “Upsampling” and 𝑎 = 1⁄𝑏, where 𝑏 is an integer.
If 𝑎 > 1, the number of samples is reduced by the factor 𝑎 and the signal is compressed. This is
why it is called “Down sampling”. Likewise, if 𝑎 < 1, the number of samples is increased by the
factor 𝑎 and the signal is expanded. Hence the name “Upsampling”.
In case of down sampling, every 𝑎 samples from the original signal is taken. This is why the
number of sample is reduced and the signal gets compressed. For example, if 𝑦(𝑛) = 𝑥(2𝑛), then
𝑦(0) = 𝑥(0), 𝑦(1) = 𝑥(2), 𝑦(2) = 𝑥(4), 𝑦(3) = 𝑥(6). So the samples of the output signal at
𝑛 = 0,1,2,3, 𝑒𝑡𝑐.are created by taking the samples from the input signal at 𝑛 = 0,2,4,6, 𝑒𝑡𝑐.
In case of upsampling, extra samples are produced. This is why the signal gets expanded. For
example, if 𝑦(𝑛) = 𝑥(0.5𝑛), then 𝑦(0) = 𝑥(0), 𝑦(1) = 𝑥(0.5), 𝑦(2) = 𝑥(1), 𝑦(3) = 𝑥(1.5),
𝑦(4) = 𝑥(2). So the samples of the output signal at 𝑛 = 0,1,2,3,4,5,6, 𝑒𝑡𝑐.are created by taking
the samples from the input signal at 𝑛 = 0,0.5,1,1.5,2,2.5,3, 𝑒𝑡𝑐. But how can one get samples at
𝑛 = 0.5,1.5,2.5 for a discrete signal? It is actually not possible as 𝑛 is always integer. For this
reason we can simply put 0 at the samples at the corresponding indices of the output signal. A
better option is to interpolate the sample values from the surrounding samples. But that is for
another day.
EEE-314-38 | P a g e
end
Exercise 03: Let 𝑥(𝑛) = cos(0.05𝜋𝑛)over the duration −25 ≤ 𝑛 ≤ 25. Generate and plot the
following signals on the same figure:
Here, 𝑦(𝑛) is a downsampled version of 𝑥(𝑛) (as 𝑎 = 2 > 1) and 𝑧(𝑛) is an upsampled version
of 𝑥(𝑛) (as 𝑎 = 0.5 < 1). Execute the following MATLAB code:
n = -25:25;
x = cos(0.05*pi*n);
subplot(3,1,1)
stem(n,x);
title('Signal: x(n) = cos(0.05{\pi}n)')
xlabel('Index (n)')
ylabel('Amplitude')
[y,m] = sigdown(x,n,2);
subplot(3,1,2)
stem(m,y);
title('Signal: y(n) = x(2n)')
xlabel('Index (n)')
ylabel('Amplitude')
[z,m] = sigup(x,n,0.5);
subplot(3,1,3)
stem(m,z);
title('Signal: z(n) = x(0.5n)')
xlabel('Index (n)')
ylabel('Amplitude')
EEE-314-39 | P a g e
Figure 03: Output figure for Exercise 03
Practice problem 05: For the signal 𝑥(𝑛) = cos(0.1𝜋𝑛) over the duration 0 ≤ 𝑛 ≤ 10 generate
and plot the following sequence:
Precautions:
1. Follow the software instructions and lab manual for using the software.
2. Be careful while input the variables value before run the code.
3. Always work in the editor environment. This will you to edit the Matlab Code.
4. Do not turn off your pc or laptop while simulating the design.
5. Check your code with the desired input data.
6. Never hurry. Hurry can cause error in simulation.
7. After simulation collect all the data and graphs carefully, take screen shot if necessary.
Data Analysis:
Report:
1) Submit the complete data sheet with the screenshots of Matlab code and Output
Graphs.
2) Using various variables value complete the data table, observe the output graphs and
write a report
EEE-314-40 | P a g e
Results and Discussion:
References
1. Li Tan, Purdue University, Jean Jiang, Purdue University “Digital Signal Processing:
Fundamentals and Applications’’.
2. Website: https://www.mathworks.com/products/matlab.html
EEE-314-41 | P a g e
Experiment No. 05
Name of the Experiment: Discrete-time Convolution summation
Objective:
The objectives of this experiment are to:
5) Learn about convolution operation and its purpose.
6) Perform convolution summation on signals using MATLAB.
Domain /
Delivery
Corresponding level of Assessment
CO Statement methods and
PO learning tools
activities
taxonomy
CO1:Use
MATLAB to Lab tests
generate signals, Simulation Lab reports
describe systems,
apply different Application Experiment Final lab
Affective test
types of signal (PO3) Practice lab
domain/
transformations Modern Tool Open ended
valuing level Group
such as shifting, Usage (PO5) lab
scaling, folding discussion
and perform Project
Tutorial
convolution and show& project
correlation. presentation
Theory:
Convolution is a mathematical operation used to express the relation between input and output of
an LTI system. It relates input, output and impulse response of anLTI system as:
Discrete Convolution:
∞
If 𝑥(𝑛) and ℎ(𝑛) are provided then one can find the output 𝑦(𝑛) using MATLAB in-built function
conv. The function conv takes two inputs: one is the input signal and the other is the impulse
EEE-314-42 | P a g e
response. No time information is taken as input nor given as output. We will discuss about the time
information in the next section.
Exercise 01:The input signal and the impulse response of a system are given as following:
𝑥(𝑛) = {3,11,7,0, −1,4,2} , − 3 ≤ 𝑛 ≤ 3
Solution: Create the signals first. Then use the conv function to generate the output. Finally, plot
the three signals on the same figure using subplots. Plot the output without the time information
as we don’t have it yet. Execute the code below and observe the plot.
n1 = -3:3;
x = [3,11,7,0,-1,4,2];
n2 = -1:4;
h = [2,3,0,-5,2,1];
y = conv(x,h);
subplot(3,1,1)
stem(n1,x);
title('Input signal, x(n)')
xlabel('Index (n)')
ylabel('Amplitude')
subplot(3,1,2)
stem(n2,h);
title('Impulse response, h(n)')
xlabel('Index (n)')
ylabel('Amplitude')
subplot(3,1,3)
stem(y);
title('Output signal, y(n)')
xlabel('Index (n)')
ylabel('Amplitude')
EEE-314-43 | P a g e
Output waveform:
Examine the x-axis of the output signal in the figure above. The values are not time index (n),
rather they are actually the MATLAB array indices. We need to figure out the time information.
What is needed is the beginning and ending points of the output signal time index. Then we can
create the output time index using the colon (:) operator. Given the time index of 𝑥(𝑛) and ℎ(𝑛),
these points are very easy to determine.
Suppose, for 𝑥(𝑛), 𝑛𝑥𝑏 ≤ 𝑛 ≤ 𝑛𝑥𝑒 and for ℎ(𝑛), 𝑛ℎ𝑏 ≤ 𝑛 ≤ 𝑛ℎ𝑒 . So, 𝑛𝑥𝑏 and 𝑛𝑥𝑒 are the
beginning and ending points of the input signal 𝑥(𝑛) and 𝑛ℎ𝑏 respectively and 𝑛ℎ𝑒 are the
beginning and ending points of the impulse response ℎ(𝑛) respectively. Now, if 𝑛𝑦𝑏 and 𝑛𝑦𝑒 are
the beginning and ending points of the output signal 𝑦(𝑛), then,
Respectively. We can create a new MATLAB function conv_with_time to incorporate these time
information.
EEE-314-44 | P a g e
end
Such a filter accumulates (integrates) the present and past 14 samples of the input signal. The
factor0.1 represents only a convenient scale factor for this experiment. It follows that the impulse
responseof this filter will be,
0.1, 0 ≤ 𝑛 ≤ 14
ℎ(𝑛) = {
0, 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
To observe the steady-state response of this filter, as well as the input-on and input-off transients,
consider a square wave input signal 𝑥(𝑛) of length L = 200 and period of N = 50 samples.
Solution: First, we need to generate the input signal 𝑥(𝑛) and the impulse response ℎ(𝑛). This part
will be very easy as signal generation has been covered in the previous labs. Then we will use the
function we created (conv_with_time) to generate the output and will also get its time index.
nx = 0:199;
x = repmat([ones(1,25) zeros(1,25)],[1,4]);
subplot(3,1,1)
stem(nx,x)
title('Input signal, x(n)')
xlabel('Index (n)')
ylabel('Amplitude')
nh = 0:14;
h = 0.1*ones(1,15);
subplot(3,1,2)
stem(nh,h)
title('Impulse response, h(n)')
xlabel('Index (n)')
ylabel('Amplitude')
[y,ny] = conv_with_time(x,nx,h,nh);
subplot(3,1,3)
stem(ny,y)
title('Output signal, y(n)')
xlabel('Index (n)')
ylabel('Amplitude')
Output waveform:
EEE-314-45 | P a g e
Figure 02: Output figure for exercise 02
0.25(0.75)𝑛 , 0 ≤ 𝑛 ≤ 14
ℎ(𝑛) = {
0, 𝑒𝑙𝑠𝑒𝑤ℎ𝑒𝑟𝑒
Practice problem02: To demonstrate the concepts of impulse response, linearity, and time-
invariance, consider a filter with finite impulse response,ℎ(𝑛) = (0.95)𝑛 , 𝑓𝑜𝑟 0 ≤ 𝑛 ≤ 24.The
input signal,
consists of four impulses of the indicated strengths occurring at the indicated time instances. Note
that the first two impulses are separated by more than the duration of the filter, whereas the last
two are separated by less. Using your function conv_with_time, compute the filter output
𝑦(𝑛)andplot it on the same graph with 𝑥(𝑛). Comment on the resulting output with regard to
linearity and time invariance.
EEE-314-46 | P a g e
In order to remove 𝑤(𝑛), the signal 𝑥(𝑛) is filtered through a filter that isdesigned to pass the
frequency 𝑓1 and reject the interfering frequency 𝑓2 .
The actual designing of the filter is beyond scope of this lab. For now, say we know that a filter
with the following system equation will be able to remove the noise 𝑤(𝑛):
1
𝑦(𝑛) = {𝑥(𝑛) + 𝑥(𝑛 − 1) + 𝑥(𝑛 − 2)}
3
Practice problem 03: Implement the filter discussed above. Use a sampling frequency of 90
Hzand signal length of 200to generate the signals.Plot the original signal 𝑥(𝑛), the desired signal
𝑠(𝑛) and the output signal 𝑦(𝑛). Observe the output and see if the filter hasreally been able to
remove the noise. You can use the plot function instead of the stem function for better
visualization.
which computes a backward first-order difference of the input sequence. Implement this
differentiator on the following sequences and plot the results. Use suitable signal length. Comment
on the appropriateness of this simple differentiator.
Precautions:
1) Follow the software instructions and lab manual for using the software.
2) Be careful while input the variables value before run the code.
3) Always work in the editor environment. This will you to edit the Matlab Code.
4) Do not turn off your pc or laptop while simulating the design.
5) Check your code with the desired input data.
6) Never hurry. Hurry can cause error in simulation.
7) After simulation collect all the data and graphs carefully, take screen shot if necessary.
Data Analysis:
Report:
1) Submit the complete data sheet with the screenshots of Matlab code and Output
Graphs.
2) Using various variables value complete the data table, observe the output graphs and
write a report
EEE-314-47 | P a g e
Results and Discussion:
References
1) Li Tan, Purdue University, Jean Jiang, Purdue University “Digital Signal Processing:
Fundamentals and Applications’’.
2) Website: https://www.mathworks.com/products/matlab.html
EEE-314-48 | P a g e
Experiment No. 06
Name of the Experiment: Discrete-time Correlation
Objective:
The objectives of this experiment are to:
1) Learn about correlation operations and their properties and purposes.
2) Calculate autocorrelation and cross-correlation of signals using MATLAB.
3) learn about some real-world application of correlation and simulate them in the LAB.
Domain /
Delivery
Corresponding level of Assessment
CO Statement methods and
PO learning tools
activities
taxonomy
CO1:Use
MATLAB to Lab tests
generate signals, Simulation Lab reports
describe systems,
apply different Application Experiment Final lab
Affective test
types of signal (PO3) Practice lab
domain/
transformations Modern Tool Open ended
valuing level Group
such as shifting, Usage (PO5) lab
scaling, folding discussion
and perform Project
Tutorial
convolution and show & project
correlation. presentation
Theory:
Correlation: Correlation determines the degree of similarity between two signals. If the signals
are identical, then the correlation coefficient is 1; if they are totally different, the correlation
coefficient is 0, and if they are identical except that the phase is shifted by exactly 180° (i.e.
mirrored), then the correlation coefficient is -1.
EEE-314-49 | P a g e
Algorithm for calculating Autocorrelation:
1. Read the input sequence x[n].
2. Auto correlate the signal using xcorr(x,x). [xcorr is the built in MATLAB function for
performing correlation.]
3. Display the auto correlation result on a suitable axis.
You can additionally verify the correlation property 𝑟𝑥𝑥 (0) = 𝑒𝑛𝑒𝑟𝑔𝑦(𝑥) and the symmetric
property to get a better understanding.
Example 01: For the following signal 𝑥(𝑛) calculate the autocorrelation sequence 𝑟𝑥𝑥 (𝑙).
1, −5≤𝑛 ≤5
𝑥(𝑛) = {
0, 𝑒𝑙𝑠𝑒𝑤ℎ𝑒𝑟𝑒
Solution:
Execute the following MATLAB code:
% Verifying property 1
Energy = sum(x.^2); % calculate the energy of input signal
fprintf("Energy: %2.f\n",Energy);
EEE-314-50 | P a g e
Output waveform:
Using Data Tips on the MATLAB figure, we can clearly see that that,
So, the first property is verified. Also, we can see that 𝑟𝑥𝑥 (𝑙) is symmetric about the y axis. So, the
second property is also verified.
Cross-correlation: When two independent signals are compared, the procedure is known as cross-
correlation. The cross-correlation between two signals 𝑥(𝑛) and 𝑦(𝑛) is given by,
∞
EEE-314-51 | P a g e
independent.
5. 𝑟𝑥𝑦 (𝑙) may not be necessarily have a maximum at 𝑙 = 0 nor 𝑟𝑥𝑦 (𝑙) an even function.
Example 02: For the following signals 𝑥(𝑛) and𝑦(𝑛), calculate the cross-correlation sequence
𝑟𝑥𝑦 (𝑙).
Solution:
Execute the following MATLAB code:
EEE-314-52 | P a g e
Output waveform:
Practice Problem 01: Verify the properties of cross-correlation for Example 02.
where a is some attenuation factor representing the signal loss involved in the round-trip
transmission of the signal 𝑥(𝑛), 𝐷 is the round-trip delay, which is assumed to be an integer
multiple of the sampling interval, and 𝑤(𝑛) represents the additive noise that is picked up by the
antenna and any noise generated by the electronic components and amplifiers contained in the
front end of the receiver. On the other hand, if there is no target in the space searched by the radar
and sonar, the received signal 𝑦(𝑛) consists of noise alone.
Cross-correlation between 𝑥(𝑛) and𝑦(𝑛) can be used to determine if the received signal contains
EEE-314-53 | P a g e
the transmitted signal or not and also the delay between transmission and reception. The cross-
correlation when 𝑦(𝑛) contains delayed 𝑥(𝑛) is distinctly different than the cross-correlation when
there is only noise is 𝑦(𝑛). The reason is simple. As cross-correlation measures the similarity
between signals, when 𝑥(𝑛) and 𝑦(𝑛) matches the output is very high at that time. But if 𝑦(𝑛) is
only noise then there is no match and the output is low.
Suppose, 𝑥(𝑛) = 5cos(𝜋𝑛/10) and the noise is a uniformly distributed random signalhaving
values in the range of 0 to 1. We will explore both the cases (when 𝑦(𝑛) contains 𝑥(𝑛) and when
𝑦(𝑛) do not contains 𝑥(𝑛)) and observe the output of the cross-correlation in the following
example.
Example 03:
Execute and try to understand the following MATLAB code:
EEE-314-55 | P a g e
Output waveform:
Observe the difference between the two cases. In the first case, the output of correlation is very
high. The highest value is more than 1000 and is occurred at 𝑛 = 0. If we had a delay of 20 samples
the highest value would have been located at 𝑛 = 20. This is how we can calculate the delay. In
the second case, the highest value is only close to 20. This reflects the fact that there is not as much
similarity as in the first case.
where,𝑥(𝑛) is a periodic sequence of some unknown period 𝑁 and 𝑤(𝑛) represents an additive
random interference. Suppose, we observe 𝑀 samples of 𝑦(𝑛). Now, we can write a normalized
version of autocorrelation sequence of 𝑦(𝑛) as given bellow:
𝑀−1
1
𝑟𝑦𝑦 (𝑙) = ∑ 𝑦(𝑛)𝑦(𝑛 − 𝑙)
𝑀
𝑛=0
Following the calculation done in “Digital Signal Processing” (Proakis and Manolakis, Chapter 2,
EEE-314-56 | P a g e
Topic 2.6, Page 124) we can write,
𝑟𝑦𝑦 (𝑙) = 𝑟𝑥𝑥 (𝑙) + 𝑟𝑤𝑥 (𝑙) + 𝑟𝑥𝑤 (𝑙) + 𝑟𝑤𝑤 (𝑙)
The cross-correlation term of 𝑟𝑤𝑥 (𝑙) 𝑎𝑛𝑑 𝑟𝑥𝑤 (𝑙) will be relatively small as there is no similarity
between the periodic signal 𝑥(𝑛) and random noise 𝑤(𝑛). The autocorrelation term 𝑟𝑤𝑤 (𝑙) will be
large at 𝑙 = 0 but decay rapidly toward zero because there is no similarity between a random signal
and its delayed version. So, only the autocorrelation term 𝑟𝑥𝑥 (𝑙) will have large peaks at a fixed
interval. If there is no periodic signal in 𝑦(𝑛), 𝑟𝑦𝑦 (𝑙) will only have the term 𝑟𝑤𝑤 (𝑙), which will
not have periodic peaks. This behavior slows us to detect a small periodic signal buried in a
relatively large random interference.
Practice Problem 02:Suppose, you want to work on a signal 𝑦(𝑛) which consists of two parts, a
periodic signal 𝑥(𝑛) = 0.2cos(𝜋𝑛/10) and a noise𝑤(𝑛), which is a uniformly distributed random
signal having values in the range of 0 to 1. But you don’t know about the periodic signal. How can
you check if there is any? Write a MATLAB program which can serve this cause.
Precautions:
1. Follow the software instructions and lab manual for using the software.
2. Be careful while input the variables value before run the code.
3. Always work in the editor environment. This will you to edit the Matlab Code.
4. Do not turn off your pc or laptop while simulating the design.
5. Check your code with the desired input data.
6. Never hurry. Hurry can cause error in simulation.
7. After simulation collect all the data and graphs carefully, take screen shot if necessary.
Data Analysis:
Report:
1. Submit the complete data sheet with the screenshots of Matlab code and Output
Graphs.
2. Using various variables value complete the data table, observe the output graphs and
write a report
References
1. Li Tan, Purdue University, Jean Jiang, Purdue University “Digital Signal Processing:
Fundamentals and Applications’’.
2. Website: https://www.mathworks.com/products/matlab.html
EEE-314-57 | P a g e
Pre Lab Viva Sample Question:
1. Discrete-time Correlation and what are the applications of correlation?
EEE-314-58 | P a g e
Experiment No. 07:
Name of the Experiment: Z-transformation and its application.
Objective:
The objectives of this experiment are to:
4) Analyze signals and systems using Z-transform.
5) Learn usage of some signal processing and symbolic toolbox functions related to Z-
transform.
6) Create simple discrete time systems from given parameters.
Domain /
Delivery
Corresponding level of Assessment
CO Statement methods and
PO learning tools
activities
taxonomy
Lab tests
CO2:Analyze Simulation Lab reports
discrete time Investigation(P
systems using O4) Experiment Final lab
Affective test
signal processing Modern Tool Practice lab
domain/
and symbolic Usage: (PO5) Open ended
valuing level Group
toolboxes of lab
MATLAB. discussion
Project
Tutorial
show & project
presentation
Lab tests
CO3: Design
different discrete Simulation Lab reports
time systems to Experiment Final lab
Investigation Affective
meet specific test
(PO4) domain/char Practice lab
practical
Modern Tool acterizing Open ended
requirements and Group
Usage: (PO5) level lab
limitations. discussion
Project
Tutorial
show & project
presentation
Theory:
The Z-transform plays the same role in the analysis of discrete time signals and LTI systems as
the Laplace transform does in the analysis of continuous-time signals and LTI systems. The use of
z-transform techniques permits simple algebraic manipulations. The Z-transform has become an
EEE-314-59 | P a g e
important tool in the analysis and design of digital filters. In this experiment, different features of
Z-transform have been discussed through various examples and pre-lab work exercises. At the end
of this experiment, one will be able to perform Z transformation, inverse Z transform, system
analysis through stability and causality.
Z-transform:
The Z-transform of a discrete time signal 𝑥(𝑛) is –
∞
𝑋(𝑧) = ∑ 𝑥(𝑛)𝑧 −𝑛
𝑛=−∞
where, z is a complex variable. Since Z-transform is an infinite series, it exists only for those values
of z for which this series converges. The region of convergence (ROC) of 𝑋(𝑧) is the set of all
values of z for which 𝑋(𝑧) attains a finite value.
If 𝑥(𝑛) is -
𝑥(𝑛) = {1, 2, 5, 7, 0, 1}
Its Z-transformed signal,
𝑋(𝑧) = 𝑧 2 + 2𝑧 + 5 + 7𝑧 −1 + 𝑧 −3
And its ROC is entire Z-plane except 𝑧 = 0 and 𝑧 = ∞.
Converting a Z-domain function back to its time-domain form is called inverse Z-transform.
For Z-transform pairs and ROC of common functions, look up Table 3.1 (Chapter 3, Digital signal
processing - principles, algorithms, and applications, Proakis and Manolakis).
EEE-314-60 | P a g e
Experimental simulation procedure:
x = [1, 2, 5, 7, 0, 1];
For converting the time domain signal into equivalent Z domain ztrans() function can be used
which is part of the symbolic toolbox. It evaluates signals of the form 𝑥[𝑛]𝑢[𝑛], i.e. for non-
negative values of 𝑛.
Example 01: Consider the infinite duration time domain signal below:
𝑥(𝑛) = 𝑎𝑛 𝑢(𝑛)
Determine the Z domain signal.
We have to declare some symbolic variables, declare the function and the ztrans() function on it.
Write down the following code and execute it.
syms a n;
x = a^n;
X = ztrans(x)
Compare the result with the result found solving by hand.Note that there is also the iztrans()
function which performs inverse Z-transform.
Practice Problem 01:Determine the Z-transform of the time domain signals below:
i. 𝑥(𝑛) = sin(𝑤0 𝑛) 𝑢(𝑛)
ii. 𝑥(𝑛) = 𝑢(𝑛)
iii. 𝑥(𝑛) = 𝛿(𝑛)
iv. 𝑥(𝑛) = 𝑛𝑎𝑛 𝑢(𝑛)
[Hint: (i), (ii) and (iv) are quite straight forward. For (iii), use the kronecker Delta function to
create the delta function. See the MATLAB help page on kronecker Delta if you have
difficulties.]
Properties of Z-transform:
There are many properties of Z-transform which dictates how a change in one domain affects the
other domain. For example, the time-shifting property states the effect on Z-domain function if the
time-domain function is shifted. Complete collection of the properties are listed in Table 3.2
(Chapter 3, Digital signal processing - principles, algorithms, and applications, Proakis and
Manolakis).
EEE-314-61 | P a g e
the complexity of doing convolution, because this property transforms the time domain
convolution into a multiplication of two functions.
Here, 𝑥(𝑛) is the system input and ℎ(𝑛) is the impulse response. Determine the system response
𝑦(𝑛).
[Hint: In time domain we will have to perform convolution to find the output. But in Z-domain we
will have to just multiply. So, transform both the signals to Z-domain, multiply and then inverse
transform back to the time domain.]
Inverse Z-transform:
In previous sections it was shown that the iztrans() function can be used to perform the inverse Z-
transform operation. But iztrans()normally returns a very long and complicated symbolic
expressions. There are other methods to perform inverse Z_transform.MATLAB functions
deconv() and residuez() can be used in this purpose. The deconv() function is used to perform the
long division required in the power series method. The residuez() function is used to find the
partial fraction coefficients (residues) and poles of the Z-transform.
𝑏0 + 𝑏1 𝑧 −1 + 𝑏2 𝑧 −2 + ⋯ + 𝑏𝑚 𝑧 −𝑚 𝐵(𝑧)
𝑋(𝑧) = =
𝑎0 + 𝑎1 𝑧 −1 + 𝑎2 𝑧 −2 + ⋯ + 𝑎𝑛 𝑧 −𝑛 𝐴(𝑧)
[q,r] = deconv(B,A)
where Band A are vectors representing the numerator and denominator polynomials, 𝐵(𝑧) and
𝐴(𝑧), respectively, in increasing negative powers of 𝑧. The quotient of the polynomial division is
returned in the vector 𝑞 and the remainder is contained in 𝑟. To implement the power series
method, the long division operation is applied successively depending on the number of points
required in the inverse operation.
Example 03: Find the first five terms of the inverse Z-transform, 𝑥(𝑛), using the power series
EEE-314-62 | P a g e
(polynomial division) method and MATLAB. Assume that the Z-transform, 𝑋(𝑧), hasthe
following form:
1 + 2𝑧 −1 + 𝑧 −2
𝑋(𝑧) =
1 − 𝑧 −1 + 0.3561𝑧 −2
Solution:
The coefficient for the numerator and denominator polynomials are formed, zeros are appended to
the coefficient vector b to ensure the correct dimension for MATLAB, and then the command
deconv() is used to compute the inverse Z-transform.
B=[1 2 1];
A=[1 -1 0.3561];
n=5;% number of power series points
B=[B zeros(1, n-1)];
[x, r]=deconv(B,A);
disp(x)
That means, 𝑥(0) = 1, 𝑥(1) = 3, 𝑥(2) = 3.6439, 𝑥(3) = 2.5756, 𝑥(4) = 1.2780.
Example 04:
Find the first five values of the inverse z-transform of the following using the power series
(polynomial division) method and MATLAB:
Solution:
The Z-transform has three pairs of numerator and denominator polynomials. In the MATLAB
implementation (Example 03), the vectors containing the polynomial coefficient are first formed.
The MATLAB function sos2tf() (second order sections – to- transfer function) is then used to
convert the three pairs of polynomials into a transfer function with a pair of rational polynomials,
like𝐵(𝑧)/𝐴(𝑧):
EEE-314-63 | P a g e
𝐵(𝑧) 𝑏0 + 𝑏1 𝑧 −1 + 𝑏2 𝑧 −2 + ⋯ + 𝑏𝑚 𝑧 −𝑚
𝑋(𝑧) = =
𝐴(𝑧) 𝑎0 + 𝑎1 𝑧 −1 + 𝑎2 𝑧 −2 + ⋯ + 𝑎𝑛 𝑧 −𝑛
The deconv() function is used to generate the inverse Z-transform coefficients. The firstfive values
of the inverse Z-transform are
𝑥(0) = 1.0000, 𝑥(1) = 4.6915, 𝑥(2) = 11.4246, 𝑥(3) = 19.5863, 𝑥(4) = 27.0284
[B,A] = sos2tf([ba]);
B = [B zeros(1,n-1 )];
[x,r] = deconv(B,A); %perform long division
disp(x);
[r, p, k] = residuez(B, A)
where B and A are vectors representing the numerator and denominator polynomials,
𝐵(𝑧) and 𝐴(𝑧), respectively, in increasing negative powers of 𝑧 as follows:
𝑏0 + 𝑏1 𝑧 −1 + 𝑏2 𝑧 −2 + ⋯ + 𝑏𝑚 𝑧 −𝑚 𝐵(𝑧)
𝑋(𝑧) = =
𝑎0 + 𝑎1 𝑧 −1 + 𝑎2 𝑧 −2 + ⋯ + 𝑎𝑛 𝑧 −𝑛 𝐴(𝑧)
If the poles of 𝐻(𝑧) are distinct, its partial fraction expansion has the form
𝐵(𝑧) 𝑟1 𝑟𝑛
𝑋(𝑧) = = −1
+ ⋯ + −1
+ 𝑘1 + 𝑘2 𝑧 −1 + ⋯ + 𝑘𝑚−𝑛 𝑧 −(𝑚−𝑛)
𝐴(𝑧) 1 − 𝑝1 𝑧 1 − 𝑝𝑛 𝑧
After calculating the partial fraction, Table 3.1 and 3.2 can be used to get the time domain signal.
EEE-314-64 | P a g e
The residuez() function returns the residues of the rational polynomial 𝐵(𝑧)/𝐴(𝑧) in the vector 𝑟,
the pole positions in 𝑝, and the constant terms in 𝑘.
1 + 2𝑧 −1 + 𝑧 −2
𝐻(𝑧) =
1 − 𝑧 −1 + 0.3561𝑧 −2
Solution:
r=
-0.9041 - 5.9928i
-0.9041 + 5.9928i
p=
0.5000 + 0.3257i
0.5000 - 0.3257i
k=
2.8082
Pole-zero diagram:
The MATLAB function, zplane(), allows the computation and display of the pole-zero diagram.
The syntax for the command is:
zplane(B,A)
where B and A are the coefficient vectors of the numerator and denominator polynomials,
𝐵(𝑧)/𝐴(𝑧). In this format, the command first finds the locations of the poles and zeros (i.e. the
roots of 𝐵(𝑧) and 𝐴(𝑧), respectively) and then plots the Z-plane diagram.
EEE-314-65 | P a g e
Example 06:
A discrete-time system is characterized by the following transfer function:
1 + 1.16180𝑧 −1 + 𝑧 −2
𝐻(𝑧) =
1 − 1.5161𝑧 −1 + 0.878𝑧 −2
Solution:
B = [1 -1.6180 1];
A = [1 -1.5161 0.878];
If the locations of the poles and zeros are known, these can be used as inputs to the zplane()
command. The syntax of the command in this case is,
zplane(z, p)
The locations of the poles and zeros can be found directly using the roots() command. This is
EEE-314-66 | P a g e
useful for converting between pole and zero and the transfer function representations. For example,
an IIR filter is represented by,
1 + 1.16180𝑧 −1 + 𝑧 −2
𝐻(𝑧) =
1 − 1.5161𝑧 −1 + 0.878𝑧 −2
B = [1 -1.618 11];
A = [1 -1 .5161 0.878];
zk = roots(B);
pk = roots(A);
On the other hand, the numerator and denominator polynomials, b(z) and a(z), can beobtained
using thepoly() function:
B = poly(zk);
A = poly(pk);
Impulse response:
We can use the impz() function to calculate the impulse response of a given system in the form:
𝑏0 + 𝑏1 𝑧 −1 + 𝑏2 𝑧 −2 + ⋯ + 𝑏𝑚 𝑧 −𝑚 𝐵(𝑧)
𝑋(𝑧) = =
𝑎0 + 𝑎1 𝑧 −1 + 𝑎2 𝑧 −2 + ⋯ + 𝑎𝑛 𝑧 −𝑛 𝐴(𝑧)
h = impz(B, A, n)
where the variables B and A are the vectors of the numerator and denominator polynomials’ is the
number of samples of the impulse response. If n is 50, first 50 samples of the impulse response
will be calculated and returned.
1 + 1.16180𝑧 −1 + 𝑧 −2
𝐻(𝑧) =
1 − 1.5161𝑧 −1 + 0.878𝑧 −2
Solution:
B = [1 -1.6180 1];
A = [1 -1.5161 0.878];
n = 50;
impz(B,A,n); % compute and plot the impulse response
EEE-314-67 | P a g e
Fig. 2: Impulse response of the system in Example 07.
Practice problem 04:
For the following system,
𝑦(𝑛) = 0.9𝑦(𝑛 − 1) + 𝑥(𝑛)
Precautions:
1) Follow the software instructions and lab manual for using the software.
2) Be careful while input the variables value before run the code.
3) Always work in the editor environment. This will you to edit the Matlab Code.
4) Do not turn off your pc or laptop while simulating the design.
5) Check your code with the desired input data.
6) Never hurry. Hurry can cause error in simulation.
7) After simulation collect all the data and graphs carefully, take screen shot if necessary.
Data Analysis:
Report:
EEE-314-68 | P a g e
1. Submit the complete data sheet with the screenshots of Matlab code and Output
Graphs.
2. Using various variables value complete the data table, observe the output graphs and
write a report
References
1. Li Tan, Purdue University, Jean Jiang, Purdue University “Digital Signal Processing:
Fundamentals and Applications’’.
2. Website: https://www.mathworks.com/products/matlab.html
EEE-314-69 | P a g e
Experiment No. 08:
Name of the Experiment: Discrete Time Fourier Series and its application
Objective:
The objectives of this experiment are to:
1) Learn how Discrete Time Fourier Series works.
2) Analyze signals using Discrete Time Fourier Series.
3) Learn usage of some signal processing functions related to Discrete Time Fourier Series.
Domain /
Delivery
Corresponding level of Assessment
CO Statement methods and
PO learning tools
activities
taxonomy
Lab tests
CO2: Analyze Simulation Lab reports
discrete time Investigation(P
systems using O4) Experiment Final lab
Affective test
signal processing Modern Tool Practice lab
domain/
and symbolic Usage: (PO5) Open ended
valuing level Group
toolboxes of lab
MATLAB. discussion
Project
Tutorial
show & project
presentation
Theory:
𝑗2𝜋𝑘𝑛
𝑒 𝑁 , 𝑤ℎ𝑒𝑟𝑒 𝑘 = 0, 1, 2, … , 𝑁 − 1
This equation is often called the discrete-time Fourier series (DTFS). Fourier
coefficients,𝐶𝑘 𝑓𝑜𝑟 𝑘 = 0, 1, 2, … , 𝑁 − 1 provide the description of 𝑥(𝑛) is in frequency
EEE-314-70 | P a g e
domain.𝐶𝑘 can be computed as,
𝑁−1
1 𝑗2𝜋𝑘𝑛
𝐶𝑘 = ∑ 𝑥(𝑛)𝑒 𝑁
𝑁
𝑛=0
Note that,𝐶𝑘+𝑁 = 𝐶𝑘 , that is, 𝐶𝑘 is a periodic sequence with fundamental period 𝑁. Thus, the
spectrum of a signal 𝑥(𝑛),which is periodic with period 𝑁, is a periodic sequence with period 𝑁.
𝑁−1 𝑁−1
1
𝑃𝑥 = ∑|𝐶𝑘 |2 = ∑|𝑥(𝑛)|2
𝑁
𝑘=0 𝑛=0
If the signal 𝑥(𝑛) is real [𝑥(𝑛) = 𝑥 ∗ (𝑛)] then it can be shown that,
𝐶𝑘 ∗ = 𝐶−𝑘
Example 01:
Calculate Fourier Series Coefficients of a continuous rectangular pulse sequence of 1ms period
and pulse width 0.1ms.The signal is sampled at 100kHz and sampled discrete with 𝑛 its index is
shown below in Fig. 1.
Solution:
The following MATLAB code calculates the Fourier series coefficients from the first principle
and from the Fourier series coefficients, again reconstructs the original periodic sequence.
EEE-314-71 | P a g e
Code (part 1: Generation of the signal)
clear all;
echo on;
Fs = 100e3;
dt = 1/Fs;
EEE-314-72 | P a g e
Plot for code part 1:
EEE-314-73 | P a g e
Plot for code part 2:
Fig. 2: Magnitude and phase spectrum of the discrete time signal. Note that the phase spectrum is
not skew-symmetric with respect to 𝑘 = 0. It is an artifact of MATLAB and 𝜃 =
+180o and −180o are in fact synonymous.
for i1=1:length(k)
for i2=1:length(x_re)
x_re(i2)= x_re(i2)+c(i1)*exp(1i*2*pi*k(i1)*n_re(i2)/N);
end
end
EEE-314-74 | P a g e
Plot for code part 3:
Now, we can see that the Fourier Coefficients are plotted with respect to the variable 𝑘. We can
easily convert this unintuitive variable to continuous time frequency as the relationship between 𝑘
and the continuous time frequency can be represented by the following equation:
𝑘
𝑓= 𝐹
𝑁 𝑠
where,
𝑓 = Continuous time frequency
𝑁 = Period of the discrete time signal
𝐹𝑠 = Sampling frequency
Practice Problem01:
Modify code part 2 in Example 01 so that the x-axis of the plot of Fourier Coefficients represents
the continuous frequency instead of the variable 𝑘.
Practice Problem02:
Plot the power density spectrum of the signal in Example 01 with respect to the continuous
frequency.
[Hint: In Fig. 2 you can see that |𝐶𝑘 | has been plotted. For the power density spectrum you will
have to just plot |𝐶𝑘 |2 instead of |𝐶𝑘 | as evident from the equation of the average power in theory
section.]
EEE-314-75 | P a g e
In Example 01, we have used 𝑁𝑐 = 𝑁 or in other words, the number of coefficients is same as the
number of samples in one period of the original signal.
If we take less coefficients than 𝑁 (i.e. 𝑁 = 101 and 𝑁𝑐 = 50), we will not be able to perfectly
reconstruct the signal which is intuitive because we have essentially left out some information.
If we take more coefficients than 𝑁 and 𝑁𝑐 is integer multiple of 𝑁 (i.e. 𝑁 = 101 and 𝑁𝑐 = 303),
there will be no extra benefit. That means we will get the same result as when we used 𝑁𝑐 = 𝑁.
This is also intuitive because we are actually getting no extra information. We are just providing
more information than needed.
If we take more coefficients than 𝑁 and 𝑁𝑐 is not integer multiple of 𝑁 (i.e. 𝑁 = 101 and 𝑁𝑐 =
300), there will be some errors because of disturbance in symmetry.
Practice Problem03:
For the signal in Example 01, plot the Fourier coefficients and the reconstructed signals for each
of the case below:
𝑁𝑐 = 𝑓𝑎𝑐𝑡𝑜𝑟 ∗ 𝑁
1. 𝑓𝑎𝑐𝑡𝑜𝑟 = 0.1
2. 𝑓𝑎𝑐𝑡𝑜𝑟 = 0.5
3. 𝑓𝑎𝑐𝑡𝑜𝑟 = 2.5
4. 𝑓𝑎𝑐𝑡𝑜𝑟 =3
Comment on the results. Can you find out the errors in each case?
[Hint: To calculate the error, first, calculate the difference between the original and the
reconstructed signal. Then, square the differences (errors) and lastly, get the summation of squared
errors and find the mean value. This type of error calculation is called the mean squared error
(MSE).]
Practice Problem04:
Repeat Example 01 to Practice Problem 03 for the triangular pulse depicted in Fig. 4. Assume, the
sampling frequency is 500 Hz.
EEE-314-76 | P a g e
Fig. 4: Signal for practice problem 04.
Precautions:
15) Follow the software instructions and lab manual for using the software.
16) Be careful while input the variables value before run the code.
17) Always work in the editor environment. This will you to edit the Matlab Code.
18) Do not turn off your pc or laptop while simulating the design.
19) Check your code with the desired input data.
20) Never hurry. Hurry can cause error in simulation.
21) After simulation collect all the data and graphs carefully, take screen shot if necessary.
Data Analysis:
Report:
5) Submit the complete data sheet with the screenshots of Matlab code and Output
Graphs.
6) Using various variables value complete the data table, observe the output graphs and
write a report
EEE-314-77 | P a g e
References
1. Li Tan, Purdue University, Jean Jiang, Purdue University “Digital Signal Processing:
Fundamentals and Applications’’.
2. Website: https://www.mathworks.com/products/matlab.html
𝑁𝑐 = 𝑓𝑎𝑐𝑡𝑜𝑟 ∗ 𝑁
I. 𝑓𝑎𝑐𝑡𝑜𝑟 = 0.1
II. 𝑓𝑎𝑐𝑡𝑜𝑟 = 0.5
III. 𝑓𝑎𝑐𝑡𝑜𝑟 = 2.5
IV. 𝑓𝑎𝑐𝑡𝑜𝑟 =3
Comment on the results. Can you find out the errors in each case?
[Hint: To calculate the error, first, calculate the difference between the original and the
reconstructed signal. Then, square the differences (errors) and lastly, get the summation of squared
errors and find the mean value. This type of error calculation is called the mean squared error
(MSE).]
2. Repeat Example 01 to Practice Problem 03 for the triangular pulse depicted in Fig. 4.
Assume, the sampling frequency is 500 Hz
EEE-314-78 | P a g e
Experiment No. 09:
Experiment Name: Discrete Time Fourier Transform and its application
Objective:
The objectives of this experiment are to:
1) Learn how Discrete Time Fourier Transform works.
2) Analyze signals using Discrete Time Fourier Transform.
3) Learn usage of some signal processing functions related to Discrete Time Fourier
Transform.
Domain /
Delivery
Corresponding level of Assessment
CO Statement methods and
PO learning tools
activities
taxonomy
Lab tests
CO2: Analyze Simulation Lab reports
discrete time Investigation(P
systems using O4) Experiment Final lab
Affective test
signal processing Modern Tool Practice lab
domain/
and symbolic Usage: (PO5) Open ended
valuing level Group
toolboxes of lab
MATLAB. discussion
Project
Tutorial
show& project
presentation
Theory:
∑ |𝑥(𝑛)| < ∞
𝑛=−∞
Now 𝜔 is a real variable between − ∞ to + ∞ but one important property of 𝑋(𝜔) is itsperiodicity
in 𝜔 with period 2𝜋. So, we only need one period of 𝑋(𝜔) i.e. 𝜔 ∈ [0, 2𝜋] or[−𝜋, 𝜋].
EEE-314-79 | P a g e
The inverse DTFT equation, in other words the equation for reconstructing the signal from𝑋(𝜔)
is given by,
1 𝜋
𝑥(𝑛) = ∫ 𝑋(𝜔)𝑒 𝑗𝜔𝑛 𝑑𝜔
2𝜋 −𝜋
Required Devices & Software:
Since the frequency is continuous variable, DTFT cannot be implemented in digital hardware in
rigorous sense. By defining a fine grid of frequency in the range [−𝜋, 𝜋]the frequency variable is
usually handled in DTFT implementation. In MATLAB we evaluate 𝑋(𝜔)atequidistant
frequencies between [0, 2𝜋]and then interpolate using plot()function.
2𝜋𝑘
𝜔𝑘 = , 𝑤ℎ𝑒𝑟𝑒 𝑘 = 0, 1, 2, … , 𝑀 − 1
𝑀
𝑛𝑁
𝑗2𝜋𝑘𝑛
𝑋(𝜔𝑘 ) = ∑ 𝑥(𝑛)𝑒 − 𝑀
𝑛=𝑛1
Although matrix method may be an easier approach for DTFT in some cases, we first examine
calculation DTFT of an aperiodic signal from first principles in the following example.
Example 01:
Calculate the Fourier transform of a discrete time sinc signal with a frequency of 1⁄8.Plot the
magnitude spectra and reconstruct the signal back to the time domain.
Solution:
The following MATLAB code calculates the Fourier transform of the given signal using the first
principle. And then, from the Fourier transform, reconstructs the original signal. For better
understanding the code has been organized in three parts.
EEE-314-80 | P a g e
f_c=1/8; %DEFINING FREQUENCY
n=-40:40; %DEFINING THE TIME INDEX
x=sinc(2*f_c*n);
%END OF SINC PULSE
figure(1);
stem(n, x);
xlabel('n');
ylabel('x(n)');
title('Discrete time signal');
EEE-314-81 | P a g e
Output of Code Part 2:
EEE-314-82 | P a g e
Output of Code Part 3:
Practice problem01:
Calculate the Fourier transform of a 𝑠𝑖𝑛𝑐 2 pulse with a frequency of 1⁄8.The signal is given as,
sin(2𝜋𝑓𝑛) 2
𝑥(𝑛) = 𝑠𝑖𝑛𝑐 2 (2𝜋𝑓𝑛) = ( )
2𝜋𝑓𝑛
where, 𝑓 = 1⁄8. Plot the magnitude spectra and reconstruct the signal back to the time domain.
Practice problem02:
Do the following for the signal in Example 01:
1. Increase the range of the frequency grid to [0, 2𝜋]. Observe the magnitude spectra and explain
the effects.
2. Change the range of the frequency range to [−2𝜋, 2𝜋]. Observe the magnitude spectra and
explain the effects.
3. Verify the effect of changing index (𝑛) to -40:120 and -40:80. In each case, observe the
reconstructed signal and explain the result.
4. If you reconstruct the signal in n_re=-240:240, why do you get a repetition of theaperiodic
signal?
5. Verify the duality property of DTFT with rectangular pulse and sinc function.
EEE-314-83 | P a g e
𝑋 = 𝑊𝑥 𝑇
The advantage of using the matrix form is that we don’t have to use for loops here. So, the
calculation will be faster.
Example 02:
Calculate the Fourier transform of the following signal,
Solution:
EEE-314-84 | P a g e
Output:
Example 03:
Calculate the Fourier transform of the signal in Example 02 using MATLAB built-in functions.
Solution:
EEE-314-85 | P a g e
plot(w/(2*pi),angle(X)*180/pi);
xlabel('Digital frequency, f');
ylabel('angle(X(f))');
title('Phase Spectrum');
This code will generate the same magnitude spectra as Example 02. The phase spectra might be a
little different but it would be due to the behavior of MATLAB function angle (). For example,
instead of an angle of 185° it could be −175°. Though it distorts the graph and makes it
discontinuous but the values are actually same.
Precautions:
1. Follow the software instructions and lab manual for using the software.
2. Be careful while input the variables value before run the code.
3. Always work in the editor environment. This will you to edit the Matlab Code.
4. Do not turn off your pc or laptop while simulating the design.
5. Check your code with the desired input data.
6. Never hurry. Hurry can cause error in simulation.
7. After simulation collect all the data and graphs carefully, take screen shot if necessary.
Data Analysis:
Report:
1) Submit the complete data sheet with the screenshots of Matlab code and Output
Graphs.
2) Using various variables value complete the data table, observe the output graphs and
write a report
References
1) Li Tan, Purdue University, Jean Jiang, Purdue University “Digital Signal Processing:
Fundamentals and Applications’’.
2) Website: https://www.mathworks.com/products/matlab.html
EEE-314-86 | P a g e
2 (2𝜋𝑓𝑛)
sin(2𝜋𝑓𝑛) 2
𝑥(𝑛) = 𝑠𝑖𝑛𝑐 =( )
2𝜋𝑓𝑛
where, 𝑓 = 1⁄8. Plot the magnitude spectra and reconstruct the signal back to the time domain.
EEE-314-87 | P a g e
Experiment No. 10:
Name of the Experiment: Frequency domain analysis of discrete-time systems
Objective:
The objectives of this experiment are to:
2. Learn to analyze discrete-time systems in frequency domain.
3. Compute the magnitude and phase response of systems and interpret them.
4. Apply filters or systems to some real world audio signals and observe the response.
Domain /
Delivery
Corresponding level of Assessment
CO Statement methods and
PO learning tools
activities
taxonomy
Lab tests
CO2:Analyze Simulation Lab reports
discrete time Investigation(P
systems using O4) Experiment Final lab
Affective test
signal processing Modern Tool Practice lab
domain/
and symbolic Usage: (PO5) Open ended
valuing level Group
toolboxes of lab
MATLAB. discussion
Project
Tutorial
show & project
presentation
Theory:
𝑏0 + 𝑏1 𝑧 −1 + 𝑏2 𝑧 −2 + ⋯ + 𝑏𝑚 𝑧 −𝑚 𝐵(𝑧)
𝐻(𝑧) = =
𝑎0 + 𝑎1 𝑧 −1 + 𝑎2 𝑧 −2 + ⋯ + 𝑎𝑛 𝑧 −𝑛 𝐴(𝑧)
the freqz() function uses an FFT-based approach to compute the frequency response. The function
has a variety of formats. A useful format is,
where the variables B and A are the vectors of the numerator and denominator polynomials. Fs is
the sampling frequency and npt the number of frequency points between 0 and Fs/2. In the
EEE-314-88 | P a g e
MATLAB Toolbox, the Nyquist frequency (i.e. Fs/2) is the unit of normalized frequency, Using
the freqz() command without output arguments plots the magnitude and phase responses
automatically.
1 + 1.16180𝑧 −1 + 𝑧 −2
𝐻(𝑧) =
1 − 1.5161𝑧 −1 + 0.878𝑧 −2
Plot the frequency response of the system using MATLAB. Assume a sampling frequency of 500
Hz and a resolution of <1 Hz for the frequency response.
Solution:
Here, sampling frequency, Fs is 500 Hz. So, we will have to choose few points between 0 and 250
Hz. The more point we choose the sharper the plot will be. As the resolution should be less than 1
Hz we can choose any number of points more than 250.
B = [1 -1.6180 1];
A = [1 -1.5161 0.878];
Fs = 500;
npt = 256;
freqz(B,A,npt,Fs); % compute and plot the frequency response
EEE-314-89 | P a g e
Calculating response for a given input signal:
Given the transfer function of a system in the following form:
𝑏0 + 𝑏1 𝑧 −1 + 𝑏2 𝑧 −2 + ⋯ + 𝑏𝑚 𝑧 −𝑚 𝐵(𝑧)
𝐻(𝑧) = =
𝑎0 + 𝑎1 𝑧 −1 + 𝑎2 𝑧 −2 + ⋯ + 𝑎𝑛 𝑧 −𝑛 𝐴(𝑧)
and a time domain input signal 𝑥(𝑛), we can calculate the response of the system using MATLAB
built-in function filter().
y = filter(B, A, x)
Example 02: For the system in Example 01, if the sampling rate is 500 Hz, plot the response of
the system for the following signals,
1. 𝑥(𝑡) = 5cos(100𝜋𝑡)
2. 𝑥(𝑡) = 5cos(200𝜋𝑡)
Solution:
Fs = 500;
B = [1 -1.6180 1]; % System coefficients B
A = [1 -1.5161 0.878]; % System coefficients A
% Signal generation
F1 = 50; % Frequency of the first signal
F2 = 100; % Frequency of the second signal
t = 0:(1/Fs):0.2; % 0s to 200ms
x1 = 5*cos(2*pi*F1*t);
x2 = 5*cos(2*pi*F2*t);
% Plotting inputs
subplot(221)
plot(t,x1);
xlabel('time (s)');
ylabel('Amplitude');
title('First signal, F = 50 Hz');
subplot(222)
plot(t,x2);
xlabel('time (s)');
ylabel('Amplitude');
title('Second signal, F = 100 Hz');
EEE-314-90 | P a g e
y1 = filter(B,A,x1);
y2 = filter(B,A,x2);
% End of applying filter. Easy, isn't it?
% Plotting outputs
subplot(223)
plot(t,y1);
xlabel('time (s)');
ylabel('Amplitude');
title('Output for first (50 Hz) signal');
subplot(224)
plot(t,y2);
xlabel('time (s)');
ylabel('Amplitude');
title('Output for second (100 Hz) signal');
Observe how the 50 Hz signal is rejected by the filter. Its amplitude has rapidly declined to zero.
From the output of Example 01 (Fig. 01), we can see that it was bound to happen as at 50 Hz the
magnitude response is zero. On the other hand, the magnitude of the 100 Hz signal is nearly
unchanged which can also be explained from Fig. 01.
Practice Problem 01:A discrete-time system is characterized by the following transfer function:
𝑁1 (𝑧)𝑁2 (𝑧)𝑁3 (𝑧)
𝑋(𝑧) =
𝐷1 (𝑧)𝐷2 (𝑧)𝐷3 (𝑧)
where,
𝑁1 (𝑧) = 1 − 1.22346𝑧 −1 + 𝑧 −2
EEE-314-91 | P a g e
𝑁2 (𝑧) = 1 − 0.437833𝑧 −1 + 𝑧 −2
𝑁3 (𝑧) = 1 + 𝑧 −1
𝐷1 (𝑧) = 1 − 1.4334509𝑧 −1 + 0.85811𝑧 −2
𝐷2 (𝑧) = 1 − 1.293601𝑧 −1 + 0.556929𝑧 −2
𝐷3 (𝑧) = 1 – 0.612159𝑧 −1
Plot the frequency response of the system using MATLAB. Assume a sampling frequency of 10
kHz and a resolution of < 10 Hz for the frequency response.
Code for loading audio files using the load() function is,
Some of vaild sampl names: gong, handle, laughter, train. You can also play the ausio using the
sound() function.
For any other audio files (.wav, .mp3, .flac, .ogg, etc) that isn’t built into MATLAByou can use
the audioread() function. The syntax is given below,
[y,Fs] = audioread(filename);
Solution:
Code Part 1: Loading the input and calculating the magnitude spectra:
EEE-314-92 | P a g e
data = load('gong'); % Load audio
audio = data.y;
L = length(audio); % Length of audio
Fs = data.Fs;
t = (0:L-1)*(1/Fs); % Generate time sequence
N = 1025; % Define number of points for DFT
F = (-(N-1)/2:(N-1)/2)*Fs/(N-1);% Generate frequency sequence
H = fft(audio,N); % Calculate DFT using FFT algorithm
H = fftshift(H); % Shift frequency range
Output of Part 1:
EEE-314-93 | P a g e
Code Part 2: Calculating the output of the filter and its magnitude spectra:
Output of Part 2:
EEE-314-94 | P a g e
Observe how the filter removed all the frequency components beyond 1000 Hz. Can you explain
this result from the frequency response of the filter?
Precautions:
1) Follow the software instructions and lab manual for using the software.
2) Be careful while input the variables value before run the code.
3) Always work in the editor environment. This will you to edit the Matlab Code.
4) Do not turn off your pc or laptop while simulating the design.
5) Check your code with the desired input data.
6) Never hurry. Hurry can cause error in simulation.
7) After simulation collect all the data and graphs carefully, take screen shot if necessary.
Data Analysis:
Report:
1) Submit the complete data sheet with the screenshots of Matlab code and Output
Graphs.
2) Using various variables value complete the data table, observe the output graphs and
write a report
References
1. Li Tan, Purdue University, Jean Jiang, Purdue University “Digital Signal Processing:
Fundamentals and Applications’’.
2. Website: https://www.mathworks.com/products/matlab.html
1 + 1.16180𝑧 −1 + 𝑧 −2
𝐻(𝑧) =
1 − 1.5161𝑧 −1 + 0.878𝑧 −2
Plot the frequency response of the system using MATLAB. Assume a sampling frequency
of 500 Hz and a resolution of <1 Hz for the frequency response.?
2. The coefficients of a FIR filter are stored in the file ‘coeff2.mat’. Plot the frequency
EEE-314-95 | P a g e
response this filter. What type of filter is it? What is the cutoff frequency of the filter? Do
the same tasks in Example 03 for the audio samples ‘train’ and ‘handle’ using the provided
filter.
EEE-314-96 | P a g e
Experiment No. 11:
Name of the Experiment: Design a LP FIR filter in MATLAB
Objective:
The objectives of this experiment are to:
1) Learn to analyze a LP FIR filter.
2) To implement LP FIR filter for a given sequence.
3) Apply filters or systems to some real world and observe the response.
Domain /
Delivery
Corresponding level of Assessment
CO Statement methods and
PO learning tools
activities
taxonomy
Lab tests
CO2:Analyze Lab
discrete time Simulation
Investigation( reports
systems using Affective Experiment
PO4) Final lab
signal
ModernTool domain/ Practice lab test
processing and
Usage: (PO5) valuing
symbolic Group Open
level
toolboxes of discussion ended lab
MATLAB.
Tutorial Project
show & project
presentation
Theory:
FIR filters are digital filters with finite impulse response. They are also known asnon-recursive
digital filters as they do not have the feedback. An FIR filter has two important advantages over
an IIR design: Firstly, there is no feedback loop in the structure of an FIR filter. Due to not having
a feedback loop, an FIR filter is inherently stable. Meanwhile, for an IIR filter, we need to check
the stability. Secondly, an FIR filter can provide a linear-phase response. As a matter of fact, a
linear-phase response is the main advantage of an FIR filter over an IIR design otherwise, for the
same filtering specifications; an IIR filter will lead to a lower order. FIR FILTER DESIGN An
FIR filter is designed by finding the coefficients and filter order that meet certain specifications,
which can be in the time-domain (e.g. a matched filter) and/or the frequency domain (most
common). Matched filters perform a cross-correlation between the input signal and a known pulse-
shape. The FIR convolution is a cross-correlation between the input signal and a time-reversed
copy of the impulse-response. Therefore, the matched-filter’s impulse response is “designed” by
sampling the known pulse-shape and using those samples in reverse order as the coefficients of
the filter.
EEE-314-97 | P a g e
Output Graph:
EEE-314-98 | P a g e
Required Devices & Software:
3. A well configured Laptop or PC.
4. Software: Latest Matlab version. (2014-2020).
Precautions:
1) Follow the software instructions and lab manual for using the software.
2) Be careful while input the variables value before run the code.
3) Always work in the editor environment. This will you to edit the Matlab Code.
4) Do not turn off your pc or laptop while simulating the design.
5) Check your code with the desired input data.
EEE-314-99 | P a g e
6) Never hurry. Hurry can cause error in simulation.
7) After simulation collect all the data and graphs carefully, take screen shot if necessary.
Data Analysis:
Report:
3. Submit the complete data sheet with the screenshots of Matlab code and Output
Graphs.
4. Using various variables value complete the data table, observe the output graphs and
write a report
References
3) Li Tan, Purdue University,Jean Jiang, Purdue University “Digital Signal Processing:
Fundamentals and Applications’’.
4) Website: https://www.mathworks.com/products/matlab.html
EEE-314-100 | P a g e