0% found this document useful (0 votes)
20 views24 pages

Signal & System: Laboratory Manual

This document provides instructions for experiment 3 on plotting various signals in MATLAB. The objective is to understand how to plot and subplot different signals. The theory section explains how to plot a function by creating x and y vectors of equal length containing the independent and dependent variable values, and then using the plot command. It describes how to plot multiple functions on the same figure, add grids, labels, titles, and how to use subplot to divide the figure into multiple subplots.

Uploaded by

itachi
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)
20 views24 pages

Signal & System: Laboratory Manual

This document provides instructions for experiment 3 on plotting various signals in MATLAB. The objective is to understand how to plot and subplot different signals. The theory section explains how to plot a function by creating x and y vectors of equal length containing the independent and dependent variable values, and then using the plot command. It describes how to plot multiple functions on the same figure, add grids, labels, titles, and how to use subplot to divide the figure into multiple subplots.

Uploaded by

itachi
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/ 24

SIGNAL & SYSTEM

Laboratory Manual

Premier university Chittagong


Department of Electrical & Electronics Engineering
Premier university Chittagong
Department of Electrical & Electronic Engineering

Course Code: EEE-202


Course Title: Signals & Systems Laboratory

Experiment Name of Experiment


no.

01. Familiarization with MATLAB and functions in MATLAB

02. Observation of Matrix operations in MATLAB

03. Plotting of various signals in MATLAB

04. Understanding the Basic Signals using MATLAB

05. Solving of differential equation in MATLAB

06. Solving of integral equation in MATLAB

07. Evaluation of convolution integral in MATLAB

08. Implementing Fourier transform in MATLAB

09. Implementing Laplace transform in MATLAB

10. Implementing Z-transform in MATLAB

Department of EEE, Premier University, Chittagong | Signal & System 1


Experiment No: 01

Name of the experiment: Familiarization with MATLAB and Functions in MATLAB

Objective: To familiarize the students with MATLAB

Software Requirement: MATLAB 2014

Theory:

Introduction to MATLAB
MATLAB is a high-level technical computing language equipped with a user-friendly interface. Its
name stems from the words MATrix and LABoratory as it is based on the use of matrices.
MATLAB is an extremely powerful tool useful for scientists and engineers from various disciplines.
For example, MATLAB can be used in a wide range of applications, such as telecommunications,
signal and image processing, control, mathematics, financial modelling, bioengineering, aeronautics,
and many more.
M-Files
In order to write many commands that are executed all together, the program must be written in a text
editor. In this editor, one can type all the needed commands to form a program, save the program, and
execute it any time he or she wants. The text files are called M-files due to their suffice * .m.

There are two categories of M-files: the Scripts and the Functions.

Scripts
Scripts are the M-files with MATLAB commands. Their name must have a .m suffix. Scripts are
suitable for solving the problems that require many commands. The advantage of the scripts
is that they are implemented very easily.
Functions
Function are also M-files, That is, are files with extension .m and must be saved in the current
Directory of MATLAB. The difference between functions and scripts is that a function accepts one
or more input arguments and returns one or more output arguments. To declare that an M-file is
a function the first line of the m file must contain the syntax definition. More specifically, the first
line of the M-file must be of the form function[y1,y2,y3,…yn]=name{x1,x2,x3… xm}.
The variable y1,y2,…yn are the outputs of the function while x1,x2,…xm are the input arguments.
In case there is only one output, the square brackets are not necessary. The “name” specifies the
name of the function. In order to execute a function, first the M-File is saved in Current Directory.

Useful Commands
Here we will learn and practice useful (when working with vectors and matrices) commands. As
already discussed, the command sumreturns the sum of the elements of a vector. The command
cumsum returns a vector whose elements are the cumulative sum of the previous elements, the
command prodis the product of the vector elements, while the command diffreturns a vector in
Department of EEE, Premier University, Chittagong | Signal & System 2
which each element is given by its subtraction with the previous element. The command max
and min return the largest and smallest elements of the vector, respectively, as well as their index.
The command sortsorts the vector elements in ascending (by default) or descending order. The
command mean computes the mean value, while the command medianreturns the median value.
All these commands are suitable also for matrices by slightly changing their syntax.

Lab Tasks:
1. Write a script file and execute.
2. Write a function file and execute

Discussion:

Experiment no: 02

Experiment name: Observation of Matrix operations in MATLAB


Department of EEE, Premier University, Chittagong | Signal & System 3
Objective: To perform matrix additions, subtractions and multiplications in MATLAB

Software Requirement: MATLAB 2014

Theory:

Matrices

The MATLAB environment uses the term matrix to indicate a variable containing real or complex
numbers arranged in a two-dimensional grid. An array is, more generally, a vector, matrix, or higher
dimensional grid of numbers. All arrays in MATLAB are rectangular, in the sense that the component
vectors along any dimension are all the same length.

Adding and Subtracting Matrices

Addition and subtraction of matrices is defined just as it is for arrays, element by element. Adding A to
B, and then subtracting A from the result recovers B:

A = pascal(3);

B = magic(3);

X=A+B

X=

9 2 7

4 7 10

5 12 8

Y=X-A

Y=

8 1 6

3 5 7

4 9 2

Vector Products and Transpose

A row vector and a column vector of the same length can be multiplied in either order. The result is
either a scalar, the inner product, or a matrix, the outer product:

u = [3; 1; 4];

v = [2 0 -1];
Department of EEE, Premier University, Chittagong | Signal & System 4
x = v*u

x=

X = u*v

X=

6 0 -3

2 0 -1

8 0 -4

Transposition turns a row vector into a column vector:

x = v'

x=

-1

If x and y are both real column vectors, the product x*y is not defined, but the two products

x'*y

and

y'*x

are the same scalar. This quantity is used so frequently, it has three different names: inner product,
scalar product, or dot product.

Multiplying Matrices

Department of EEE, Premier University, Chittagong | Signal & System 5


Multiplication of matrices is defined in a way that reflects composition of the underlying linear
transformations and allows compact representation of systems of simultaneous linear equations. The
matrix product C = AB is defined when the column dimension of A is equal to the row dimension of
B, or when one of them is a scalar.

MATLAB uses a single asterisk to denote matrix multiplication. The next two examples illustrate the
fact that matrix multiplication is not commutative; AB is usually not equal to BA:

X = A*B

X=

15 15 15

26 38 26

41 70 39

Y = B*A

Y=

15 28 47

15 34 60

15 28 43

A matrix can be multiplied on the right by a column vector and on the left by a row vector:

u = [3; 1; 4];

x = A*u

x=

17

30

v = [2 0 -1];

y = v*B

y=

12 -7 10

Department of EEE, Premier University, Chittagong | Signal & System 6


Identity Matrix

Generally accepted mathematical notation uses the capital letter I to denote identity matrices, matrices
of various sizes with ones on the main diagonal and zeros elsewhere. These matrices have the property
that AI = A and IA = A whenever the dimensions are compatible. The original version of MATLAB
could not use I for this purpose because it did not distinguish between uppercase and lowercase letters
and i already served as a subscript and as the complex unit. So an English language pun was
introduced. The function

eye(m,n)

returns an m-by-n rectangular identity matrix and eye(n) returns an n-by-n square identity matrix.

Lab Tasks:
1. Execute addition and subtraction of matrics
2. Execute multiplication of matrics

Discussion:

Department of EEE, Premier University, Chittagong | Signal & System 7


Experiment no.: 03

Experiment name: Plotting of various signals in MATLAB

Software Requirement: MATLAB 2014

Objective: To understand the process of plotting & sub plotting of different signals in
MATLAB

Software Requirement: MATLAB 2014

Theory:

Plotting Signals in MATLAB


MATLAB is a very reliable and power full tool for plotting. A graph is constructed as a set of points
in two or three dimensions. These points are typically connected with a solid line. Commonly a graph
of a function is required. However in MATLAB a plot is done using the vectors and matrices not
functions.
Suppose that we want to plot a function y(x), where is an independent variable. The procedure to
plot is as follows:

1. Vector x is created. Such as a ≤ x ≤ b , where a and ab are scalars.


2. The function y (x) will be plotted over the interval [a,b]
3. Create the vector y, which is of the same length as x. the two vectors have an equal
number of elements
4. The value of each element of is the value of y (x) calculated for each value of .
5. Finally, the function y(x) is plotted by typing ‘plot(x,y)’

Plotting several function in one figure

It is possible to plot more than one function in the name of figure by employing a different syntax
of command Plot.

Formatting a Figure
The command grid on adds lines to the graph, while the command grid off removes the grid lines.
Simply typing gridis switch between the two modes. Text besides the x-axis and y-axis can be
added using the commands xlabel and ylabel, respectively. A graph title is inserted by the
command title .

Plotting in Different Figures


The command subplot(m,n,p) or subplot(mnp) splits the figure window into m×n small
subfigures and makes the pth subfigure active.

Department of EEE, Premier University, Chittagong | Signal & System 8


Plotting the Discrete Time Functions
A discrete time function is a function of the form f [n], n € z, where z denotes the set of integers,
In this case the appropriate command for plotting is ‘stem (n,f)’

Lab Tasks:
1. Plot the following function y(x) = x^2 , -2 ≥ 0 ≥ 2
2. Plot the y(x) = x^2 cos(x), g(x) = xcos (x) and f(x) = 2^xsin (x), 0 ≤ x ≤ 2π in the same figure
3. Plot the discrete function f (n) = n^2, where -2 ≤ x ≤ 2

Discussion:

Department of EEE, Premier University, Chittagong | Signal & System 9


Experiment no: 04

Experiment name: Understanding the Basic Signals using MATLAB

Objective: To familiarize the students basic signals using MATLAB.

Software Requirement: MATLAB 2014

Theory:

Continuous Time Signals:


A signal is called continuous-time (or analog) signals if the independent (time) is defined in
continuous interval. For 1 - D signals, time domain of signal is continuous interval of the axis. In other
words, for continuous-time signals the independent variable is continuous. Moreover, the
dependent value that usually denotes the amplitude of the signal is also continuous variable. An
example of such a signal is speech as a function of time. An analog Signal is expressed by a function
x(t) , where takes real values.

Discrete Time Signals :


A signal is called a discrete-time signal if the independent variable (time) is defined in a discrete
interval (e.g., the set of integer number), while the dependent variable is defined in a continuous set
of values. In the following example, the discrete-time signal y [n ] = Cos[n] is plotted.

Digital Signals :
Digital signals are the signals that both independent and dependent variables take values from a
discrete set.
In the following example, the signal y [n] = cos[n] is again plotted but we use the command round
to limit the set values that y[n] can take , that is , y[n] can be -1, 0 or 1

Lab Tasks:
1. Form gate signal
2. Plot triangular Signal with amplitude 10 frequency 50 Hz and for 2 cycles
3. Plot Rectangular Signal with amplitude 10&15 frequency 50Hz, duty cycle 60% and 40% and
for
2 cycles.
4. Plot Sinusoidal Signal with amplitude 10, frequency 50hz and for 2 cycles.
5. Plot the unit step function
6. Plot the ramp function
7. Plot the impulse function

Discussion

Department of EEE, Premier University, Chittagong | Signal & System 10


Experiment no: 05

Experiment name: Solving of differential equation in MATLAB

Objective: To perform differential operation in MATLAB

Software Requirement: MATLAB 2014

Theory:

Symbolic Variables

In MATLAB, a variable type is the symbolic variable (or object). A symbolic variable is defined by
the command sym and syms. The use of symbolic variables allows the computation of limits,
integrals, derivatives etc.
diff
Differentiate symbolic expression or function
Syntax
diff(F)
diff(F,var)
diff (F,n)
diff(F,var,n)
diff(F,n,var)
diff(F,var1,...,varN)

Description
diff(F) - differentiates F with respect to the variable determined by symvar.
diff(F,var) - differentiates F with respect to the variable var.
diff(F,n) - computes the nth derivative of F with respect to the variable determined by symvar.
diff(F,var,n)- computes the nth derivative of F with respect to the variable var. This syntax is
equivalent to diff(F,n,var).
diff(F,var1,...,varN) - differentiates F with respect to the variables var1,...,varN.

Differentiation of a Univariate Function


Find the first derivative of this univariate function:
syms x
f(x) = sin(x^2);
df = diff(f)

Higher-Order Derivatives of a Multivariate Expression with Respect to the Default Variable


Compute the second derivative of the expression x*y. If you do not specify the differentiation variable,
diff uses the variable determined by symvar. For this expression, symvar(x*y, 1) returns x. Therefore,
diff computes the second derivative of x*y with respect to x.

Department of EEE, Premier University, Chittagong | Signal & System 11


syms x y
diff(x*y, 2)
If you use nested diff calls and do not specify the differentiation variable, diff determines the
differentiation variable for each call. For example, differentiate the expression x*y by calling the diff
function twice:

diff(diff(x*y))

In the first call, diff differentiate x*y with respect to x, and returns y. In the second call, diff differentiates
y with respect to y, and returns 1.

Thus, diff(x*y, 2) is equivalent to diff(x*y, x, x), and diff(diff(x*y)) is equivalent to diff(x*y, x, y).

Lab Tasks:
Find out first, second and third derivative of the following functions:
i. 𝑒 −𝑎𝑡
ii. 𝑒 −𝑎𝑡 sin ωt
iii. 𝑒 −𝑎𝑡 cos ωt
iv. cos ωt
v. sin ωt
vi. cos ωt sin ωt
vii. t^2

Discussion:

Department of EEE, Premier University, Chittagong | Signal & System 12


Experiment no: 06

Experiment name: Solving of integral equation in MATLAB

Objective: To perform integral operation in MATLAB

Software Requirement: MATLAB 2014

Theory:

Int
Definite and indefinite integrals

Syntax
int(expr,var)
int(expr,var,a,b)
int(___,Name,Value)
Description
int(expr,var) - computes the indefinite integral of expr with respect to the symbolic scalar variable
var. Specifying the variable var is optional. If you do not specify it, int uses the default variable
determined by symvar. If expr is a constant, then the default variable is x.
int(expr,var,a,b) - computes the definite integral of expr with respect to var from a to b. If you
do not specify it, int uses the default variable determined by symvar. If expr is a constant, then the
default variable is x.
int(expr,var,[a,b]), int(expr,var,[a b]), and int(expr,var,[a;b]) are equivalent to int(expr,var,a,b).
int(___,Name,Value) - uses additional options specified by one or more Name,Value pair
arguments.
Indefinite Integral of a Univariate Expression
Find an indefinite integral of this univariate expression:
syms x
int(-2*x/(1 + x^2)^2)

Department of EEE, Premier University, Chittagong | Signal & System 13


Definite Integrals of Univariate Expressions
Integrate this expression from 0 to 1:
syms x
int(x*log(1 + x), 0, 1)
Lab Tasks:
1. Integrate the following functions
i. 𝑒 −𝑎𝑡
ii. 𝑒 −𝑎𝑡 sin ωt
iii. 𝑒 −𝑎𝑡 cos ωt
iv. cos ωt
v. sin ωt
vi. cos ωt sin ωt
vii. t^2

2. Integrate the following functions with limit (0,pi)


viii. 𝑒 −𝑎𝑡
ix. 𝑒 −𝑎𝑡 sin ωt
x. 𝑒 −𝑎𝑡 cos ωt
xi. cos ωt
xii. sin ωt
xiii. cos ωt sin ωt
xiv. t^2

Discussion:

Department of EEE, Premier University, Chittagong | Signal & System 14


Department of EEE, Premier University, Chittagong | Signal & System 15
Experiment no: 07

Experiment name: Evaluation of convolution integral in MATLAB

Objective: To perform convolution of continuous time signals.

Software Requirement: MATLAB 2014

Theory:

Continuous-Time Convolution
The impulse response of a linear time-invariant system completely specifies the system. More specifically,
if the impulse response of a system is known one can compute the system output for any input signal. We
now present on of most important topics in signals and systems theory.

The response (or output) of a system to any input signal is computed by the convolution

of the input signal with the impulse response of the system.

Suppose that y(t) denotes the output of the system, x(t) is the input signal, and h(t) is the impulse response
of the system. The mathematical expression of the convolution relationship is

y(t) = x(t) * h (t)

Where, the symbol * denotes convolution, and it must not be confused with the multiplication symbol. The
calculation of the convolution between two signals involves the computation of an integral. The complete
form of is

y(t) = x(t) * h (t) =


∫−∞ 𝑥(𝜏) ℎ(𝑡 − 𝜏)𝑑𝜏
By alternation variables τ and t, becomes

y(t) = x(t) * h (t) =


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

The Command conv:

The computational process followed in the previous lab is the analytical way of deriving the convolution
between two signals. In MATLAB, the command ‘conv’ allows the direct computation of the
convolution between two signals.

Lab Task:
A linear time-invariant system is described by the impulse response
Department of EEE, Premier University, Chittagong | Signal & System 16
ℎ(𝑡) = { 1−𝑡
0
0≤𝑡≤1
𝑒𝑙𝑠𝑒𝑤ℎ𝑒𝑟𝑒

If the response is y(t), calculate the response of the system to the input signal using convolution integral

𝑥(𝑡) = { 10 0≤𝑡≤2
𝑒𝑙𝑠𝑒𝑤ℎ𝑒𝑟𝑒

Discussion:

Experiment no: 08

Experiment name: Implementing Fourier transform in MATLAB


Department of EEE, Premier University, Chittagong | Signal & System 17
Objective: To understand and implement the Fourier transform using MATLAB.

Software Requirement: MATLAB 2014

Theory:

Fourier transform

The Fourier transform of the expression f = f(x) with respect to the variable x at the point w is
defined as follows


𝐹(𝜔) = 𝑐 ∫−∞ 𝑓(𝑥)𝑒^𝑖𝑠𝑤𝑥 𝑑𝑥

Here, c and s are parameters of the Fourier transform. The fourier function uses c = 1, s = –1.

Syntax

fourier(f,trans_var,eval_point)

Description

fourier(f,trans_var,eval_point) - computes the Fourier transform of f with respect to the


transformation variable trans_var at the point eval_point.

Input Arguments

f- Symbolic expression, symbolic function, or vector or matrix of symbolic expressions or


functions.

trans_var -Symbolic variable representing the transformation variable. This variable is often
called the "time variable" or the "space variable".

Default: The variable x. If f does not contain x, then the default variable is determined by symvar.

eval_point- Symbolic variable, expression, vector or matrix representing the evaluation point.
This variable is often called the "frequency variable".

Default: The variable w. If w is the transformation variable of f, then the default evaluation point
is the variable v.

Examples

Compute the Fourier transform of this expression with respect to the variable x at the evaluation
point y:

Department of EEE, Premier University, Chittagong | Signal & System 18


syms x y

f = exp(-x^2);

fourier(f, x, y)

Lab Tasks:
1. Execute Fourier transform of complex exponential
2. Execute Fourier transform of rectangular gate
3. Execute Fourier transform of sinc function

Discussion:

Experiment no: 09

Experiment name: Implementing Laplace transform in MATLAB

Department of EEE, Premier University, Chittagong | Signal & System 19


Objective: To implement Laplace Transform using MATLAB.

Software Requirement: MATLAB 2014

Theory:

Laplace transform

The Laplace transform is defined as follows:



𝐹(𝑠) = 𝑐 ∫0 𝑓(𝑡)𝑒^ − 𝑠𝑡 𝑑𝑡

Syntax

laplace(f,trans_var,eval_point)

Description

laplace(f,trans_var,eval_point) - computes the Laplace transform of f with respect to the transformation


variable trans_var at the point eval_point.

Input Arguments

f- Symbolic expression, symbolic function, or vector or matrix of symbolic expressions or functions.

trans_var- Symbolic variable representing the transformation variable. This variable is often called the
"time variable".

Default: The variable t. If f does not contain t, then the default variable is determined by symvar.

eval_point- Symbolic variable or expression representing the evaluation point. This variable is often called
the "complex frequency variable".

Default: The variable s. If s is the transformation variable of f, then the default evaluation point is the
variable z.

Examples

Compute the Laplace transform of this expression with respect to the variable x at the evaluation point y:

syms x y

f = 1/sqrt(x);

laplace(f, x, y)

Lab Tasks:
Find out the laplace transform of the following functions:
i. 𝑒 −𝑎𝑡
ii. 𝑒 −𝑎𝑡 sin ωt

Department of EEE, Premier University, Chittagong | Signal & System 20


iii. cos ωt
iv. sinh bt
v. sin ωt
vi. cosh bt
vii. t^2
viii. U(t)

Discussion:

Department of EEE, Premier University, Chittagong | Signal & System 21


Experiment no: 10

Experiment name: Implementing Z-transform in MATLAB

Objective: To implement Z- Transform using MATLAB.

Software Requirement: MATLAB 2014

Theory:

Z-transform

The Z-transform of the expression f = f(n) is defined as follows:

𝐹(𝑧) = ∑∞
𝑛=0 𝑓(𝑛) ∗ 𝑧^ − 𝑛

Syntax

ztrans(f,trans_index,eval_point)

Description

ztrans(f,trans_index,eval_point) - computes the Z-transform of f with respect to the transformation


index trans_index at the point eval_point.

Input Arguments

f- Symbolic expression, symbolic function, or vector or matrix of symbolic expressions or functions.

trans_index- Symbolic variable representing the transformation index. This variable is often called the
"discrete time variable".

Default: The variable n. If f does not contain n, then the default variable is determined by symvar.

eval_point- Symbolic variable or expression representing the evaluation point. This variable is often
called the "complex frequency variable".

Default: The variable z. If z is the transformation index of f, then the default evaluation point is the
variable w.

Examples

Department of EEE, Premier University, Chittagong | Signal & System 22


Compute the Z-transform of this expression with respect to the transformation index k at the evaluation
point x:

syms k x

f = sin(k);

ztrans(f, k, x)

Lab Tasks:
Find the Z transformation of the following function:

i. 𝑒 𝑗𝜔𝑡
ii. sinh bt
iii. cosh bt
iv. sinωt
v. cosωt
vi. t
vii. t^2
viii. U(t)

Discussion:

Department of EEE, Premier University, Chittagong | Signal & System 23

You might also like