0% found this document useful (0 votes)
129 views49 pages

S&S Lab1-13 PDF

This document provides an introduction and overview of MATLAB. It describes the MATLAB interface including the prompt, editor, and workspace. It explains how to perform basic calculations and operations in MATLAB similarly to a calculator. It introduces variables, built-in functions, binary operations, and vectors/arrays. It also describes how to access the help section and search for documentation on functions. The overall purpose is to familiarize readers with the MATLAB environment and basic functionality.

Uploaded by

faiza
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
129 views49 pages

S&S Lab1-13 PDF

This document provides an introduction and overview of MATLAB. It describes the MATLAB interface including the prompt, editor, and workspace. It explains how to perform basic calculations and operations in MATLAB similarly to a calculator. It introduces variables, built-in functions, binary operations, and vectors/arrays. It also describes how to access the help section and search for documentation on functions. The overall purpose is to familiarize readers with the MATLAB environment and basic functionality.

Uploaded by

faiza
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 49

Lab Manual EEE223 Signals and Systems

Experiment No.1 INTRODUCTION TO MATLAB


1.1 Objective
Objective of this lab is to familiarize students with MATLAB interface and some basic operations.
1.2 Introduction to MATLAB
1.2.1 The MATLAB Interface
1.2.1.1 The Prompt
Open MATLAB on your computer. You will be greeted by an interface similar to this one:

The >> symbol indicates that MATLAB is ready to accept input and it is called a prompt. Type in
the following and press enter:
>> x = 3
You will see two changes: First, MATLAB will output the value now stored in x. Second, on the
right, x will appear in the list of variables. When there is a long process taking place, the prompt
will disappear and appear again when the calculation has completed. Usually when you add a
semicolon after a statement, it means that the output won’t be shown on the screen.
1.2.1.2 The MATLAB Editor
When writing long programs or writing programs you may want to edit or run over and over, it is
better to create a script in the editor. Click “New Script” near the top left to open the editor.

Department of Electrical and Computer Engineering 1


Lab Manual EEE223 Signals and Systems

The editor is where you will write and save all your programs. For example, type The following
code in the editor:
clc;
x = inv(x);
disp(x);
And press “Run”. Once you do that, it will ask you where to save your script. Save it somewhere.
You should see something similar to the following:

1.2.1.3 Using MATLAB as a Calculator


Try entering the following in MATLAB:
>> 3 + 5
ans =

Department of Electrical and Computer Engineering 2


Lab Manual EEE223 Signals and Systems
8
>> 3 - 5
ans =
-2
Experiment with MATLAB. Do the same as we have done above with different numbers and also
*, / and ^. Apart from normal division in MATLAB, there is also the left-division operator, \. It
divides the second number (on its right) by the first and gives the result.
You can use parentheses in MATLAB as you would in normal mathematics, or on your calculator.
For example,
>> (3 + 5) * 8
ans =
64
>> 3 + 5 * 8
ans =
43
Note that MATLAB does not simply evaluate expressions from left to right, but it respects the
order of operations, which means that it does multiplication and division first, then addition and
subtraction.
1.2.2 Variables
In MATLAB, you can store the results of any calculation in a variable. Try the following in
MATLAB:
>> x = 1 / 2
x =
0.5000
>> x = 3;
If you look on the right side of MATLAB in the Workspace, you will see at least two variables
defined. You will see x with the value of 3 that you just assigned, and you will see ans, which
stores the result of the last calculation you did. Just keep in mind a few rules, MATLAB variables
always start with a letter, and can have letters, numbers or underscores in them.
1.2.3 Built-In Functions and Variables
MATLAB has a big library of built-in functions that can do special jobs. For example,
>> theta = pi;
>> x = cos(theta);
>> y = sin(theta);
Check the workspace and you will see that it has three new variables: theta, x, and y. In the
table below you will find some common functions used in calculations and their explanation.
Note also that the semicolon after a statement means it won’t show the output, but it will store
it.
MATLAB Expression Meaning
sqrt(x) √𝑥
𝑛
nthroot(x, n) √𝑥

Department of Electrical and Computer Engineering 3


Lab Manual EEE223 Signals and Systems
log(x) ln 𝑥 = log 𝑒 𝑥
log10(x) lg 𝑥 = log10 𝑥
log(x)/log(b) log 𝑏 𝑥
exp(x) 𝑒𝑥
pi 𝜋
sin(x) sin 𝑥
cos(x) cos 𝑥
tan(x) tan 𝑥
csc(x) csc 𝑥 = sin1 𝑥
sec(x) sec 𝑥 = cos1 𝑥
cot(x) cot 𝑥 = tan1 𝑥
asin(x) sin−1 𝑥
acos(x) cos−1 𝑥
atan(x) tan−1 𝑥
atan2(y,x) tan−1(𝑦, 𝑥) (takes care of the quadrant)
𝑥 −𝑒−𝑥
sinh(x) sinh 𝑥 = 𝑒 2

cosh(x) 𝑒𝑥 +𝑒−𝑥
cosh 𝑥 = 2
𝑥 −𝑥
tanh(x) sinh 𝑥
tanh 𝑥 = cosh = 𝑒𝑒𝑥 −𝑒
𝑥 +𝑒−𝑥

i 𝑖 = √−1
real(z) Re{𝑧}
imag(z) Im{𝑧}
abs(z) |𝑧|
angle(z) ∠𝑧
conj(z) 𝑧∗
rand Random number between 0 and 1.
randn Random number that follows a standard Normal (Gaussian)
distribution.
randi([min max]) Random integer between min and max.
1.2.4 Binary Operations in MATLAB
MATLAB has a lot of operators and functions you can use to check relationships between two
numbers. Each of them returns 0 or 1, for false and true, respectively.

Department of Electrical and Computer Engineering 4


Lab Manual EEE223 Signals and Systems
MATLAB Expression Explanation
a == b Is a equal to b?
a > b Is a greater than b?
a >= b Is a greater than or equal to b?
a < b Is a less than b?
a <= b Is a less than or equal to b?
a ~= b Opposite of a == b.
a && b Returns true if both a and b are true.
a || b Returns true if one or both of a and b are true.
xor(a, b) Returns true if exactly one of a and b are true.
~a Returns the opposite of a.
true Always true.
false Always false.
We can use these as follows:
>> 5 > 3
ans =
1
>> 5 < 3
ans =
0
>> 5 > 3 && 3 < 5
ans =
1
1.2.5 The Help Section
Stuck somewhere? There’s always the MATLAB help. Please attempt to solve your own problems
before asking the instructor; that’s how you learn. There are two main ways to access the help. The
first is by pressing F1 on your keyboard. This should bring up a window like the following in
which you can search for in-built functions or help, or look up the syntax of a function:

Department of Electrical and Computer Engineering 5


Lab Manual EEE223 Signals and Systems

The second way is to type in help <function name>. This way, you can quickly look up the
syntax or what a function does without opening the Help Centre. Type in help inv. You will see
something like the following:

You can also jump directly to the help section of a function by typing doc <function name>.

Department of Electrical and Computer Engineering 6


Lab Manual EEE223 Signals and Systems
1.2.6 Vectors/Arrays
Row vectors, also known as 1-D arrays, are defined in MATLAB like this:
>> x = [2 5 4 3 1]
x =
2 5 4 3 1
>> x = [2, 5, 4, 3, 1]
x =
2 5 4 3 1
To access one element of a row vector, you can do this:
>> x(3)
ans =
4
Note that the numbering of an array starts at 1 in MATLAB. Many of the functions we studied
above can be applied to arrays as well. For example,
>> sqrt(x)
ans =
1.4142 2.2361 2.0000 1.7321 1.0000
If arrays are of the same length, addition and subtraction works as usual. You can also
multiply/divide an array by a number (also known as a scalar) with * and /. However, if you want
to multiply two arrays or divide them element by element, you need to use the operators .* and
./, along with .\, for example:
>> x .* x
ans =
4 25 16 9 1
You can do something similar for exponentiation:
>> x .^ 3
ans =
8 125 64 27 1

A similar thing applies for binary operators. You need to use & instead of && and | instead of ||
when working with arrays.
Here are some special commands for generating arrays, along with their explanation. Note that
commands that have a different behavior as compared to scalars are repeated below for clarity.
MATLAB Expression Explanation
a:b An array starting at a and ending at b with steps of 1.
a:step:b An array starting at a and ending at b with a step size of
step.
linspace(a, b, n) An array starting at a, ending at b, with a total of n points.
rand([1 n]) An array of n points where each element is a random
number between 0 and 1.

Department of Electrical and Computer Engineering 7


Lab Manual EEE223 Signals and Systems
randn([1 n]) An array of n points where each element is a sample from
a standard normal distribution.
randi([min max], [1 n]) An array of random integers with n points, each of them
between min and max.
true([1 n]) An array of n points, all containing true.
false([1 n]) An array of n points, all containing false.
zeros([1 n]) An array of n points, all containing 0.
ones([1 n]) An array of n points, all containing 1.
mean(a) Mean of all elements of a.
median(a) Median of all elements of a.
sort(a) Sorts the elements of a.
Sort(a, 'descend'); Sorts the elements of a in descending order.
max(a) Maximum of all elements of a.
min(a) Minimum of all elements of a.
[m, i] = max(a) Stores the maximum of a in m and its index in i.
[m, i] = min(a) Stores the minimum of a in m and its index in i.
sum(a) Sum of all elements of a.
cumsum(a) Cumulative sum, where each element is the sum of all
previous elements.
prod(a) Product of all elements of a.
diff(a) Difference between successive elements of a.
find(a) Returns the indexes where the array a is not 0 or false.
x(a) Returns x only where a is not false. For example, if x =
[1 2 3 4 5] and a = [true false true false
true], then x(a) will return [1 3 5].

You can also combine indexing and arrays. For example,


>> x(1:3)
ans =
1 2 3
>> x(1:2:5)
ans =
1 3 5
>> x(4:end)
ans =
4 5
>> x(end-2:end)
ans =

Department of Electrical and Computer Engineering 8


Lab Manual EEE223 Signals and Systems
3 4 5
1.2.7 Matrices
First, we will go through some basic operations in MATLAB. Basic programming knowledge is
assumed. If the matrix 𝑥 is defined as
1 2
𝑥≜[ ]
3 4
we write this in MATLAB as
>> x = [1 2; 3 4];
or, equivalently
>> x = [1, 2; 3, 4]
x =
1 2
3 4
Below are some MATLAB expressions relating matrices and their explanation.
MATLAB Expression Explanation
A * B The matrix multiplication of A and B.
A.' The transpose of the matrix A.
A' The conjugate-transpose of the matrix A.
A^n The square matrix A to the power of n.
rand([m n]) An matrix of order 𝑚 × 𝑛 where each element is a random
number between 0 and 1.
randn([m n]) An matrix of order 𝑚 × 𝑛 where each element is a sample
from a standard normal distribution.
randi([min max], [m n]) An matrix of random integers of order 𝑚 × 𝑛, each of
them between min and max.
true([m n]) An matrix of order 𝑚 × 𝑛, all containing true.
false([m n]) An matrix of order 𝑚 × 𝑛, all containing false.
zeros([m n]) An matrix of order 𝑚 × 𝑛, all containing 0.
ones([m n]) An matrix of order 𝑚 × 𝑛, all containing 1.
eye(n) An identity matrix of order 𝑛 × 𝑛.
inv(x) The inverse of square matrix x.
det(x) The determinant of the square matrix x.
size(x) Returns [m n] if x is 𝑚 × 𝑛
diag(x) If x is a matrix, this returns an array with the diagonal
elements of x. If x is an array, this creates a diagonal

Department of Electrical and Computer Engineering 9


Lab Manual EEE223 Signals and Systems
matrix where the elements of x lie along the diagonal and
the rest are zeroes.
A \ B or B / A Solves the matrix equation 𝐴𝑋 = 𝐵 for the matrix 𝑋.
More efficient than doing inv(A) * B.
x(a) Returns x only where a is not false. For example, if x =
[1 2; 3 4] and a = [true false; false true],
then x(a) will return [1 4].

1.3 In-Lab Tasks


1. Generate the vectors:
A = [1 0 4 5 3 9 0 2]
B = [4 5 0 2 0 0 7 1]
C = [B A]
D = [0 0 0 ⋯ 0] % (size = 1x50)
E = [1 1 1 ⋯ 1] % (size = 1x100)
F = [1 2 3 ⋯ 30]
G = [25 22 19 16 ⋯ 1]
H = [0 0.2 0.4 ⋯ 2.0]
2. Perform following operations on vectors:
V1 = [1 2 3 4 5 6 7 8 9 0]
V2 = [0.3 1.2 0.5 2.1 0.1 0.4 3.6 4.2 1.7 0.9]
V3 = [4 4 4 4 3 3 2 2 2 1]
a) Calculate the sum of all elements in vectors V1, V2 and V3.
b) Calculate the sum of vectors V1, V2 and V3
c) Generate new vectors V4 = (first 5 elements of V2) and V5 = (last 5 elements of
V2) using V2.
d) Generate new vector V6 whose elements are 1st, 3rd, 5th, 7th and 9th elements of V2
3. Define vector N = [1 2 3 4 5] and obtain following vectors by using array operations on N.
a) N1 = [2 4 6 8 10]
b) N2 = [1/2 1 3/2 2 5/2]
c) N3 = [1 1/2 1/3 1/4 1/5]
4. Define a vector V = [1 2 …. 10]. Write a code by using length command and accessing
elements of V such that the 1st element of V is multiplied by length of V, 2nd element by
length of V – 1 and similarly the last element is multiplied by length of V – 9. The resultant
vector should be [10 18 24 28 30 30 28 24 18 10].
1.4 Post-Lab Tasks
Task 1: Create a vector 𝑎 = [0, 0.1, 0.2, … , 10] and a vector 𝑏 = [cos 0 , cos 0.2 , … , cos 20].
Compute the following:
a. 𝑐 where 𝑐𝑖 = 𝑎𝑖 /𝑏𝑖 .
b. 𝑑 where 𝑑𝑖 = 𝑎𝑖4
c. The element-wise product of 𝑎 and 𝑏.
d. The dot product of 𝑎 and 𝑏.
You should submit:

Department of Electrical and Computer Engineering 10


Lab Manual EEE223 Signals and Systems
• A MATLAB script (*.m file).
• A text file containing the output of your script.
Task 2: Create a 3 × 3 matrix with all its elements randomly distributed in [0, 1]. Compute:
a. The inverse matrix.
b. The transpose of the matrix.
c. The determinant of the matrix.
d. The size of the matrix.
You should submit:
• A MATLAB script (*.m file).
• A text file containing the output of your script.
Task 3: Use the built-in function eig to find the eigenvalues and eigenvectors of the matrix 𝑥,
where
1⁄4 1⁄4 5⁄4
𝑥 ≜ [ −1 2 1 ]
− 5⁄4 − 1⁄4 15⁄4
Hint: If you are stuck, use help eig to find out all the different things eig can do.
You should submit:
• A MATLAB script (*.m file).
• A text file containing the output of your script.

Department of Electrical and Computer Engineering 11


Lab Manual EEE223 Signals and Systems
Experiment No.2 SYMBOLIC COMPUTATION, PLOTTING AND
PRIMITIVE SIGNALS
2.1 Objective
Objective of this lab is to enable students to define, compute and visualize basic signals.
2.2 Pre-Lab
Discussion about Primitive Signals
2.3 In-Lab
2.3.1 Functions
Functions are like m-files in MATLAB, except that they can be called from other files in
MATLAB. They have the same extension (*.m) but they can have inputs and outputs. The first
line of a MATLAB function has the following format:
function [y1, …, yn] = name(x1, …, xm)
Where y1, …, yn are the outputs, x1, …, xm are the inputs, and name is the name of the
function. A function must have the same filename as its name, with the .m extension. In this case,
the filename would be name.m. The file must be saved in the same path as the MATLAB working
directory. In the function, you can use the input variables as if they were already defined/given to
you, and you simply have to assign values to the output variables and MATLAB takes care of the
rest.
2.3.2 Symbolic Computation
MATLAB provides a way to do what is known as symbolic computation, which means you can
work with equations and variables instead of just numbers. Let’s try this out.
>> syms x
>> f = sin(x);
>> diff(f)
ans =
cos(x)
This is very useful for us as we can play with and simplify all sorts of expressions.
>> f = sin(x)^2 + cos(x)^2;
>> simplify(f)
ans =
1
We can also have an expression of more than one variable.
syms x y z
>> exp(x * y * z);
>> f = exp(x * y * z);
>> [diff(f, x); diff(f, y); diff(f, z)]
ans =
y*z*exp(x*y*z)
x*z*exp(x*y*z)
x*y*exp(x*y*z)

Department of Electrical and Computer Engineering 12


Lab Manual EEE223 Signals and Systems
We can also make equations look nicer in MATLAB:
>> pretty(ans)
/ y z exp(x y z) \
| |
| x z exp(x y z) |
| |
\ x y exp(x y z) /
Here is a list of common functions you can use for symbolic mathematics in MATLAB.
MATLAB Expression Explanation
syms x1 x2 … xn Define x1, x2, …, xn as symbolic variables.
diff(y, x) 𝜕𝑦
Compute 𝜕𝑥 .
diff(y, x, n) 𝜕𝑛 𝑦
Compute 𝜕𝑥 𝑛 .
int(y, x) Compute ∫ 𝑦 𝑑𝑥.
int(y, x, a, b) 𝑏
Compute ∫𝑎 𝑦 𝑑𝑥 .
limit(f, x, a) Compute lim 𝑓(𝑥).
𝑥→𝑎

limit(f, x, a, 'left') Compute lim− 𝑓(𝑥).


𝑥→𝑎

limit(f, x, a, 'right') Compute lim+ 𝑓(𝑥).


𝑥→𝑎

solve(f, x) Solve the equation 𝑓(𝑥) = 0 for 𝑥.


solve(f == g, x) Solve the equation 𝑓(𝑥) = 𝑔(𝑥) for 𝑥.
simplify(f) Simplify the expression f.
expand(f) Expand the expression f.
factor(f) Factor the expression f.
subs(f, x, val) Substitute val in place of x in f.
2.3.3 Plotting functions in MATLAB
You can use the plot function in MATLAB to plot continuous time signals or the stem function
to plot discrete time signals.
>> t = -pi:0.01:pi;
>> plot(t, sin(t))
As you enter the second command, another window will pop up with a figure in it.

Department of Electrical and Computer Engineering 13


Lab Manual EEE223 Signals and Systems

Now enter the following:


>> plot(t, cos(t))
You will notice that the sine was replaced by a cosine in the same figure. To open a new figure,
you can enter the command figure.
You can also do something like this to switch between figures in your code:
>> figure(1) % Open new figure with ID 1
>> % Plot something
>> figure(2) % Open new figure with ID 2
>> % Plot something (this will be in plot 2)
>> figure(1)
>> % Plot something (this will be in plot 1 again)
Now try this:
>> plot(t, sin(t), t, cos(t))
You will notice that two plots appear on the same graph in different colors.

0.8

0.6

0.4

0.2

-0.2

-0.4

-0.6

-0.8

-1
-4 -3 -2 -1 0 1 2 3 4

Now enter the following:


>> plot(t, sin(t), 'r:', t, cos(t), 'g-.')
You will get a plot like this:

Department of Electrical and Computer Engineering 14


Lab Manual EEE223 Signals and Systems
1

0.8

0.6

0.4

0.2

-0.2

-0.4

-0.6

-0.8

-1
-4 -3 -2 -1 0 1 2 3 4

The r means red and the g means green, as you might have guessed. The meanings of the other
symbols are explained below:
Symbol Color Symbol Line Type Symbol Point Type
B Blue - Solid . Point
G Green : Dotted o Circle
R Red -. Dashed- x Cross
Dotted
C Cyan _ Dashed + Plus
M Magneta * Star
Y Yellow s Square
K Black d Diamond
W White < or > Triangle
P Pentagram
h Hexagram
Beware of using the point types when there are too many points on your plot. It will result in a plot
that’s very crowded.
Below are some other commonly used plotting functions and their explanations. In this table, parts
inside square brackets are optional.
MATLAB Expression Explanation
plot(x1, y1, [x2, y2, …, xn, yn]) Plot all the functions on the same plot.
figure(n) Select the figure with ID n. If it doesn’t
exist, open a new figure.
stem(x1, y1, [x2, y2, …, xn, yn]) Make a stem plot of the functions
xlabel('label') Change the x-axis label.
ylabel('label') Change the y-axis label.
xlim([min max]) Change the x-range of the plot that is
displayed.

Department of Electrical and Computer Engineering 15


Lab Manual EEE223 Signals and Systems
ylim([min max]) Change the y-range of the plot that is
displayed.
title('title') Change the plot title.
2.3.4 Primitive Signals in MATLAB
2.3.4.1 Continuous-time
The continuous-time unit step function, also known as the Heaviside Theta function, is defined as
0 𝑡<0
𝑢(𝑡) = {
1 𝑡>0
and it is implemented in MATLAB as heaviside(t).
The derivative of the unit step function is known as the unit impulse function, or the Dirac Delta
function. It is defined as:
0 𝑡≠0
𝛿(𝑡) = {
undefined 𝑡=0

With the additional property that ∫−∞ 𝛿(𝑡) 𝑑𝑡 = 1. It is implemented as dirac(t) in MATLAB.
2.3.4.2 Discrete-time
The discrete-time unit step function is defined as
0 𝑛<0
𝑢(𝑛) = {
1 𝑛≥0
It differs from the continuous time version in that it is 1 even at 𝑛 = 0, whereas the continuous-
time version is undefined. It is not defined in MATLAB, but it can be easily defined in MATLAB
with a one-line command:
>> unitStep = @(n) double(n >= 0);
The discrete-time equivalent of the unit impulse function is known as the unit pulse function or
the Kronecker Delta function. It is defined as
1 𝑛=0
𝛿(𝑛) = {
0 𝑛≠0
It is implemented in MATLAB as kroneckerDelta(n).
2.4 In-Lab Tasks
1. Plot the function 𝑓(𝑡) = 𝑒 −0.2𝑡 sin 𝑡 between the interval 0 ≤ 𝑡 ≤ 6𝜋.
2
2. Use Subplot command to plot the graphs of 𝑡 2 , 𝑡 3 , 𝑡 4 𝑎𝑛𝑑 𝑒 −𝑡 with −10 ≤ 𝑡 ≤ 10
3. Use subplot the following discrete time sequences:
a) 𝑥[𝑛] = 𝛼 𝑛 −10 ≤ 𝑛 ≤ 10 𝛼 = 1.5
𝑛
b) 𝑥[𝑛] = 𝛽 −10 ≤ 𝑛 ≤ 10 𝛽 = 0.5
c) 𝑥[𝑛] = 𝛾 𝑛 −10 ≤ 𝑛 ≤ 10 𝛾 = −1.5
𝑛
d) 𝑥[𝑛] = 𝜑 −10 ≤ 𝑛 ≤ 10 𝜑 = −0.5
4. Plot the function 𝑥(𝑡) = 𝐴𝑅𝑒{𝑒 𝑗(𝜔𝑜 𝑡+𝜑) }, where 𝐴 = 1, 𝑓𝑜 = 10 𝐻𝑧, 𝜑 = 0
5. Plot the sequences:
1𝑛 ≤0
a) 𝑢[𝑛] = {
0𝑛 >0
−1 𝑛 < 0
b) 𝑠𝑔𝑛[𝑛] = {
1 𝑛≥0

Department of Electrical and Computer Engineering 16


Lab Manual EEE223 Signals and Systems
1 − |𝑡||𝑡| < 0
c) 𝑡𝑟𝑖(𝑡) = {
0 |𝑡| ≥ 0
𝑛𝑛≥0
d) 𝑟[𝑛] = {
0𝑛<0
2.5 Post-Lab Tasks
Task 1: Write a function that accepts as input three arguments: a vector x, and two scalars m and
1 1 𝑥−𝑚 2
s. It should plot the function 𝑦(𝑥) = 𝑠√2𝜋 𝑒 −2( 𝑠
)
.

a. Use the function to plot 𝑦(𝑥) from −5 to 5, with 𝑚 = 0 and 𝑠 = 1.


You should submit:
• A ploty.m file containing the answer to part a.
• A MATLAB script containing the answer to part b.
Task 2: Plot the continuous time signal 𝑥(𝑡) = 𝑢(𝑡 + 1) + 𝑢(𝑡 − 2) + 𝑢(𝑡 + 4) in an appropriate
interval
a. Using the built-in function heaviside.
b. Without using the built-in function heaviside.
𝑡
Hint: Define a version of heaviside yourself or using the property ∫−∞ 𝛿(𝜏) 𝑑𝜏 = 𝑢(𝑡).
You should submit:
• One MATLAB script that does both tasks. It should open both plots in separate windows.
• A heavisidecustom.m file containing the custom Heaviside definition.
Task 3: Plot these signals and discuss their periodicity.
a. cos 𝑡
b. sin 3𝑡
c. cos 𝑡 + sin 3𝑡
d. cos 𝑡 − sin 3𝑡
You should submit:
• One MATLAB script that plots all four in different windows.
• A text file that contains the period of each function.
Task 4: Repeat Question 3 with the functions
a. sin(𝜋⁄2𝑡)
b. cos(𝜋/4𝑡)
Task 5: Show the following properties using MATLAB:
𝑑
a. 𝑢(𝑡) = 𝛿(𝑡).
𝑑𝑡

b. ∫−∞ 𝛿(𝑡) 𝑑𝑡 = 1.
Hint: You can use inf in MATLAB to represent infinity.
You should submit:
• One MATLAB script that computes each part and shows the output.

Department of Electrical and Computer Engineering 17


Lab Manual EEE223 Signals and Systems
Task 6: Run the following code:
>> syms t
>> int(dirac(t), t)
And observe the output. Why is the output different from the Heaviside function? Is the output
correct?
You should submit:
• One text file with a short explanation.

Department of Electrical and Computer Engineering 18


Lab Manual EEE223 Signals and Systems
Experiment No.3 CLASSES OF SIGNALS
3.1 Objective
Objective of this lab is to classify different signals into their respective classes using MATLAB
3.2 Pre-Lab
The basic knowledge of classes of signals
3.2.1 Periodic Signals
A continuous-time signal 𝑥(𝑡) is periodic if there exists a positive number 𝑇 such that
𝑥(𝑡) = 𝑥(𝑡 + 𝑇) ∀𝑡
holds. Moreover, if 𝑇 is the smallest positive value for which this holds, then it is called the
fundamental period of the signal. Another way to define the periodicity of a signal is
𝑥(𝑡) = 𝑥(𝑡 + 𝑘𝑇) ∀𝑡 ∈ ℝ, ∀𝑘 ∈ ℤ
For example, a sinusoidal signal 𝑥(𝑡) = 𝐴 cos(𝜔𝑡 + 𝜙) is periodic with a fundamental period 𝑇 =
2𝜋 4𝜋 6𝜋
, but 𝑇 = , 𝑇 = etc. are also periods of the signal 𝑥(𝑡).
𝜔 𝜔 𝜔

A discrete-time signal 𝑥(𝑛) is periodic if there is a positive integer 𝑁 such that


𝑥(𝑛) = 𝑥(𝑛 + 𝑁) ∀𝑁 ∈ ℤ
Example: Verify that 𝑥(𝑡) = sin 𝑡 is periodic.
>> syms t
>> f = sin(t + 2*pi);
>> simplify(f)
ans =
sin(t)
2𝜋𝑀
So, it is periodic. A discrete-time signal 𝑥(𝑛) = cos(𝜔𝑛 + 𝜙) is only periodic for 𝜔 = 𝑁 for
some 𝑀, 𝑁 ∈ ℤ. If the signal 𝑥1 (𝑡) is periodic with fundamental period 𝑇1 and 𝑥2 (𝑡) is periodic
with fundamental period 𝑇2 , then the signal 𝑥sum (𝑡) = 𝑥1 (𝑡) + 𝑥2 (𝑡) is periodic if and only if
𝑚𝑇1 = 𝑛𝑇2 for some 𝑚, 𝑛 ∈ ℤ. If these are the minimum values for 𝑚 and 𝑛, then the fundamental
period of 𝑥sum (𝑡) is usually 𝑇sum = 𝑚𝑇1 = 𝑛𝑇2 .
Example: Plot the signal 𝑥(𝑡) = cos 3𝑡 + sin 𝑡. Is it periodic?
>> t = 0:0.01:6*pi;
>> x = cos(3*t) + sin(t);
>> plot(t,x) 2

1.5

0.5

-0.5

-1

-1.5

-2
0 2 4 6 8 10 12 14 16 18 20

Department of Electrical and Computer Engineering 19


Lab Manual EEE223 Signals and Systems
As we can see here, the signal is periodic. As for the period, we can use the rule above to calculate
2𝜋
that 𝑇1 = 3 , 𝑇2 = 2𝜋, 𝑚 = 3, 𝑛 = 1 and 𝑇sum = 2𝜋.
The table below lists some common commands for used periodic signals.
MATLAB Expression Explanation
[t, x] = gensig(type, period, Generates a periodic signal. type can take on
duration, samplingFreq) the values 'square' and 'pulse'.
square(t) A square wave with a period of 2𝜋.
sawtooth(t) A sawtooth wave with a period of 2𝜋.
repmat(X, [m n]) Repeat matrix X so it has m times the rows and
n times the columns.
mod(x, y) The remainder when x is divided by y.
One way to make a signal periodic is to use the mod operator, by replacing t with mod(t,
period). Then we just have to define the function for 0 ≤ 𝑡 <period and it’ll repeat for the rest.
This example shows how to plot a function defined as 𝑡𝑒 −𝑡 for 0 ≤ 𝑡 < 10 and periodic otherwise:
>> periodictexpt = @(t) mod(t, 10) .* exp(-mod(t, 10));
>> t = 0:0.1:80;
>> x = periodictexpt(t);
>> plot(t, x)
0.4

0.35

0.3

0.25

0.2

0.15

0.1

0.05

0
0 10 20 30 40 50 60 70 80

3.2.2 Causal Signals


A signal 𝑥(𝑡) (or 𝑥(𝑛)) is called causal if 𝑥(𝑡) = 0 ∀𝑡 < 0. A signal that holds nonzero values for
both positive and negative arguments is called non-causal. Finally, a signal satisfying 𝑥(𝑡) =
0 ∀𝑡 > 0 is called anti-causal. The same holds for discrete-time signals.
>> t = -1:0.01:5;
>> x1 = t .* exp(-t) .* (t > 0); % Causal
>> x2 = t .* exp(-t); % Non-causal
>> figure; plot(t,x1)
>> figure; plot(t,x2)
3.2.3 Even and Odd Signals
A signal 𝑥(𝑡) is called even if 𝑥(−𝑡) = 𝑥(𝑡) ∀𝑡 and odd if 𝑥(−𝑡) = −𝑥(𝑡) ∀𝑡. Even if a signal is
neither even nor odd, it can be split into even and odd parts:

Department of Electrical and Computer Engineering 20


Lab Manual EEE223 Signals and Systems
𝑥(𝑡) + 𝑥(−𝑡)
𝑥𝑒 (𝑡) =
2
𝑥(𝑡) − 𝑥(−𝑡)
𝑥𝑜 (𝑡) =
2
Clearly, 𝑥(𝑡) = 𝑥𝑒 (𝑡) + 𝑥𝑜 (𝑡). The same holds for discrete-time signals.
Example: Plot the even and odd parts of 𝑢(𝑛).
>> unitStep = @(n) double(n >= 0);
>> n = -5:5;
>> u_e = 0.5 * (unitStep(n) + unitStep(-n));
>> u_o = 0.5 * (unitStep(n) - unitStep(-n));
>> figure; stem(n, u_e);
>> figure; stem(n, u_o);
3.2.4 Energy and Power Signals
The energy of a signal 𝑥(𝑡) is defined by:

𝐸𝑥 = ∫ |𝑥(𝑡)|2 𝑑𝑡
−∞

And its power is defined by:


1 𝑇
𝑃𝑥 = lim ∫ |𝑥(𝑡)|2 𝑑𝑡
𝑇→∞ 2𝑇 −𝑇

In the special case that 𝑥(𝑡) is periodic with a period 𝑇, its power can also be computed by:
1 𝑡0 +𝑇
𝑃𝑥 = ∫ |𝑥(𝑡)|2 𝑑𝑡
𝑇 𝑡0
Where 𝑡0 ∈ ℝ.
For a discrete-time signal 𝑥(𝑛),
∞ 𝑁
1
𝐸𝑥 = ∑ |𝑥(𝑛)|2 , 𝑃𝑥 = lim ∑ |𝑥(𝑛)|2
𝑁→∞ 2𝑁 + 1
𝑛=−∞ 𝑛=−𝑁

For a periodic discrete-time signal 𝑥(𝑛) with a period 𝑁,


𝑛0 +𝑁−1
1
𝑃𝑥 = ∑ |𝑥(𝑛)|2
𝑁
𝑛=𝑛0

where 𝑛0 ∈ ℤ. A signal 𝑥(𝑡) or 𝑥(𝑛) is called an energy signal if 𝐸𝑥 is finite and a power signal if
𝑃𝑥 is finite and 𝑃𝑥 ≠ 0.
Example: Prove that 𝑥1 (𝑡) = sin 𝑥 is a power signal and 𝑥2 (𝑡) = 𝑡𝑒 −𝑡 𝑢(𝑡) is an energy signal.
>> syms t T
>> x1 = sin(t);
>> limit(1/(2*T)*int(x1^2, t, -T, T), T, inf)
ans =
1/2

Department of Electrical and Computer Engineering 21


Lab Manual EEE223 Signals and Systems
>> x2 = t * exp(-t) * heaviside(t);
>> int(x2^2, t, -inf, inf)
ans =
1/4
3.2.5 Deterministic and Stochastic Signals
A function is called deterministic if, every time it is realized, it has the same output. For example,
the unit step function 𝑢(𝑛) will always be the same. In contrast, a random signal has different
values every time it is realized. All signals we have studied so far are examples of deterministic
signals. Examples of stochastic signals are shown below.
>> t = 0:0.1:10;
>> x1 = randn(size(t));
>> x2 = randn(size(t));
>> x3 = randn(size(t));
>> plot(t, x1, 'r', t, x2, 'g', t, x3, 'b')
4

-1

-2

-3
0 1 2 3 4 5 6 7 8 9 10

3.3 In-Lab Tasks


1. Prove that 𝑥1 (𝑡) = cos(𝑡) is a power signal and 𝑥2 (𝑡) = 𝑒 −5𝑡 𝑢(𝑡 − 5) is an energy
signal.
2. Plot the even and odd parts of 𝑥[𝑛] = cos[𝑛] + sin[𝑛].
3. Verify that 𝑥(𝑡) = sin(𝑡) + cos(𝑡) is periodic.
3.4 Post-Lab Tasks
Task 1: Classify the following signals as even signals, odd signals or neither, using MATLAB.
a. 𝑥1 (𝑡) = 𝑢(𝑡 − 1) + 𝑢(−𝑡 + 1)
b. 𝑥2 (𝑛) = 𝛿(𝑛 + 1) − 𝛿(𝑛 − 1)
c. 𝑥3 (𝑡) = cos 𝑡 + sin 𝑡
Hint: Compute the even and odd part of each signal. If the odd part is 0, it is an even signal. If the
even part is 0, it’s an odd signal. If both exist, it is neither.
You should submit:
• A function that computes the even and odd part of a signal.
• A main script that displays the even and odd parts, simplified.
• A text file stating which function is even, which is odd, and which is neither.

Department of Electrical and Computer Engineering 22


Lab Manual EEE223 Signals and Systems
Task 2: Classify the following signals as energy or power signals.
a. 𝑥1 (𝑛) = 𝑢(𝑛)
b. 𝑥2 (𝑛) = 2−𝑛 𝑢(𝑛)
Hint: Compute both power and energy and use the definitions. You will need the symsum function,
which works similar to the int function. Make the sum go from 0 to ∞ and skip the unit step
function.
You should submit:
• A function that computes the power and energy of a signal.
• A main script that displays the power and energy.
• A text file stating which is an energy signal and which is a power signal.

Department of Electrical and Computer Engineering 23


Lab Manual EEE223 Signals and Systems
Experiment No.4 TRANSFORMATIONS OF TIME VARIABLE
4.1 Objective
Objective of this lab is to enable the students to transform signals.
4.2 Pre-Lab
The knowledge of transformations of time variables
4.2.1 Time Reversal
First, let’s define a function that we will use, and plot it. Then, we will reverse this signal in time
and see how it looks:
>> f = @(t) sin(20*t) .* exp(-t);
>> t = -1.5:0.01:1.5;
>> figure(1); plot(t, f(t))
5

-1

-2

-3

-4
-1.5 -1 -0.5 0 0.5 1 1.5

>> figure(2); plot(t, f(-t))


5

-1

-2

-3

-4
-1.5 -1 -0.5 0 0.5 1 1.5

As you can see, the signal has been flipped (mirrored) about the y-axis.
4.2.2 Time Scaling
4.2.2.1 Time Compression
Next, we will apply a time compression to a function.
>> f = @(t) cos(t);
>> t = -2*pi:0.01:2*pi;
>> figure(1); plot(t, f(t))

Department of Electrical and Computer Engineering 24


Lab Manual EEE223 Signals and Systems
1

0.8

0.6

0.4

0.2

-0.2

-0.4

-0.6

-0.8

-1
-8 -6 -4 -2 0 2 4 6 8

>> figure(2); plot(t, f(2 * t))


1

0.8

0.6

0.4

0.2

-0.2

-0.4

-0.6

-0.8

-1
-8 -6 -4 -2 0 2 4 6 8

4.2.2.2 Time Expansion


Next, we will apply a time expansion to this same function.
>> figure(3); plot(t, f(t / 2))
1

0.8

0.6

0.4

0.2

-0.2

-0.4

-0.6

-0.8

-1
-8 -6 -4 -2 0 2 4 6 8

4.2.3 Time Shifting


4.2.3.1 Time Delay
Now we will explore how a time delay works.
>> f = @(t) t .* exp(-t) .* heaviside(t);
>> t = -6:0.01:6;
>> figure(1); plot(t, f(t))

Department of Electrical and Computer Engineering 25


Lab Manual EEE223 Signals and Systems
0.4

0.35

0.3

0.25

0.2

0.15

0.1

0.05

0
-6 -4 -2 0 2 4 6

>> figure(2); plot(t, f(t – 2))


0.4

0.35

0.3

0.25

0.2

0.15

0.1

0.05

0
-6 -4 -2 0 2 4 6

4.2.3.2 Time Advance


>> figure(2); plot(t, f(t + 2))
0.4

0.35

0.3

0.25

0.2

0.15

0.1

0.05

0
-6 -4 -2 0 2 4 6

4.2.4 Order of Transformations


If you have multiple transformations in a single function, you will apply time shifts first, then time
scaling or reversal. For example, to get 𝑔(𝑡) = 𝑓(−3𝑡 + 5), you would follow these steps:
𝑓1 (𝑡) = 𝑓(𝑡 + 5)
𝑓2 (𝑡) = 𝑓1 (3𝑡) = 𝑓(3𝑡 + 5)
𝑔(𝑡) = 𝑓2 (−𝑡) = 𝑓(−3𝑡 + 5)
You can switch the last two steps, but the time shift must come first.
4.3 In-Lab Tasks
1. Plot the function:𝑥(𝑡) = 𝑡𝑒 −𝑡 where −10 ≤ 𝑡 ≤ 10
a) 𝑥1 (𝑡) = 𝑥(−𝑡)
b) 𝑥2 (𝑡) = 𝑥(2𝑡)

Department of Electrical and Computer Engineering 26


Lab Manual EEE223 Signals and Systems
c) 𝑥3 (𝑡) = 𝑥(𝑡/2)
d) 𝑥4 (𝑡) = 𝑥(−1 − 3𝑡)
2. Plot the function: 𝑥[𝑛] = 0.9−𝑛 where −10 ≤ 𝑛 ≤ 10
a) 𝑥1 [𝑛] = 𝑥[−𝑛]
b) 𝑥2 [𝑛] = 𝑥[𝑛 − 9]
c) 𝑥3 [𝑛] = 𝑥[𝑛 + 9]
d) 𝑥4 [𝑛] = 𝑥[3𝑛]
𝑛
e) 𝑥5 [𝑛] = 𝑥 [ 3]
𝑡 0≤𝑡≤2
3. Plot the function: 𝑥(𝑡) = {
4−𝑡 2<𝑡 ≤4
a) 𝑥(−𝑡)
b) 𝑥(2 + 4𝑡)
c) 𝑥(−2 − 4𝑡)
4.4 Post-Lab Tasks
Task 1: Define 𝑥(𝑡) = 𝑡 cos 2𝜋𝑡. Plot the signals
a. 𝑥(𝑡)
b. 𝑥(−𝑡)
c. 𝑥(𝑡⁄5)
d. 𝑥(1 + 3𝑡)
e. 𝑥(−1 − 3𝑡)
for 0 ≤ 𝑡 ≤ 5.
You should submit a MATLAB script that plots all these in different figures, with y-labels to
distinguish between them.
1
Task 2: Suppose that 𝑥(𝑡) = 𝑡𝑒 −5𝑡 . Plot 𝑥(1 − 2𝑡) for −2 ≤ 𝑡 ≤ 2.
You should submit a MATLAB script.

Department of Electrical and Computer Engineering 27


Lab Manual EEE223 Signals and Systems
Experiment No.5 CLASSIFICATION AND PROPERTIES OF
SYSTEMS
5.1 Objective
Objective of this lab is to enable the students to classify systems and able to use their properties.
5.2 Pre-Lab
The background knowledge of LTI systems
5.2.1 Classification of Systems
5.2.1.1 According to Number of Inputs/Outputs
A system may be classified according to the number of inputs/outputs it has.
• SISO: Single Input, Single Output
• SIMO: Single Input, Multiple Output
• MISO: Multiple Input, Single Output
• MIMO: Multiple Input, Multiple Output
Example of a SISO System:
>> x = @(t) sin(t);
>> y = @(x, t) x(t) + x(t + pi/2);
>> t = -2*pi:0.01:2*pi;
>> plot(t, x(t), 'b', t, y(x, t), 'r');
Example of a MIMO System:
>> x1 = @(t) sin(t);
>> x2 = @(t) cos(t);
>> y1 = @(x1, x2, t) x1(t) + x2(t);
>> y2 = @(x1, x2, t) x1(t) - x2(t);
5.2.1.2 According to the Type of Inputs/Outputs
A system can be classified according to the type of inputs/outputs it has. For example
• A discrete-time system has discrete-time inputs and outputs, and components of the system
are also in discrete-time. Example: A summer.
• A continuous-time system has continuous-time inputs and outputs, and components of the
system are also in continuous-time. Example: A differentiator.
• A hybrid system is one where the inputs and outputs are of different types, or it has
components that are both continuous or discrete time. A simple example is a system that
samples a continuous-time signal to get a discrete-time output.
5.2.1.3 Deterministic and Stochastic Systems
• A deterministic system is one that always produces the same output given input.
• A stochastic system is one that may not produce the same output, even if it is given the
same input every time.
All systems above are deterministic systems. An example of a stochastic system is a sensor: it adds
noise to the original measurement. For example:

Department of Electrical and Computer Engineering 28


Lab Manual EEE223 Signals and Systems
>> y = @(x, t) x(t) + randn(size(t));
5.2.2 Properties of Systems
5.2.2.1 Causal and Non-Causal Systems.
A system is deemed causal if, at any point in time, its output does not depend on future values of
inputs. For example,
>> y = @(x, t) x(t) + x(t - 1);
is a causal system, because at any given time 𝑡0 , the value of its output only depends on values of
𝑡 such that 𝑡 ≤ 𝑡0 . However,
>> y = @(x, n) x(n) + x(n + 1);
is non-causal, because its output depends on future values of the input signal.
5.2.2.2 Static (Memory-less) and Dynamic (with Memory) Systems
A static system is one that has no memory. Its output at any time depends only on the current value
of the input. For example:
𝑆{𝑥(𝑡)} = 𝑥(𝑡)2
A dynamic system is a system where the output can depend not only on the current value of the
input, but may also past and future values. For example,
1
𝑆{𝑥(𝑛)} = (𝑥(𝑛 − 1) + 2𝑥(𝑛) + 𝑥(𝑛 + 1))
2
5.2.2.3 Linear Systems
5.2.2.3.1 Additive System
An additive system is one for which the following property holds:
𝑆{𝑥1 (𝑡) + 𝑥2 (𝑡)} = 𝑆{𝑥1 (𝑡)} + 𝑆{𝑥2 (𝑡)} ∀𝑥1 , 𝑥2 , 𝑡
For example, the system
𝑆{𝑥(𝑡)} = Re{𝑥(𝑡)}
is an additive system, while
𝑆{𝑥(𝑡)} = |𝑥(𝑡)|
is not, because additivity doesn’t hold for, for example, 𝑥1 (𝑡) = cos 𝑡 and 𝑥2 (𝑡) = 𝑗 sin 𝑡.
5.2.2.3.2 Homogenous System
A homogenous system is one for which the following property holds:
𝑆{𝑎𝑥(𝑛)} = 𝑎𝑆{𝑥(𝑛)} ∀𝑥, 𝑎, 𝑛
For example, the system
𝑆{𝑥(𝑡)} = 3𝑥(𝑡)
Is homogenous while
𝑆{𝑥(𝑡)} = |𝑥(𝑡)|
isn’t, because the condition only holds for 𝑎 ≥ 0, but not for negative or complex-valued 𝑎.

Department of Electrical and Computer Engineering 29


Lab Manual EEE223 Signals and Systems
5.2.2.3.3 Linearity of a System
A system is called linear if it satisfies both the additivity property and also the homogeneity
property.
5.2.2.4 Shift-Variant and Shift-Invariant Systems
A system is called a shift-invariant if a shift in the input results in the same amount of shift in the
output. Concretely, if 𝑆{𝑥(𝑛)} = 𝑦(𝑛), then a system is called shift invariant if and only if
𝑆{𝑥(𝑛 − 𝑛0 )} = 𝑦(𝑛 − 𝑛0 ) ∀𝑥, 𝑛0
If the independent variable of the system is time, then the system is also called time-invariant. A
system that is not shift-invariant or time-invariant is called shift-variant or time-variant. For
example, the system
𝑆{𝑥(𝑡)} = 𝑥 2 (𝑡) − 𝑥(𝑡 + 3)
is shift-invariant while the system
𝑆{𝑥(𝑡)} = 𝑥(3𝑡)
is not.
5.2.2.5 Stable and Unstable Systems
A system is called stable if the following principle holds:
|𝑆{𝑥(𝑛)}| ≤ 𝑏 ∀𝑛, 𝑥
for 𝑏 ∈ ℝ+ given that |𝑥(𝑛)| ≤ 𝑎 ∀𝑛 and 𝑎 ∈ ℝ+ .
For example, the system
𝑆{𝑥(𝑛)} = 2−𝑛 𝑥(𝑛)𝑢(𝑛)
is stable, while
𝑆{𝑥(𝑛)} = 2−𝑛 𝑥(𝑛)
is not.
5.3 In-Lab Tasks
For the system defined below describe if the system is Causal/Non-Causal, Linear/Non-Linear,
Static/Dynamic, Shift-invariant/Shift-variant and Stable/Unstable.
𝑦[𝑛] = 𝑥[𝑛] + 𝑛𝑥[𝑛 + 1], 𝑥1 [𝑛] = 𝑒𝑥𝑝[−𝑛] and 𝑥2 [𝑛] = sin[𝑛]
5.4 Post-Lab Tasks
Task 1: Demonstrate that the system 𝑆{𝑥(𝑛)} = 𝑥(𝑛) + 𝑥(𝑛 − 1) is a linear and time-invariant
system for 𝑥1 [𝑛] = 𝑒𝑥𝑝[−𝑛] and 𝑥2 [𝑛] = sin[𝑛].
Task 2: Is the system 𝑆{𝑥(𝑡)} = 𝑥(𝑡⁄3) a causal system for 𝑥(𝑡) = 2−𝑡 ? How about 𝑆{𝑥(𝑡)} =
𝑥(𝑡⁄3)𝑢(𝑡)? Why?

Department of Electrical and Computer Engineering 30


Lab Manual EEE223 Signals and Systems
Experiment No.6 LINEAR TIME-INVARIANT SYSTEMS AND
THE CONVOLUTION INTEGRAL
6.1 Objective
To enable the students to compute convolution for continuous time signals of LTI systems.

6.2 Pre-Lab
The discussion about linear time invariant system and integral convolution
6.2.1 The Impulse Response and the Convolution Integral
The impulse response of a continuous-time system 𝑆, denoted by ℎ(𝑡), is defined as

ℎ(𝑡) ≜ 𝑆{𝛿(𝑡)}.
In words, if a continuous-time system is given a Dirac delta function as an input, the resulting
output is known as the impulse response. It turns out that for LSI (Linear Shift-Invariant) systems,
knowing the impulse response ℎ(𝑡) and the input signal 𝑥(𝑡) is enough to find the output 𝑦(𝑡). In
this case, the following equation holds:

𝑦(𝑡) = (𝑥 ∗ ℎ)(𝑡)

≜ ∫ 𝑥(𝜏)ℎ(𝑡 − 𝜏) 𝑑𝜏
−∞

6.2.2 Symbolic Evaluation of the Convolution Integral with MATLAB


First of all we will see how we evaluate the convolution integral if we have an expression for
𝑥(𝑡)and ℎ(𝑡).
>> syms t tau
>> x = @(t) dirac(t);
>> h = @(t) exp(-t) .* heaviside(t);
>> y = @(t) int(x(tau) .* h(t - tau), tau, -inf, inf);
>> y(t)
ans =
(exp(-t)*(sign(t) + 1))/2
>>tr = -1:0.01:5;
>> plot(tr, y(tr))
1

0.9

0.8

0.7

0.6

0.5

0.4

0.3

0.2

0.1

0
-1 0 1 2 3 4 5

Department of Electrical and Computer Engineering 31


Lab Manual EEE223 Signals and Systems
However, this takes a long time to compute because of the way MATLAB implements it, as it
evaluates the integral at each point. An alternative is to evaluate the integral, and store it manually:
>> y = @(t) (exp(-t).*(sign(t) + 1))/2;
>> plot(tr, y(tr))
You should notice that this evaluates much faster. One thing to take care of is you must replace all
operators by their point-wise counterparts. Symbolic evaluation is very accurate.
6.2.3 Numerical Evaluation of the Convolution Integral
An alternative approach is to evaluate the integral numerically. This may not be very accurate but
is sometimes needed when analytical solutions cannot be found. Here, we use the property that if
𝑥(𝑡) is nonzero only for 𝑡1𝑥 ≤ 𝑡 ≤ 𝑡2𝑥 and ℎ(𝑡), is nonzero only for 𝑡1ℎ ≤ 𝑡 ≤ 𝑡2ℎ , then (𝑥 ∗ ℎ)(𝑡)
is nonzero for 𝑡1𝑥 + 𝑡1ℎ ≤ 𝑡 ≤ 𝑡2𝑥 + 𝑡2ℎ . Let’s put this into practice.
>> x = @(t) heaviside(t) - heaviside(t - 1);
>> h = @(t) heaviside(t) - heaviside(t - 2);
>> tx = 0:0.01:1;
>> t1x = 0;
>> t2x = 1;
>> t1h = 0;
>> t2h = 2;
>> ts = 0.01;
>> tx = t1x:ts:t2x;
>> th = t1h:ts:t2h;
>> t1y = t1x + t1h;
>> t2y = t2x + t2h;
>> ty = t1y:ts:t2y;
>> xr = x(tx);
>> hr = h(th);
>> yr = ts * conv(xr, hr);
>> plot(ty, yr)
1

0.9

0.8

0.7

0.6

0.5

0.4

0.3

0.2

0.1

0
0 0.5 1 1.5 2 2.5 3

Here, ts is the sampling time and the conv function calculates the discrete-time convolution. We
will learn more about this in the next experiment.

Department of Electrical and Computer Engineering 32


Lab Manual EEE223 Signals and Systems
6.3 In-Lab Task
Compute and plot the convolution 𝑦(𝑡) = 𝑥(𝑡) ∗ ℎ(𝑡), where
1 −𝑡
1. 𝑥(𝑡) = (3) 𝑢(−𝑡 − 1) and ℎ(𝑡) = 𝑢(𝑡 − 1)
1 0≤𝑡≤4 𝑡
2. 𝑥(𝑡) = { and ℎ(𝑡) = { 1.5 0 ≤ 𝑡 ≤ 6
0 𝑒𝑙𝑠𝑒𝑤ℎ𝑒𝑟𝑒 0 𝑒𝑙𝑠𝑒𝑤ℎ𝑒𝑟𝑒
3. 𝑥(𝑡) = 2−𝑡 𝑢(−𝑡) and ℎ(𝑡) = 𝑢(𝑡)
4. 𝑥(𝑡) = 𝑢(𝑡) − 𝑢(𝑡 − 4) and ℎ(𝑡)(𝑡) = 𝛿(𝑡) − 𝛿(𝑡 − 2)

6.4 Post-Lab Task


Calculate the symbolic convolution between the following pairs of functions.

a. 𝑥1 (𝑡) = 𝑢(𝑡) and ℎ1 (𝑡) = cos(10𝑡) 𝑒 −𝑡 𝑢(𝑡).


b. 𝑥2 (𝑡) = sin(5𝑡) and ℎ2 (𝑡) = 𝑒 −10𝑡 𝑢(𝑡).
𝑑
c. 𝑥3 (𝑡) = 𝑡𝑢(𝑡) and ℎ3 (𝑡) = 𝑑𝑡 𝛿(𝑡).
For part c, what does your intuition tell you is correct? Calculate the result manually and submit it
as well.

Hint: Type help dirac if you are stuck.

You should submit a *.mat file that calculates the answers and a handwritten sheet with the
answer to part c.

Department of Electrical and Computer Engineering 33


Lab Manual EEE223 Signals and Systems
Experiment No.7 LINEAR TIME-INVARIANT SYSTEMS AND
THE CONVOLUTION SUM
7.1 Objective
To enable the students to compute convolution for discrete time signals of LTI systems

7.2 Pre-Lab
The discussion about convolution sum.
7.2.1 The Impulse Response and the Convolution Sum
The impulse response of a discrete-time system 𝑆, denoted by ℎ(𝑛), is defined as

ℎ(𝑛) ≜ 𝑆{𝛿(𝑛)}.
In words, if a discrete-time system is given a Kronecker delta function as an input, the resulting
output is known as the impulse response. It turns out that for LSI (Linear Shift-Invariant) systems,
knowing the impulse response ℎ(𝑛) and the input signal 𝑥(𝑛) is enough to find the output 𝑦(𝑛).
In this case, the following equation holds:

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

≜ ∑ 𝑥(𝑘)ℎ(𝑛 − 𝑘)
𝑘=−∞

7.2.2 Symbolic Evaluation of the Convolution Sum with MATLAB


First of all we will see how we evaluate the convolution sum if we have an expression for 𝑥(𝑛)
and ℎ(𝑛).
>> syms n k
>> x = @(n) kroneckerDelta(n);
>> unitStep = @(n) heaviside(n + 0.5);
>> h = @(n) 2.^(-n) .* unitStep(n);
>> y = @(n) symsum(x(k) .* h(n - k), k, -inf, inf);
>> y(n)
ans =
1/2^n*heaviside(n + 1/2)
>> nr = -3:10;
>> stem(nr, y(nr))
1

0.9

0.8

0.7

0.6

0.5

0.4

0.3

0.2

0.1

0
-4 -2 0 2 4 6 8 10

Department of Electrical and Computer Engineering 34


Lab Manual EEE223 Signals and Systems
However, this takes a long time to compute because of the way MATLAB implements it, as it
evaluates the sum at each point. An alternative is to evaluate the sum, and store it manually:
>> y = @(n) 1./2.^n.*heaviside(n + 1/2);
>> plot(tr, y(tr))
You should notice that this evaluates much faster. One thing to take care of is you must replace all
operators by their point-wise counterparts. Symbolic evaluation is very accurate.
You might notice that we used heaviside(n + 0.5) as the discrete-time unit step function.
This is because heaviside(n) evaluates to 0.5 at 𝑛 = 0, so to avoid that, we use the given
function that returns the correct result for all integers.
7.2.3 Numerical Evaluation of the Convolution Integral
An alternative approach is to evaluate the sum numerically. Unlike for the continuous-time case,
this is usually accurate if both the input and the impulse response are time-limited. Here, we use
the property that if 𝑥(𝑛) is nonzero only for 𝑛1𝑥 ≤ 𝑛 ≤ 𝑛2𝑥 and ℎ(𝑛), is nonzero only for 𝑛1ℎ ≤
𝑛 ≤ 𝑛2ℎ , then (𝑥 ∗ ℎ)(𝑛) is nonzero for 𝑛1𝑥 + 𝑛1ℎ ≤ 𝑛 ≤ 𝑛2𝑥 + 𝑛2ℎ . Let’s put this into practice.
>> x = @(n) sin(2 * pi * n / 10) .* (unitStep(n) - unitStep(n -
11));
>> h = @(n) cos(2 * pi * n / 20) .* (unitStep(n) - unitStep(n -
21));
>> nx1 = 0; nx2 = 10;
>> nh1 = 0; nh2 = 20;
>> ny1 = nx1 + nh1; ny2 = nx2 + nh2;
>> nx = nx1:nx2; nh = nh1:nh2; ny = ny1:ny2;
>> xr = x(nx);
>> hr = h(nh);
>> yr = conv(xr, hr);
>> stem(ny, yr)

-1

-2

-3

-4

-5
0 5 10 15 20 25 30

Department of Electrical and Computer Engineering 35


Lab Manual EEE223 Signals and Systems
7.3 In-Lab Task
Compute and plot the convolution 𝑦[𝑛] = 𝑥[𝑛] ∗ ℎ[𝑛], where
1 −𝑛
1. 𝑥[𝑛] = (3) 𝑢[−𝑛 − 1] and ℎ[𝑛] = 𝑢[𝑛 − 1]
1 0≤𝑛≤4 1.5𝑛 0 ≤ 𝑛 ≤ 6
2. 𝑥[𝑛] = { and ℎ[𝑛] = {
0 𝑒𝑙𝑠𝑒𝑤ℎ𝑒𝑟𝑒 0 𝑒𝑙𝑠𝑒𝑤ℎ𝑒𝑟𝑒
3. 𝑥[𝑛] = 0.2−𝑛 𝑢[−𝑛] and ℎ[𝑛] = 𝑢[𝑛 − 2]
4. 𝑥[𝑛] = 𝑢[𝑛] − 𝑢[𝑛 − 4] and ℎ[𝑛] = 𝛿[𝑛] − 𝛿[𝑛 − 2]

7.4 Post-Lab Task


Calculate the symbolic convolution between the following pairs of functions.

a) 𝑥1 (𝑛) = 𝑢(𝑛) and ℎ1 (𝑛) = 2−𝑛 𝑢(𝑛).


b) 𝑥2 (𝑛) = sin(𝑛𝜋⁄5) 𝑢(𝑛) and ℎ2 (𝑛) = 3−𝑛 𝑢(𝑛).
c) 𝑥3 (𝑛) = (𝑛 + 1)𝑢(𝑛) and ℎ3 (𝑛) = 𝛿(𝑛) − 𝛿(𝑛 − 1).
You should submit a MATLAB *.m file. Leave the answers as they are, do not try to simplify
them.

Department of Electrical and Computer Engineering 36


Lab Manual EEE223 Signals and Systems
Experiment No.8 DISCRETE- AND CONTINUOUS-TIME
FOURIER SERIES
8.1 Objective
To enable the students to compute continuous and discrete time Fourier series.

8.2 Pre-Lab
The basics knowledge of discrete and continuous time Fourier series
8.2.1 The Discrete-Time Fourier Series
If a discrete-time signal is periodic with a fundamental period of 𝑁, then its Discrete-Time Fourier
Series (DTFS) is given by
𝑁−1
1
𝑋(𝑘) = ℱ{𝑥(𝑛)} = ∑ 𝑥(𝑛)𝑒 −𝑗2𝜋𝑘𝑛⁄𝑁 ,
𝑁
𝑛=0

and it is also periodic with a fundamental period of 𝑁. To get 𝑥(𝑛) back from 𝑋(𝑘), we use the
formula
𝑁−1

𝑥(𝑛) = ℱ −1 {𝑋(𝑘)}
= ∑ 𝑋(𝑘)𝑒 𝑗2𝜋𝑘𝑛⁄𝑁 .
𝑘=0

This formula is also known as the discrete-time Fourier series representation of a signal. The since
both the series and its inverse are periodic, it is always sufficient to look at them for one time
period only. We evaluate the Fourier series in MATLAB with the fft function and its inverse
with the ifft function.

>> n = 0:7;
>> x = [1 5 3 4 0 7 2 6];
>> X = fft(x);
>> figure; plot(n, x); xlim([0 7]);
>> figure; plot(n, abs(X)); xlim([0 7]);
>> figure; plot(n, angle(X)); xlim([0 7]);
>> x_recovered = ifft(X);
>> figure; plot(n, x_recovered); xlim([0 7]);

8.2.2 The Continuous-Time Fourier Series


If a continuous-time signal is periodic with a fundamental period of 𝑇, its Continuous-Time Fourier
Series (CTFS) is given by

1 𝑇⁄2
𝑋(𝑘) = ∫ 𝑥(𝑡)𝑒 −𝑗𝑘𝛺0 𝑡 𝑑𝑡,
𝑇 −𝑇⁄2

Where 𝛺0 = 2𝜋 𝑇
is known as the fundamental frequency of the signal 𝑥(𝑡). This series is generally
not periodic, and therefore has to be considered symbolically. The reverse transform is given by

𝑥(𝑡) = ∑ 𝑋(𝑘)𝑒 𝑗𝑘𝛺0 𝑡


𝑘=−∞

Department of Electrical and Computer Engineering 37


Lab Manual EEE223 Signals and Systems
which is also known as the Continuous-Time Fourier Series representation of a signal. Suppose
𝑥(𝑡) has a fundamental period of 2𝜋 and is defined in the interval 𝑡 ∈ (−𝜋, 𝜋] by
−1 −𝜋 < 𝑡 < 0
𝑥(𝑡) = {
1 0<𝑡<𝜋
Let’s implement the Fourier series of this function in MATLAB. We plug the values for 𝑇 and 𝛺0
beforehand.
>> syms t k
>> x = @(t) sign(t);
>> X = @(k) (1 / (2 * pi)) * int(x(t) .* exp(-j * k * t), t, -pi,
pi);
>> X(k)
>> kr = -10:10;
>> figure; plot(kr, real(X(kr)));
>> figure; plot(kr, imag(X(kr)));
8.3 In-Lab Task
1. The periodic signal x(t) is defined in one period as 𝑥(𝑡) = 𝑡𝑒 −𝑡 , 0 ≤ 𝑡 ≤ 6. Plot its Fourier
series.
2. Plot the Fourier Series for the periodic signal that in one period is defined by 𝑥(𝑡) =
2
𝑒 −𝑡 , −3 ≤ 𝑡 ≤ 3.
3. The periodic signal x(t) in a period is given, plot its Fourier series.
1 0≤𝑡≤1
𝑥(𝑡) = {
0 1<𝑡≤2
4. The periodic signal x(t) in a period is given, calculate its Fourier series. Furthermore, plot
the phase, magnitude, real and imaginary parts.
1 0≤𝑡≤1
𝑥(𝑡) = {
2−𝑡 1 <𝑡 ≤ 2
8.4 Post-Lab Task
Compute the Fourier Series of the function 𝑥(𝑡), with a fundamental period 𝑇 = 4, defined on
−2 ≤ 𝑡 ≤ 2 by
−1 𝑡 < −1
𝑥(𝑡) = { 1 −1 < 𝑡 < 1
−1 𝑡>1
Plot its Fourier series and display the expression for it.

Department of Electrical and Computer Engineering 38


Lab Manual EEE223 Signals and Systems
Experiment No.9 THE CONTINUOUS-TIME FOURIER
TRANSFORM
9.1 Objective
To enable the students to compute continuous time Fourier transform

9.2 Pre-Lab
Basics of continuous time Fourier transform
9.3 The Continuous-Time Fourier Transform
If a continuous-time signal 𝑥(𝑡) satisfies the property that

∫ |𝑥(𝑡)| 𝑑𝑡 ∈ ℝ+
0
−∞

then, its Fourier transform is given by the expression



ℱ{𝑥(𝑡)} = 𝑋(𝑗𝛺) = ∫ 𝑥(𝑡)𝑒 −𝑗𝛺𝑡 𝑑𝑡
−∞

which is known as the frequency domain representation of the signal 𝑥(𝑡). To represent this, we

write 𝑥(𝑡) → 𝑋(𝑗𝛺). To recover the time-domain signal from its frequency-domain representation,
we use the equation
1 ∞
𝑥(𝑡) = ℱ −1 {𝑋(𝑗𝛺)} = ∫ 𝑋(𝑗𝛺)𝑒 𝑗𝛺𝑡 𝑑𝛺.
2𝜋 −∞
ℱ −1
In this case, we write 𝑋(𝑗𝛺) → 𝑥(𝑡).

9.4 MATLAB Implementation of the Fourier Transform


Fortunately for us, MATLAB already provides the fourier and ifourier commands to make
it easy for us to compute the Fourier transform of many signals.
>> syms t Omega
>> x = @(t) heaviside(t) - heaviside(t - 1);
>> X = @(Omega) fourier(x(t), t, Omega);
>> X(Omega)
ans =
(sin(Omega) + cos(Omega)*1i)/Omega - 1i/Omega
>> X = @(Omega) (sin(Omega) + cos(Omega)*1i)./Omega - 1i./Omega;
>> Omegar = -10*pi:0.02:10*pi;
>> figure; plot(Omegar, abs(X(Omegar)));

Department of Electrical and Computer Engineering 39


Lab Manual EEE223 Signals and Systems
1

0.9

0.8

0.7

0.6

0.5

0.4

0.3

0.2

0.1

0
-40 -30 -20 -10 0 10 20 30 40

>> figure; plot(Omegar, angle(X(Omegar)));


4

-1

-2

-3

-4
-40 -30 -20 -10 0 10 20 30 40

>> x_recovered = @(t) ifourier(X(Omega), Omega, t);


>> x_recovered(t)
ans =
(pi + pi*sign(t) - 2*pi*heaviside(t - 1))/(2*pi)
>> x_recovered = @(t) (pi + pi*sign(t) - 2*pi*heaviside(t -
1))/(2*pi);
>> tr = -1:0.01:3;
>> plot(tr, x(tr))
>> figure; plot(tr, x(tr));
1

0.9

0.8

0.7

0.6

0.5

0.4

0.3

0.2

0.1

0
-1 -0.5 0 0.5 1 1.5 2 2.5 3

Department of Electrical and Computer Engineering 40


Lab Manual EEE223 Signals and Systems
9.5 In-Lab Tasks
Compute the continuous-time Fourier transform for:

1. 𝑥1 (𝑡) = 1, 0 ≤ 𝑡 ≤ 5
2. 𝑥2 (𝑡) = 2𝑒 −2𝑡 , 0 ≤ 𝑡 ≤ 5
3. 𝑥3 (𝑡) = 𝑢(𝑡) − 𝑢(𝑡 − 5)
4. 𝑥4 (𝑡) = 𝑒 −𝑡 𝑢(𝑡)
5. 𝑥5 (𝑡) = cos(𝑡) 𝑤ℎ𝑒𝑟𝑒 𝑡 = −2𝜋 𝑡𝑜 2𝜋
6. 𝑥6 (𝑡) = sin(𝑡) 𝑤ℎ𝑒𝑟𝑒 𝑡 = −2𝜋 𝑡𝑜 2𝜋
7. 𝑥7 = ℎ1 (𝑡)ℎ2 (𝑡) 𝑤ℎ𝑒𝑟𝑒 ℎ1 (𝑡) = 4, 0 ≤ 𝑡 ≤ 4 𝑎𝑛𝑑 ℎ2 (𝑡) = sin(2𝑡) , 0 ≤ 𝑡 ≤ 4
1
8. 𝑥8 = 𝑎ℎ1 (𝑡) + 𝑏ℎ2 (𝑡) 𝑤ℎ𝑒𝑟𝑒 𝑎 = 5, 𝑏 = 10, ℎ1 (𝑡) = (𝜋) 𝑡, 0 ≤ 𝑡 ≤ 4 𝑎𝑛𝑑 ℎ2 (𝑡) =
2𝑒 −2𝑡 , 0 ≤ 𝑡 ≤ 4

9.6 Post-Lab Tasks


9.6.1 Task 1
Compute the Fourier transforms of the following time-domain signals:

a) 𝑥1 (𝑡) = 𝛿(𝑡)
b) 𝑥2 (𝑡) = cos 𝑡
c) 𝑥3 (𝑡) = 𝑒 −3𝑡 𝑢(𝑡)
You should submit a *.m file that displays each result.

9.6.2 Task 2
Compute the inverse Fourier transform of the following frequency-domain representations:

a) 𝑋1 (𝑗𝛺) = 2𝜋𝛿(𝛺)
b) 𝑋2 (𝑗𝛺) = 𝑢(𝛺 + 12) − 𝑢(𝛺 − 12)
You should submit a *.m file that displays each result.

9.6.3 Task 3
For the signal 𝑥(𝑡) = 𝑢(𝑡) − 𝑢(𝑡 − 1),

a) Compute the Fourier transform of 𝑥(−𝑡). Verify that the property 𝑥(−𝑡) → 𝑋(−𝑗𝛺) holds.
b) Compute the Fourier transform of 𝑥(𝑡 − 1). Verify that the property 𝑥(𝑡 − 𝑡0 )

→ 𝑋(𝑗𝛺)𝑒 −𝑗𝛺𝑡0 holds.
You should submit a *.m file that displays each result.

Department of Electrical and Computer Engineering 41


Lab Manual EEE223 Signals and Systems
Experiment No.10 THE DISCRETE-TIME FOURIER
TRANSFORM
10.1 Objective
To enable the students to compute discrete time Fourier transform

10.2 Pre-Lab
Basics of discrete time Fourier transform
10.2.1 The Discrete-Time Fourier Transform
If a discrete-time signal 𝑥(𝑛) satisfies the property that

∑ |𝑥(𝑛)| ∈ ℝ+
0
𝑛=−∞

then, its Fourier transform is given by the expression



𝑗𝜔
ℱ{𝑥(𝑛)} = 𝑋(𝑒 ) = ∑ 𝑥(𝑛)𝑒 −𝑗𝜔𝑛
𝑛=−∞

which is known as the frequency domain representation of the signal 𝑥(𝑛). To represent this, we

write 𝑥(𝑛) → 𝑋(𝑒 𝑗𝜔 ). The DTFT of a signal is always 2𝜋-periodic.

10.2.2 MATLAB Implementation of the Fourier Transform


We can compute the discrete-time Fourier transform using the ztrans command.

>> syms n omega


>> sympref('HeavisideAtOrigin', 1);
>> x = @(n) heaviside(n) - heaviside(n - 6);
>>simplify(ztrans(x(n), n, exp(j * omega)))
ans =
1 + 1/(exp(omega*1i) - 1) - exp(-omega*5i)/(exp(omega*1i) - 1)
>> X = @(omega) 1 + 1./(exp(omega*1i) - 1) - exp(-
omega*5i)./(exp(omega*1i) - 1);
>> omegar = -pi:0.01:pi;
>> figure; plot(omegar, abs(X(omegar)));
6

0
-4 -3 -2 -1 0 1 2 3 4

Department of Electrical and Computer Engineering 42


Lab Manual EEE223 Signals and Systems
>> figure; plot(omegar, angle(X(omegar)));
3

-1

-2

-3
-4 -3 -2 -1 0 1 2 3 4

10.3 In-Lab Tasks


Compute the discrete-time Fourier transform for:
1. Compute the DTFT 𝑋(𝜔)of a signal 𝑥(𝑛) = 0.8𝑛 , 0 ≤ 𝑛 ≤ 20 and plot 𝑋(𝜔) over the
frequency interval −𝜋 ≤ 𝜔 ≤ 𝜋 and −5𝜋 ≤ 𝜔 ≤ 5𝜋.
1
2. Verify Parseval’s theorem for the DTFT pair𝑎𝑛 𝑢(𝑛) ↔ (1−𝑎𝑒 𝑗𝜔 ) , |𝑎| < 1.
3. Compute and plot the DTFT of the signal x[n] = 0.6nu[n].

10.4 Post-Lab Tasks


10.4.1 Task 1
Compute the Fourier transforms of the following time-domain signals:

a) 𝑥1 (𝑛) = 𝛿(𝑛)
b) 𝑥2 (𝑛) = 2−𝑛 𝑢(𝑛)
𝜋𝑛
c) 𝑥3 (𝑛) = 3−𝑛 cos 5 𝑢(𝑛)

You should submit a *.m file that displays each result.

10.4.2 Task 2
For the signal 𝑥(𝑛) = 𝑢(𝑛) − 𝑢(𝑛 − 6),

a) Compute the Fourier transform of 𝑥(𝑛)𝑒 𝑗2𝑛 . Verify that the property 𝑥(𝑛)𝑒 𝑗𝜔0 𝑛

→ 𝑋(𝑒 𝑗(𝜔−𝜔0 ) ) holds.
b) Compute the Fourier transform of 𝑥(𝑛 − 1). Verify that the property 𝑥(𝑛 − 𝑛0 )

→ 𝑋(𝑒 𝑗𝜔 )𝑒 −𝑗𝜔𝑛0 holds.
You should submit a *.m file that displays each result.

Department of Electrical and Computer Engineering 43


Lab Manual EEE223 Signals and Systems
Experiment No.11 THE INVERSE DISCRETE-TIME FOURIER
TRANSFORM
11.1 Objective
Objective of this lab is to enable students compute inverse of DT Fourier transform.

11.2 Pre-Lab
The discussions about the inverse discrete time Fourier transform

11.2.1 The Inverse Discrete-Time Fourier Transform

If a frequency-domain signal 𝑋(𝑒 𝑗𝜔 ) is the DTFT of a continuous-time signal 𝑥(𝑛), we can


recover the original signal by using the formula
1 𝜋
𝑥(𝑛) = ∫ 𝑋(𝑒 𝑗𝜔 )𝑒 𝑗𝜔𝑛 𝑑𝜔.
2𝜋 −𝜋
ℱ −1
To represent this, we write 𝑋(𝑒 𝑗𝜔 ) → 𝑥(𝑛).

11.2.2 MATLAB Implementation of the Inverse DT Fourier Transform

We can compute the inverse discrete-time Fourier transform (IDTFT) using the int command and
using the formula.
>> syms n omega
>>X = @(omega) heaviside(omega + pi/2) - heaviside(omega - pi/2);
>> simplify(sym('1/(2*pi)') * int(X(omega) .* exp(j * omega * n),
omega, -pi, pi))
ans =
sin((pi*n)/2)/(n*pi)
>>x = @(n) sin((pi*n)/2)./(n*pi);
>> nr = -10:10;
>> figure; stem(nr, x(nr))
0.35

0.3

0.25

0.2

0.15

0.1

0.05

-0.05

-0.1

-0.15
-10 -8 -6 -4 -2 0 2 4 6 8 10

11.3 In-Lab Tasks


Compute the inverse Fourier transforms of the following signals:

Department of Electrical and Computer Engineering 44


Lab Manual EEE223 Signals and Systems
−2𝑗, −𝜋 ≤ 𝜔 ≤ 0
1. 𝑋1 (𝑒 𝑗𝜔 ) = {
2𝑗, 0 < 𝜔 ≤ 𝜋
𝑗𝜔
2. 𝑋2 (𝑒 ) = 𝑗 sin(𝜔) cos(5𝜔)
3. 𝑋3 (𝑒 𝑗𝜔 ) = 1 + 3𝑒 −𝑗𝜔 + 2𝑒 −𝑗2𝜔 − 4𝑒 −𝑗3𝜔 + 𝑒 −𝑗10𝜔
𝜔
4. 𝑋4 (𝑒 𝑗𝜔 ) = 𝑒 −𝑗 2 , −𝜋 ≤ 𝜔 ≤ 𝜋

11.4 Post-Lab Tasks


11.4.1 Task 1
Compute the inverse Fourier transforms of the following signals:

a) 𝑋1 (𝑒 𝑗𝜔 ) = 2𝜋𝛿(𝜔) , − 𝜋 ≤ 𝜔 ≤ 𝜋
1
b) 𝑋2 (𝑒 𝑗𝜔 ) = 1−2𝑒 −𝑗𝜔
You should submit a *.m file that displays each result.

11.4.2 Task 2
For the signal 𝑋(𝑒 𝑗𝜔 ) = 𝑢(𝜔 + 𝜋2) − 𝑢(𝜔 − 𝜋2), defined for −𝜋 ≤ 𝜔 ≤ 𝜋 and periodic otherwise,

a. Compute the inverse Fourier transform of 𝑋(𝑒 𝑗𝜔 )𝑒 −𝑗2𝜔 . Verify that the property
ℱ −1
𝑋(𝑒 𝑗𝜔 )𝑒 𝑗𝜔𝑛0 → 𝑥(𝑛 − 𝑛0 ) holds.
b. Compute the inverse Fourier transform of 𝑋(𝑒 𝑗(𝜔−1) ). Verify that the property
ℱ −1
𝑋(𝑒 𝑗(𝜔−𝜔0 ) ) → 𝑥(𝑛)𝑒 −𝑗𝜔0 𝑛 holds.
You should submit a *.m file that displays each result.

Department of Electrical and Computer Engineering 45


Lab Manual EEE223 Signals and Systems
Experiment No.12 ANALYSIS OF SYSTEM USING LAPLACE
TRANSFORM
12.1 Objective
Enable students to analyse signals and systems using Laplace transform.

12.2 Pre-Lab
The basic concepts of Laplace transform.
12.2.1 The Definition of the Laplace Transform
The bilateral Laplace Transform 𝑋(𝑠) of a continuous-time signal 𝑥(𝑡) is defined as

𝑋(𝑠) = ∫ 𝑥(𝑡)𝑒 −𝑠𝑡 𝑑𝑡.
−∞


We write 𝑥(𝑡) → 𝑋(𝑠) or 𝑋(𝑠) = ℒ{𝑥(𝑡)} to represent this. The complex frequency 𝑠 has two
parts: 𝑠 = 𝜎 + 𝑗𝛺. Re{𝑠} = 𝜎 is the decay factor and Im{𝑠} = 𝛺 is the oscillatory factor. If there
is no decay factor (𝜎 = 0), the Laplace transform simplifies to the continuous-time Fourier
transform.
12.2.2 The Laplace Transform in MATLAB
In MATLAB, the Laplace transform is implemented using the command laplace.

>> clearvars
>> syms s t
>> x = @(t) cos(t) .* exp(-3*t) .* heaviside(t);
>> laplace(x(t), t, s)
ans =
(s + 3)/((s + 3)^2 + 1)
>> X = @(s) (s + 3)./((s + 3).^2 + 1);
>> pretty(X(s))
s + 3
------------
2
(s + 3) + 1
12.3 In-Lab Tasks
Compute the Laplace Transform for:

1. 𝑥1 (𝑡) = 1, 0 ≤ 𝑡 ≤ 5
2. 𝑥2 (𝑡) = 2𝑒 −2𝑡 , 0 ≤ 𝑡 ≤ 5
3. 𝑥3 (𝑡) = 𝑢(𝑡) − 𝑢(𝑡 − 5)
4. 𝑥4 (𝑡) = 𝑒 −𝑡 𝑢(𝑡)
5. 𝑥5 (𝑡) = cos(𝑡) 𝑤ℎ𝑒𝑟𝑒 𝑡 = −2𝜋 𝑡𝑜 2𝜋
6. 𝑥6 (𝑡) = sin(𝑡) 𝑤ℎ𝑒𝑟𝑒 𝑡 = −2𝜋 𝑡𝑜 2𝜋
7. 𝑥7 = ℎ1 (𝑡)ℎ2 (𝑡) 𝑤ℎ𝑒𝑟𝑒 ℎ1 (𝑡) = 4, 0 ≤ 𝑡 ≤ 4 𝑎𝑛𝑑 ℎ2 (𝑡) = sin(2𝑡) , 0 ≤ 𝑡 ≤ 4
1
8. 𝑥8 = 𝑎ℎ1 (𝑡) + 𝑏ℎ2 (𝑡) 𝑤ℎ𝑒𝑟𝑒 𝑎 = 5, 𝑏 = 10, ℎ1 (𝑡) = (𝜋) 𝑡, 0 ≤ 𝑡 ≤ 4 𝑎𝑛𝑑 ℎ2 (𝑡) =
2𝑒 −2𝑡 , 0 ≤ 𝑡 ≤ 4

Department of Electrical and Computer Engineering 46


Lab Manual EEE223 Signals and Systems
12.4 Post-Lab Tasks
12.4.1 Task 1
Compute the Laplace Transform of the following signals.

a. 𝑥1 (𝑡) = 𝛿(𝑡)
b. 𝑥2 (𝑡) = 𝑒 𝑗2𝜋𝑡 𝑢(𝑡)
c. 𝑥3 (𝑡) = 𝑒 3𝑡 cos(2𝑡) 𝑢(𝑡)
You should submit an m-file that prints each Laplace transform using the pretty function.

Hint: You can pass the output of the laplace function directly to the pretty function.

12.4.2 Task 2
For the signal 𝑥(𝑡) = 𝑒 −𝑡 𝑢(𝑡), compute the Laplace transform of the following signals
a. 𝑥(𝑡 − 3)
b. 𝑒 3𝑡 𝑥(𝑡)
c. 𝑒 𝑗3𝑡 𝑥(𝑡)
You should submit an m-file that prints each Laplace transform using the pretty function.

Department of Electrical and Computer Engineering 47


Lab Manual EEE223 Signals and Systems
Experiment No.13 ANALYSIS OF SYSTEM USING INVERSE
LAPLACE TRANSFORM
13.1 Objective
Enable students to analyse signals and systems using inverse Laplace transform.

13.2 Pre-Lab
The basic concepts of Inverse Laplace transform.
13.2.1 The Definition of the Inverse Laplace Transform
The inverse Laplace Transform 𝑥(𝑡) of a complex signal 𝑋(𝑠) is defined as

1 𝜎+𝑗∞
𝑥(𝑡) = ∫ 𝑋(𝑠)𝑒 𝑠𝑡 𝑑𝑠
𝑗2𝜋 𝜎−𝑗∞

where the value 𝜎 can be any real value within the region of convergence of 𝑋(𝑠). We write 𝑋(𝑠)
ℒ −1
→ 𝑥(𝑡) or 𝑥(𝑡) = ℒ −1 {𝑋(𝑠)} to represent this. Usually, this integration is complex and difficult
to perform, so we use tables of Laplace transform pairs to perform the inverse transformation.
13.2.2 The Inverse Laplace Transform in MATLAB
In MATLAB, the inverse Laplace transform is implemented using the command ilaplace.

>> syms s t
>> X = @(s) 3./(s .* (s + 3));
>> ilaplace(X(s), s, t)
ans =
1 - exp(-3*t)
>> pretty(ans)
1 - exp(-3 t)
13.3 In-Lab Tasks
Compute the inverse Laplace Transform for:
1
1. 𝑋1 (𝑠) = 𝑠2 +𝑏2
1
2. 𝑋2 (𝑠) = (𝑠+𝑎)2 +𝑏2
1
3. 𝑋3 (𝑠) = 𝑠𝑛
1
4. 𝑋4 (𝑠) = (𝑠−𝑎)𝑛
𝑒 −5𝑠 (𝑠+1)
5. 𝑋5 (𝑠) = (𝑠+1)2 +16
𝑒 −10𝑠
6. 𝑋6 (𝑠) = (𝑠−3)2
7. Prove for ℎ(𝑡) = 𝑒 −4𝑡
a) 𝑒 −𝑎𝑡 × ℎ(𝑡) = 𝐻(𝑠 + 𝑎)
𝑑
b) 𝑑𝑡 ℎ(𝑡) = 𝑠𝐻(𝑠)
∞ 1
c) ∫−∞ ℎ(𝑡) = 𝑠 𝐻(𝑠)

Department of Electrical and Computer Engineering 48


Lab Manual EEE223 Signals and Systems
13.4 Post-Lab Task
Compute the inverse Laplace transformation of the functions given below:
2
1. 𝑋1 (𝑠) = 𝑠2 +4
𝑠+2
2. 𝑋2 (𝑠) = (𝑠+2)2 +4
6
3. 𝑋3 (𝑠) = 𝑠4

Department of Electrical and Computer Engineering 49

You might also like