Download as pdf or txt
Download as pdf or txt
You are on page 1of 53

SIGNALS AND

SYSTEMS
Lab Manual

Prepared By: Asif Ullah Khan


Lab Manual of
Signal & System

Name: Asif Ullah Khan.

Reg No: NSR/20/ET/21.

Department: Electrical Engineering Technology.

Semester: 5th

Batch: 05

Instructor: Engr. Dawar Awan.

Lab Instructor: Engr. Saadia Tabassum.

Date: 28 - Feb - 2023


Author Declaration .

I hereby certify that I am the sole author of this lab manual and that no part of this lab
manual has been submitted. .
.

I certify that, to the best of my knowledge, my lab manual does not infringe upon
anyone’s copyright nor violate any proprietary rights and that any ideas, techniques,
quotations, or any other material from the work of the people included in my lab manual,
submitted or otherwise, are fully acknowledged in accordance with the standard
referencing practice. Furthermore, to the extent that I have included copyrighted material
from some books. I certify that I have obtained a written permission for copyright from
my Lab Instructor (Engr. Saadia Tabassum) to include such material in my lab manual.

I declare that this is a true copy of my lab manual, and accepted by my instructor
Engr. Saadia Tabassum. .
.
Acknowledgement

All praise to Al-Mighty Allah, the most merciful and beneficent, who enabled me to
explore the present studies and also to the Holy Prophet Muhammad (S.A.W.W), the
source of knowledge and torch of guidance for the entire world.
.

I would like to acknowledge and give my warmest thanks to my lab instructors


(Engr. Saadia Tabassum) who made this work possible. Her guidance and advice
carried me through all the stages of making my lab manual. I would also like to thanks
my friends for letting my defense be an enjoyable moment, and for your brilliant
comments and suggestions, thanks to you. You are the one who let me finish my lab
manual. . .

I would also like to give special thanks to my beloved friend (Engr. Muhammad Ali)
and my family as a whole for their continuous support and understanding when
undertaking my research and created my lab manual. Your prayer for me was what
sustained me this far. .
.

Dedication

All my effort is dedicated to our beloved parents and teachers who have been a
constant support and source of encouragement for me throughout my life. May Allah
bless them with long lives and always provide us their loving and throughout guidance
(Ameen).
List of Experiments
Sr.No Experiments

01 INTRODUCTION TO MATLAB

02 BASIC OPERATIONS ON MATRICES

03 GENERATION OF VARIOUS SIGNALS AND THEIR PLOTTING IN MATLAB)


GENERATION OF VARIOUS SIGNALS AND SEQUENCES
04 (UNIT IMPULSE, UNIT STEP, SQUARE, SAWTOOTH, TRIANGULAR, SINUSOIDAL, RAMP,
SINC.)

05 OPERATION ON VARIOUS SIGNALS AND SEQUENCES

a) PROPERTIES of SYSTEMS
06 b) Even and Odd Signals

07 CONVOLUTION BETWEEN SIGNALS AND SEQUENCES

08 USE OF CONDITIONAL STATEMENTS AND FOR LOOP IN MATLAB

09 FOURIER SERIES AND FOURIER TRANSFORM

10 LAPLACE AND Z-TRANSFORM


LAB NO: 01 (INTRODUCTION TO MATLAB)

AIM/OBJECTIVE:
 In this lab we will briefly know about MATLAB software.
 Simple Addition, Multiplication or Arithmetic operations in MATLAB.
 Generate (3×3, 4×4) matrices. And also multiply those matrices.

EQUIPMENTS:
 MATLAB software.

INTRODUCTION:

What is MATLAB?
Answer: A high-performance language for technical computing. Typical uses of
MATLAB:

• Mathematical computations.

• Algorithmic development.

• Model prototyping (prior to complex model development).

• Data analysis and exploration of data (visualization).

• Scientific and engineering graphics for presentation.

• Complex analysis using MATLAB toolboxes (i.e., statistics neural networks, fuzzy
logic, H-infinity control, economics, etc.).

In this lab we know about the basics of MATLAB, his environment, simple command and
windows like Command window. Also know the “m” file, work space and many other
things. We learn the basic arithmetic operations like (Addition, Multiplication),
generating of matrices in MATLAB, also the addition of matrices.

LAB TASK:

Code:
clear all
close all
clc
%Generate 4*4 Matric
M= [1, 3,-1, 6; 2, 4, 0,-1; 0,-2, 3,-1; -1, 2,-5, 1]
%Generate 4*4 Matric
N= [-1 -3 3; 2 -1 6; 1 4 -1; 2 -1 2]
%M*N
M*N
%N*M
N*M
%Gerenate
A= [2 4 -1; -2 1 9; -1 -1 0]
%Gerenate
B= [0 -1 -1; 1 0 2; -1 -2 0]
%Gerenate
V= [3; 1; -1]
%Gerenate
A*V
%Gerenate
A*B
%Gerenate
B*A

Result:

M=

1 3 -1 6
2 4 0 -1
0 -2 3 -1
-1 2 -5 1

N=

-1 -3 3
2 -1 6
1 4 -1
2 -1 2

ans =

16 -16 34
4 -9 28
-3 15 -17
2 -20 16

A=

2 4 -1
-2 1 9
-1 -1 0

B=

0 -1 -1
1 0 2
-1 -2 0

V=

3
1
-1

ans =

11
-14
-4

ans =
5 0 6
-8 -16 4
-1 1 -1

ans =

3 0 -9
0 2 -1
2 -6 -17

Note:
%N*M
(N*M)
Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first
matrix matches the number of rows in the second matrix. To perform elementwise
multiplication, use '.*'.

CONCLUSION:
To seek a basics operation of MATLAB. Generated on the base of rows and column. Seek
the “m” file, work space and many other things. We learn the basic arithmetic operations
like (Addition, Multiplication), generated of matrices in MATLAB.
LAB NO: 02 (BASIC OPERATIONS ON MATRICES)

AIM/OBJECTIVE:
 To generate matrix and perform basic operation on matrices Using MATLAB Software.
 Matrix Generation.
 Entering a Vector.
 Entering a Matrix.
 Matrix Indexing.
 Colon Operator.
 Linear Spacing.
 Etc...

EQUIPMENTS:
 PC.
 MATLAB software.

INTRODUCTION:

Matrices are the basic elements of the MATLAB environment. A matrix is a two-
dimensional array consisting of m rows and n columns. Special cases are column vectors (n
= 1) and row vectors (m = 1).
In this section we will illustrate how to apply different operations on matrices.
MATLAB supports two types of operations, known as matrix operations and array
operations.

LAB TASK:

Code:
clear all
close all
clc
A=[2 2 2 2;3 3 3 3;4 4 4 4;5 5 5 5]
B=21*A
B(4,:)=[]
B(:,4)=[]
C=B.^2
C(:,3)=[0]
C'
eye(3,3)
D=[C' eye(3,3)]

Results:
A=

2 2 2 2
3 3 3 3
4 4 4 4
5 5 5 5

B=
42 42 42 42
63 63 63 63
84 84 84 84
105 105 105 105

B=

42 42 42 42
63 63 63 63
84 84 84 84

B=

42 42 42
63 63 63
84 84 84

C=

1764 1764 1764


3969 3969 3969
7056 7056 7056

C=

1764 1764 0
3969 3969 0
7056 7056 0

ans =

1764 3969 7056


1764 3969 7056
0 0 0

ans =

1 0 0
0 1 0
0 0 1

D=

1764 3969 7056 1 0 0


1764 3969 7056 0 1 0
0 0 0 0 0 1

CONCLUSION:
From this lab, I seek 4×4 matrix and applied such basics commands like, (eye command,
concatenated, Transpose, deleting row & column) in MATLAB.
LAB NO: 03 (GENERATION OF VARIOUS SIGNALS AND THEIR
c PLOTTING IN MATLAB)

AIM/OBJECTIVE:
 Plotting is one of the most useful applications of a math package to plot experimental or generated data.
 Creating Simple Plots.
 Basic 2D Plotting.
 Adding Axis Command.
 Multiple Plots.
 Adding legend & Colors.
 Etc...

EQUIPMENTS:
 PC.
 MATLAB software.

INTRODUCTION:

In this lab we will learn about the different signal and their graph for example Ramp signal,
Unit signal, and unit impulse signal. We will study how to generate the signal on MATLAB.
Plotting signals in MATLAB Plotting signals is a basic skill in MATLAB that will be used
frequently in analyzing signals and systems. Plots in MATLAB are generated using the plot
function. The function plot (x, y) generates a 2-D plot where the values of the vector x
indicate points along the horizontal axis.

LAB TASK:

Code:
clear all
close all
clc
%sine Function
x=[0:pi/100:2*pi];
y1=21*sin(x)
subplot(4,4,1)
plot(x,y1)
xlabel('x')
ylabel('y1')
title('sine Function')
grid on
%Cosine Function
y2=pi/30*cos(x)
subplot(4,4,2)
plot(x,y2)
xlabel('x')
ylabel('y2')
title('Cosine Function')
grid on
%Exponentional +(X)
y3=21.*exp(-1.5*x).*sin(10*x)
subplot(4,4,3)
plot(x,y3)
xlabel('x')
ylabel('y3')
title('Cont Exp Function Decreasing')
grid on
%Exponentional -(x)
y4=21.*exp(1.5*x).*sin(10*x)
subplot(4,4,4)
plot(x,y4)
xlabel('x')
ylabel('y4')
title('Cont Exp Function Increasing')
grid on
%Addition of the above function
A=y1+y2
subplot(4,4,5)
plot(A)
xlabel('x')
ylabel('yA')
title('Adding of Y1&Y2')
grid on
B=y1+y3
subplot(4,4,6)
plot(B)
xlabel('x')
ylabel('yB')
title('Adding of Y1&Y3')
grid on
C=y1+y4
subplot(4,4,7)
plot(C)
xlabel('x')
ylabel('yC')
title('Adding of Y1&Y4')
grid on
D=y2+y3
subplot(4,4,8)
plot(D)
xlabel('x')
ylabel('yD')
title('Adding of Y2&Y3')
grid on
%Stem Continous Function
y1=21*sin(x)
subplot(4,4,9)
plot(x,y1)
xlabel('x')
ylabel('y1')
stem(y1)
title('Discrete Function of sine')
grid on
y2=21*sin(x)
subplot(4,4,10)
plot(x,y2)
xlabel('x')
ylabel('y2')
stem(y2)
title('Discrete Function of cosine')
grid on
y3=21.*exp(-1.5*x).*sin(10*x)
subplot(4,4,11)
plot(x,y3)
xlabel('x')
ylabel('y3')
stem(y3)
title('Dis Exp Function Decreasing')
grid on
y4=21.*exp(1.5*x).*sin(10*x)
subplot(4,4,12)
plot(x,y4)
xlabel('x')
ylabel('y4')
stem(y4)
title('Disc Exp Function Increasing')
grid on
%Stem of Addition
A=y1+y2
subplot(4,4,13)
plot(A)
xlabel('x')
ylabel('yA')
stem(A)
title('Disc of Y1&Y2 Adding')
grid on
B=y1+y3
subplot(4,4,14)
plot(B)
xlabel('x')
ylabel('yB')
stem(B)
title('Disc of Y1&Y3 Adding')
grid on
C=y1+y4
subplot(4,4,15)
plot(C)
xlabel('x')
ylabel('yC')
stem(C)
title('Disc of Y1&Y4 Adding')
grid on
D=y2+y3
subplot(4,4,16)
plot(D)
xlabel('x')
ylabel('yD')
stem(D)
title('Disc of Y2&Y3 Adding')
grid on
%Plot Multiple graph
t=linspace(0,20*pi,100)
y=sin(2*pi*t).*sin(2*pi*(20*t))
z=cos(2*pi*t).*cos(2*pi*(20*t+pi/4))
plot(t,y,'-.',t,z,'--')
xlabel('sin(2*pi*t),cos(2*pi*t)')
ylabel('sin(2*pi*(20*t),cos(2*pi*(20*t+pi/4)')
title('Multiplication Of y&z Fuction')
legend('t,y','t,z')
grid on
Results:

CONCLUSION:
At the end of this lab, I seek the generation of signal and their plotting e.g. (sine function,
cosine function, and also how to discrete them etc.) in MATLAB.
LAB NO: 04 GENERATION OF VARIOUS SIGNALS AND SEQUENCES
c (UNIT IMPULSE, UNIT STEP, SQUARE,SAWTOOTH, TRIANGULAR, SINUSOIDAL, RAMP,

SINC.)

AIM/OBJECTIVE:
To generate different types of signals Using MATLAB Software.
 Unit impulse function.
 Ramp signal.
 Parabolic signal.
 Signum function.
 Unit step function.
 Square wave.
 Saw tooth wave.
 Sinc function.

EQUIPMENTS:
 PC.
 MATLAB software.

INTRODUCTION:

In this lab we will learn about the generation of different signal and sequences for example
Unit impulse function, Ramp signal, Parabolic signal, Signum function, Unit step function,
Square wave, Saw-tooth wave and Sinc function. Also learn about the user friendly input.

LAB TASK:
1. x(t)= u(-t+1)
2. x(t)=3r(t-1)
3. x(t)=U(n+2)-(n-3)
4. x(n)=x1(n)+x2(n)
where x1(n)={1,3,2,1},x2(n)={1,-2,3,2}
5. x(t)=r(t)-2r(t-1)+r(t-2)
6. x(n)=2δ(n+2)-2δ(n-4), -5≤ n ≥5.
7. Given X(n)={1,2,3,4,5,6,7,6,5,4,2,1}

Determine and plot the following sequence

a- x1(n)=2x(n-5-3x(n+4))
b. x2(n)=x(3-n)+x(n)x(n-2)

Code 1.

clear all;
close all;
clc;
Result:

Code 2.
clear all
close all
clc
%Unit Impulse Function Using(Zeros & Ones)
t=-21:1:21;
y=[zeros(1,21), ones(1,1), zeros(1,21)];
subplot(1,3,1);
plot(t,y);
title('unit impulse');
xlabel('time');
ylabel('unit impulse');
grid on;
%Unit Step Function Using(Zeros & Ones)
t= -21:1:21;
unitstep=[t>=0];
subplot(1,3,2);
plot(t,unitstep); xlabel('t');ylabel('amplitude');
title('continuous unit step');
grid on;
%Unit Ramp Function Using(Zeros & Ones)
t= -21:1:21;
x=[2*t];
subplot(1,3,3);
plot(x,t);
xlabel('t');
ylabel('amplitude');
title('ramp function'); grid on;
Result:

Code 3.
clear all
close all
clc
a=input('Enter a value');
a2=input('Enter a2 value');
a1=input('Enter a1 value');
t=a:a1:a2;
y=sign(t);
plot(t,y);
a3=input('Enter a3 value');
a4=input('Enter a4 value');
ylim([a3 a4]);
xlabel('t');
ylabel('y');
title('Continous signum Pariodic wave');
grid on
Results:

CONCLUSION:
From this lab, I seek the generation of signal and their sequences e.g. (unit impulse function,
ramp signal, Signum function etc. and also learnt about user defined command.) in MATLAB.
LAB NO: 05 (OPERATION ON VARIOUS SIGNALS AND SEQUENCES)

AIM/OBJECTIVE:
The objective is to perform the following various operations on different signals using MATLAB software;
 Time Reversal.
 Time Shift.
 Amplitude Scaling.
 Compression.

EQUIPMENTS:
 PC
 MATLAB software.

INTRODUCTION:
Basic Operation on Signals:
Time shifting:

y(t)=x(t-T)

The effect that a time shift has on the appearance of a signal If T is a positive number,
the time shifted signal, x (t -T ) gets shifted to the left, otherwise it gets shifted right.

Time reversal:
y(t)=y(-t) Time reversal flips the signal about t = 0
Signal Addition:
Addition: any two signals can be added to form a third signal,
z (t) = x(t) + y (t)
Multiplication: of two signals, their product is also a signal.
z (t) = x(t) * y (t)

LAB TASK:

1. x(t)= u(-t+1)
2. x(t)=3r(t-1)
3. x(t)=U(n+2-u(n-3)
4. x(n)=x1(n)+x2(n)
where x1(n)={1,3,2,1},x2(n)={1,-2,3,2}
5. x(t)=r(t)-2r(t-1)+r(t-2)
6. x(n)=2δ(n+2)-2δ(n-4), -5≤ n ≥5.
7.Given X(n)={1,2,3,4,5,6,7,6,5,4,2,1}
Determine and plot the following sequence
a- x1(n)=2x(n-5)-3x(n+4)
b. x2(n)=x(3-n)+x(n)x(n-2)

MATLAB CODE:
Question (1,2 and 3) Code;
clear all
close all
clc
% Question No 01
t=[-10:.005:10;];
unitstep=[-t+1>=0];
subplot(3,2,1);
plot(t,unitstep);
xlabel('time');
ylabel('amplitude');
title('(Q1) x(t)= u(-t+1))');
grid on

% Question No 02
t1=[0:0.01:5];
a=3;
t0=1;
r=a*(t1-t0).*((t1-t0)>=0);
subplot(3,2,2);
plot(t1,r);
xlabel('time');
ylabel('amplitude');
title('(Q2) x(t)=3r(t-1)');
grid on

% Question No 03
n=[-4:.025:4];
u=[n>=0];
subplot(3,2,3);
stem(n,u);
xlabel('time');
ylabel('amplitude');
title('(Q3) Orignal Signal');
grid on
x=(n+2);
subplot(3,2,4);
stem(n,x);
xlabel('time');
ylabel('amplitude');
title('(Q3)=(n+2)');
grid on
x1=(n-3);
subplot(3,2,5);
stem(n,x1);
xlabel('time');
ylabel('amplitude');
title('(Q3)=(n-3)');
grid on
x2=x-x1;
subplot(3,2,6);
stem(n,x2);
xlabel('time');
ylabel('amplitude');
title('(Q3) x(n)=u(n+2)-(n-3)');
grid on
Result of (Q=1,2,3):

Fig. 01

Question (4 and 5) code;


clear all
close all
clc
% Question No 04
x1=[1,3,2,1];
x2=[1,-2,3,2];
subplot(2,3,1);
stem(x1);
xlabel('time');
ylabel('amplitude');
title('(Q4)=x1(n)');
grid on
% x2=[1,-2,3,2];
subplot(2,3,2);
stem(x2);
xlabel('time');
ylabel('amplitude');
title('(Q4)=x2(n)');
grid on
x3=x1+x2;
subplot(2,3,3);
stem(x3);
xlabel('time');
ylabel('amplitude');
title('(Q4)=x1(n)+x2(n)');
grid on

% Question No 05
t=-7:0.001:7;
a=2;
t0=1;
r=a*(t-t0).*((t-t0)>=0);
subplot(2,3,4);
plot(t,r);
xlabel('time');
ylabel('amplitude');
title('(Q5)');
grid on
a1=1;
t1=2;
r1=a1*(t-t1).*((t-t1)>=0);
subplot(2,3,5);
plot(t,r1);
xlabel('time');
ylabel('amplitude');
title('(Q5)');
grid on
z=t-r+r1;
subplot(2,3,6);
plot(t,z);
xlabel('time');
ylabel('amplitude');
title('(Q5) x(t)=r(t)-2r(t-1)+r(t-2)');
grid on

Result of (Q= 4 and 5):

Fig. 02

Question (6 and 7) code;


clear all
close all
clc
% Question N0 06
n=[-5:5];
y=[zeros(1,5), ones(1,1),zeros(1,5)];
subplot(3,3,1);
stem(n,y);
xlabel('time');
ylabel('amplitude');
title('(Q6)=-5?n?5')
grid on
y=2.*[zeros(1,3), ones(1,1),zeros(1,7)];
subplot(3,3,2);
stem(n,y);
xlabel('time');
ylabel('amplitude');
title('(Q6)=2(n+2)')
grid on
y1=2.*[zeros(1,9), ones(1,1),zeros(1,1)];
subplot(3,3,3);
stem(n,y1);
xlabel('time');
ylabel('amplitude');
title('(Q6)=2(n-4),')
grid on
y2=y1-y;
subplot(3,3,4);
stem(n,y2);
xlabel('time');
ylabel('amplitude');
title('(Q6)=2(n+2)-2(n-4)');

% Question No 07
n=[1:7 6:-1:1];
subplot(3,3,5);
stem(n);
xlabel('time');
ylabel('amplitude');
title('Q7 X(N)={1,2,3,4,5,6,7,6,5,4,2,1}');
grid on
x1=2.*(n-5)-3.*(n+4);
subplot(3,3,6);
stem(n,x1);
xlabel('time');
ylabel('amplitude');
title('Q7 x1=2x(n-5)-3x(n+4)');
grid on
x2=3-n+n.*(n-2);
subplot(3,3,7);
stem(n,x2);
xlabel('time');
ylabel('amplitude');
title('Q7 x2=x(3-n)+x(n)x(n-2)');
grid on

Result of (Q= 6 and 7):

Fig. 03

CONCLUSION:
In this lab we observe the nature of different Signals & their Sequences (Shift, Reverse, Compression
etc) and their Response through different waveforms.
LAB NO: 06 (PROPERTIES of SYSTEMS)

AIM/OBJECTIVE:
The objective is to check different properties of systems using MATLAB software;
 Causality.
 Memory.
 Linearity.

EQUIPMENTS:
 PC
 MATLAB software.

THEORY:
A system is a mathematical mapping that transforms the input signal into the output signal. Thus, a system is
a process in which one signal is transformed into another signal. Usually, the physical system is made as an
interconnection of some components.

A system is called continuous-time if both input signal and output signal are continuous-time
signals. A system is called discrete-time if both input signal and output signal are discrete-time
signals.

System properties:
In this section we will study some fundamental properties of both continuous time and discrete-time
systems.

 Causal and Non-Causal Systems.

 Static (Memory less) and Dynamic (with Memory) Systems.

 Linear and Non-Linear Systems.

Causality:
Causal System:
A system whose output or response at any time instant (t) depends only on the present and past values of the
input but not on the future values of the input is called the causal system.
x(𝑡) = 𝑥(𝑡 − 3) + 3𝑥(𝑡)
x(𝑛) = 𝑥(𝑛 − 1) + 𝑥(𝑛)
Non-Causal System:
A system whose output or response at any time instant (t) depends upon future values of the input is called
the non-causal system.
x(𝑡) = 𝑥(𝑡 + 3) + 2𝑥(𝑡)
x(𝑛) = 𝑥2(𝑛) + 2𝑥(𝑛 + 1)
Static and Dynamic Systems

Static System:

A system whose response or output is due to present input alone is known as static system.
The static system is also called the memoryless system.

𝑐(𝑡) = 𝑟(𝑡)
(𝑡) = 2𝑟2(𝑡)
𝑐(𝑛) = 𝑟(𝑛)
(𝑛) = 5𝑟2(𝑛)
Dynamic System:

A system whose response or output depends upon the past or future inputs in addition to the present input is
called the dynamic system. The dynamic systems are also known as memory systems.

Some more examples of dynamic systems are given below −


(𝑡) = (𝑡 − 3)
(𝑡) = (𝑡) + 𝑟(𝑡 + 1)
(𝑛) = (5𝑛)
(𝑛) = (𝑛) + 𝑟(𝑛 + 5)

Linearity:

Linear and non-linear systems:


A system is said to be linear if it obeys the principle of homogeneity and principle of superposition.

Principle of Homogeneity
The principle of homogeneity says that a system which generates an output y(t) for an input x(t) must produce
an output ay(t) for an input ax(t).

Superposition Principle
According to the principle of superposition, a system which gives an output 𝑦1(𝑡) for an input 𝑥1(𝑡) and an
output 𝑦2(𝑡) for an input 𝑥2(𝑡) must produce an output [𝑦1(𝑡) + 𝑦2(𝑡)] for an input
[𝑥1(𝑡) + 𝑥2(𝑡)].

Therefore, for a continuous-time linear system,


[𝑎𝑦1(𝑡) + 𝑏𝑦2(𝑡)] = [𝑎𝑥1(𝑡) + 𝑏𝑥2(𝑡)] = 𝑎𝑇[𝑥1(𝑡)] + 𝑏𝑇[𝑥2(𝑡)]

Also, for a discrete-time linear system,


[𝑎𝑦1(𝑛) + 𝑏𝑦2(𝑛)] = [𝑎𝑥1(𝑛) + 𝑏𝑥2(𝑛)] = 𝑎𝑇[𝑥1(𝑛)] + 𝑏𝑇[𝑥2(𝑛)]

Hence, we can say that a system is linear if the output of the system due to weighted sum of inputs is equal to
the weighted sum of outputs.

Non-Linear System
A system is said to be a non-linear system if it does not obey the principle of homogeneity and principle of
superposition.
LAB TASK:

For linear S{a1x1(t) + a2x2(t)} = a1S{x1(t)} + a2S{x2(t)}

Let x1(t) = u(t) - u(t - 1) and x2(t) = u(t) - u(t - 2) be input signals to the systems described by the
i/o relationships y(t) = 2*x(t) and y(t) = x2(t). Determine if the linearity property holds for these
two systems.

To examine if the systems are linear, use the


scalars a1 = Registration No and a2 = Registration No. +1.

Code:
clear all
close all
clc

%UnitStep Function
t=-5:0.01:5;
z=[t>=0];
subplot(3,4,1);
plot(t,z)
title('u(t)');
xlabel('time');
ylabel('Amp');
grid on
%u(t-1)
z1=[t>=1];
subplot(3,4,2);
plot(t,z1)
title('u(t-1)');
xlabel('time');
ylabel('Amp');
grid on
%x1(t)=u(t) - u(t-1)
x1=(z-z1);
subplot(3,4,3);
plot(t,x1)
title('x1(t)=u(t) - u(t-1)');
xlabel('time');
ylabel('Amp');
grid on
%u(t-2)
w1=[t>=2];
subplot(3,4,4);
plot(t,w1)
title('u(t-2)');
xlabel('time');
ylabel('Amp');
grid on
%x2(t)=u(t) - u(t-2)
x2=(z-w1);
subplot(3,4,5);
plot(t,x2)
title('x2(t)=u(t) - u(t-2)');
xlabel('time');
ylabel('Amp');
grid on
%x=(x1+x2)
x=(x1+x2);
subplot(3,4,6);
plot(t,x)
title('x=(x1(t)+x2(t))');
xlabel('time');
ylabel('Amp');
grid on
%y1=2.*x(t)
y1=2.*x;
subplot(3,4,7);
plot(t,y1)
title('y1=2.*x(t)');
xlabel('time');
ylabel('Amp');
grid on
%y2=x^2(t)
y2=x.^2;
subplot(3,4,8);
plot(t,y2)
title('y2=x^2(t)');
xlabel('time');
ylabel('Amp');
grid on

%S[a1x1(t) + a2x2(t)]
%a1x1(t)
a1=21;
A=a1.*x1;
subplot(3,4,9);
plot(t,A)
title('a1x1(t)');
xlabel('time');
ylabel('Amp');
grid on
%a2x2(t)
%a2=21+1;
a2=22;
B=a2.*x2;
subplot(3,4,10);
plot(t,B)
title('a2x2(t)');
xlabel('time');
ylabel('Amp');
grid on
%S[a1x1(t) + a2x2(t)]
C=A+B;
subplot(3,4,11);
plot(t,C)
title('S{a1x1(t) + a2x2(t)}');
xlabel('time');
ylabel('Amp');
grid on
Figure:

CONCLUSION:
In this lab we observe the nature of Signals Properties e.g. (causality, Static and Dynamic,
Linearity) and their Response through waveforms in MATLAB.
LAB NO: 06 Practice (Even and Odd Signals)

AIM/OBJECTIVE:
The objective is to check different properties of systems using MATLAB software;
 Causality.
 Memory.
 Linearity.

EQUIPMENTS:
 PC
 MATLAB software.

Even and odd Signals:

Even Signal
A signal which is symmetrical about the vertical axis or time origin is known as even signal or
even function. Therefore, the even signals are also called the symmetrical signals.
Cosine wave is an example of even signal.
Continuous-time Even Signal
A continuous-time signal x(t) is called the even signal or symmetrical signal if it satisfies
the following condition,
x(𝑡) = 𝑥(−𝑡); for − ∞ < 𝑡 < ∞
Some examples of continuous-time even signals are shown in Figure-1.

Discrete-time Even Signal


A discrete-time signal x(n) is said to be even signal or symmetrical signal if it satisfies the
condition,
x(�) = �(−�); for − ∞ < �< ∞
Examples of discrete-time even signals are shown in Figure-2.
Odd Signal
A signal that is anti-symmetrical about the vertical axis is known as odd signal or odd function.
Therefore, the odd signals are also called the antisymmetric signals.
Sine wave is an example of odd signal.
Continuous-time Odd Signal
A continuous time signal x(t) is called an odd signal or antisymmetric signal if it satisfies the
Following condition,
x(−𝑡) = −𝑥(𝑡); for − ∞ < 𝑡 < ∞
Examples of continuous time odd signals or antisymmetric signals are shown in Figure-3.

Discrete-time Odd Signal


A discrete time signal x(n) is said to be an odd signal or antisymmetric signal, if it satisfies the
following condition,
x(−𝑛) = −𝑥(𝑛); for − ∞ < 𝑛 < ∞
Examples of discrete-time odd signals are shown in Figure-4.

LAB TASK:

1- Addition of two signals.


Define the given functions in the interval 0 to 2П and add them.
Cos(t) and sin (3t).

2- Suppose that x(t) = t* cos(2 π t), 0 ≤ t ≤ 5.


Plot the signals x(t), x(-t), x(t/5), x(1 +3t) , x( -1-3t)

3- x(t) = t*e-t, -1 ≤ t ≤ 3.
Plot the following different versions of the above signal.
 Flipped Signal
 Amplitude scaled signal (by a factor of 2 and 1/2)
 x(1-2t)
Code:
clear all
close all
clc

% Q1+ addition of signals


t=0:0.01:2.*pi;
x=cos(t)
subplot(4,4,1)
plot(t,x)
title('cos(t)')
grid on
y=sin(3.*t);
subplot(4,4,2);
plot(t,y)
title('sin(3t)')
grid on
x1=x+y;
subplot(4,4,3);
plot(t,x1)
title('addition of sin & cos')
grid on
% Question 2
t1=-1:0.01:3;
x2=t1.*cos(2.*pi.*t1);
subplot(4,4,4);
plot(t1,x2)
title('x(t)')
grid on
x3=x2
subplot(4,4,5);
plot(-t1,x3)
title('x(-t)')
grid on
x4=x2;
subplot(4,4,6);
plot(t1/5,x4)
title('x(t/5)')
grid on
x5=(x2);
subplot(4,4,7);
plot(((3.*t1)+1),x5)
title('x(1+3t)')
grid on
x6=(x2);
subplot(4,4,8);
plot(((-3.*t1)-1),x6)
title('x(-1-3t)')
grid on
% Question 3
t2=-1:0.1:3;
x7=t2.*exp(-t2);
subplot(4,4,9);
plot(t2,x7)
title('t*e-t')
grid on
x8=flip(x7)
subplot(4,4,10);
plot(t2,x8)
title('flip of (t*e-t)')
grid on
x9=2.*t2;
subplot(4,4,11);
plot(t2,x9)
title('amplitude by 2')
grid on
x10=0.5.*t2;
subplot(4,4,12);
plot(t2,x10)
title('amplitude by 1/2')
grid on
x11=(x7>=-1);
subplot(4,4,13);
plot(-2.*t2,x11)
title('x(1-2t)')
grid on

Figure:

CONCLUSION:

In this lab we observe the nature of Signals Properties e.g. (even and odd signals) and their
Response through waveforms in MATLAB.
LAB NO: 07 (Convolution between Signals and Sequences)

AIM/OBJECTIVE:
The objective is to find the output with linear convolution operation using MATLAB software;

EQUIPMENTS:
 PC
 MATLAB software.

THEORY:
Linear Convolution involves the following operations.

1. Folding
2. Shifting
3. Multiplication
4. Addition

In mathematics (in particular, functional analysis), convolution is a mathematical operation on


two functions (f and g) that produces a third function {\displaystyle f*g}(f*g) {\displaystyle f*g}that
expresses how the shape of one is modified by the other.

The convolution of f and g is written f*g, denoting the operator with the symbol *. It is defined as the integral
of the product of the two functions after one is reflected about the y-axis and shifted. As such, it is a particular
kind of integral transform:

An equivalent definition is
LAB TASK:

Perform linear convolution of given sequences/signals.

1- [1 4 3 2] and [1 0 2 1]
2- x1(t)=e-3t{u(t)-u(t-2)} , x2(t)= e -3t for 0 ≤ t ≤ 2

Perform convolution of two signals (sin wave and a cos wave both having different frequencies)

1). [1 4 3 2] and [1 0 2 1]
Code:
clear all
close all
clc

%[1 4 3 2] and [1 0 2 1]
%[1 4 3 2]
x=[1 4 3 2];
subplot(3,1,1)
stem(x)
xlabel('time');
ylabel('amplitude');
title('Samples');
grid on
% [1 0 2 1]
x2=[1 0 2 1];
subplot(3,1,2);
stem(x2)
xlabel('time');
ylabel('amplitude');
title('Samples');
grid on
%Convolution of x1 & x2
y=conv(x,x2);
subplot(3,1,3);
stem(y)
xlabel('time');
ylabel('amplitude');
title('Convolution of x1 & x2');
grid on

Result:
2). x1(t)=e-3t{u(t)-u(t-2)} , x2(t)= e -3t for 0 ≤ t ≤ 2

Code:
clear all
close all
clc
%x1(t)=e-3t{u(t)-u(t-2)} , x2(t)= e -3t for 0 < t < 2
t=0:0.01:2;
y=exp(-3.*t);
y1=[t>=0];
y2=[t>=2];
y3=y1-y2;
subplot(4,2,1);
plot(t,y);
xlabel('time');
ylabel('amplitude');
title('exponentional function (-3t)');
grid on
subplot(4,2,2);
plot(t,y1,'linewidth',3);
xlabel('time');
ylabel('amplitude');
title('unitstep function');
grid on
subplot(4,2,3);
plot(t,y2,'linewidth',3);
xlabel('time');
ylabel('amplitude');
title('unitstep function with +2 shift');
grid on
subplot(4,2,4);
plot(t,y3,'linewidth',3);
xlabel('time');
ylabel('amplitude');
title('u(t)-u(t-2)');
grid on
% x1={e^-3t} * {u(t)-u(t-2)}
x1=y.*y3;
subplot(4,2,5);
plot(t,x1,'linewidth',3);
xlabel('time');
ylabel('amplitude');
title('x1={e^-3t} * {u(t)-u(t-2)}');
grid on
%x2=e^-3t
x2=exp(-3.*t);
subplot(4,2,6);
plot(t,x2);
xlabel('time');
ylabel('amplitude');
title('exponentional function with (-3t)');
grid on
% convolution of x1 & x2
x=conv(x1,x2);
subplot(4,2,7);
plot(t,x1,'linewidth',3);
xlabel('time');
ylabel('amplitude');
title('convolution of x1 & x2');
grid on
Result:

3). Perform convolution of two signals (sin wave and a cos wave both having different frequencies)

Code:
clear all
close all
clc
% Perform convolution of two signals (sin wave and a cos wave both having different
frequencies)
%sin Function
t1=0:0.01:5;
f=10;
A=2;
y5=A.*sin(2.*pi*f.*t1);
subplot(4,1,1);
plot(t1,y5);
xlabel('time');
ylabel('amplitude');
title('sin finction');
grid on
%cos function
f1=20;
A1=2;
y6=A1.*cos(2.*pi*f1.*t1);
subplot(4,1,2);
plot(t1,y6);
xlabel('time');
ylabel('amplitude');
title('cos finction');
grid on
%Convolution of Sin & Cos function
z=conv(y5,y6);
subplot(4,1,3);
plot(z);
xlabel('time');
ylabel('amplitude');
title('convolution of sin & cos function');
grid on
%Time Scaling of Convoluted Signal
dt=0:0.01:10;
subplot(4,1,4);
plot(dt,z);
xlabel('time');
ylabel('amplitude');
title('Time Scaling of Convoluted Signal');
grid on
Result:

4).Convolve the random two given signals.


Code:
clear all
close all
clc
%Ramp function
t=0:0.01:2;
x=2-t;
subplot(2,2,1);
plot(t,x,'k','linewidth',3);
xlabel('time');
ylabel('amplitude');
title('x=ramp function(2-t)');
grid on

%Rect Pulse
t1=-3.5:0.01:3.5;
x1=3*rectpuls(t1,4);
subplot(2,2,2);
plot(t1,x1,'b','linewidth',3);
xlabel('time');
ylabel('amplitude');
title('x1=rect pulse');
grid on

%Convolution x and x1
z=conv(x/10,x1/10)
subplot(2,2,3);
plot(z,'r','linewidth',3)
xlabel('time');
ylabel('amplitude');
title('Linear Convolution of x and x2');
grid on

% time scaling of convoluted signal


t2=0:0.01:9;
subplot(2,2,4);
plot(t2,z,'r','linewidth',3)
axis([-2 12 0 8]);
xlabel('time');
ylabel('amplitude');
title('time scaling of convoluted signal');
grid on

Result:

5.)Convolution of cos signal with a random data (noise signal).


Code:
clear all
close all
clc
%Cos Function
t=0:0.01:5;
x=cos(t);
subplot(2,2,1);
plot(t,x)
xlabel('time');
ylabel('amplitude');
title('x=cos function');
grid on

%Noise Signal
x1=rand(1,length(t));
subplot(2,2,2);
plot(t,x1)
xlabel('time');
ylabel('amplitude');
title('x1=Noise Signal');
grid on

%COnvolution of x & x1
x2=conv(x1/10,x/10);
subplot(2,2,3);
plot(x2)
xlabel('time');
ylabel('amplitude');
title('Convolution of x & x1 and also amplitude scalling');
grid on
% Time Scalling of Convoluted Signal
t1=1:0.01:11;
subplot(2,2,4);
plot(t1,x2);
xlabel('time');
ylabel('amplitude');
title('time Scalling of Convoluted Signal');
grid on

Result:

CONCLUSION:
In this lab we seek the convolution between signals and sequences and their response through waveforms in
MATLAB.
LAB NO: 08 (USE OF CONDITIONAL STATEMENTS AND FOR LOOP IN MATLAB)

AIM/OBJECTIVE:
The main aim/objective is how we insert conditional (if), repeat (for) and or (else) loop in programming using
MATLAB software.

EQUIPMENTS:
 PC
 MATLAB software.

THEORY:

For Loop:
A for loop is a repetition control structure that allows you to efficiently write a loop that
needs to execute a specific number of times.
Syntax:
The syntax of a for loop in MATLAB is −
for index = values
<program statements>
end
values has one of the following forms −

Sr.No. Format & Description


initval:endval
01
Increments the index variable from initval to endval by 1, and repeats execution
of program statements until index is greater than endval.
initval:step:endval
02
Increments index by the value step on each iteration, or decrements when step is
negative.
valArray
Creates a column vector index from subsequent columns of array valArray on each
03 iteration. For example, on the first iteration, index = valArray (:,1). The loop executes
for a maximum of n times, where n is the number of columns of valArray, given by
numel (valArray, 1, :). The input valArray can be of any MATLAB data type,
including a string, cell array, or struct.

Conditional (if) and OR (else) Loop:


Syntax:
The syntax of a if loop and elseif loops in MATLAB is −
if expression
statements
elseif expression
statements
else
statements
end
LAB TASK:
 Write a MATLAB code to compute the square, cube, and fourth power of all integers
between 4 and 18.
 Define an array of 10 numbers and write a matlab code for adding all these numbers
and displaying the answers at the End using for loop.
 Write the MATLAB program to ask a number from a user, verify that the number is
not negative.
 Generate random integers between 100 and 1. Categorize them as small medium and
large (set your own threshold level.) Using if and else if command.
 Write a MATLAB code that considers a student pass if attendance is greater than or
equal to 75 and grade is greater than Or equal to 60 else FAIL.
 Make a MATLAB program that uses for loop, if and else if (nested if).

MATLAB Program:
1). Write a MATLAB code to compute the square, cube, and fourth power of all integers between 4 and
18.

Code:
clear all
close all
clc
for a=4:18
x1=a^2
x2=a^3
x3=a^4
end

Result: 7
x1 = x1 =
16 49
x2 = x2 =
64 343
x3 = x3 =
256 2401

5 8
x1 = x1 =
25 64
x2 = x2 =
125 512
x3 = x3 =
625 4096

6 9
x1 = x1 =
36 81
x2 = x2 =
216 729
x3 = x3 =
1296 6561
x1 =
100
x2 = x3 =
1000 38416
x3 =
10000 15
x1 =
11 225
x1 = x2 =
121 3375
x2 = x3 =
1331 50625
x3 =
14641 16
x1 =
12 256
x1 = x2 =
144 4096
x2 = x3 =
1728 65536
x3 =
20736 17
x1 =
13 289
x1 = x2 =
169 4913
x2 = x3 =
2197 83521
x3 =
28561 18
x1 =
14 324
x1 = x2 =
196 5832
x2 = x3 =
2744 104976

2). Define an array of 10 numbers and write a matlab code for adding all these numbers and displaying
the answers at the End using for loop.

Code:
clear all
close all
clc
m=[1 2 3 4 5 6 7 8 9 10]
sum=0
for i=1:length(m)
sum=sum+m(i)
disp('sum')
end

Result:

m=
Columns 1 through 9
1 2 3 4 5 6 7 8 9
Column 10
10
sum =
0
sum = sum =
1 21
sum sum
sum = sum =
3 28
sum sum
sum = sum =
6 36
sum sum
sum = sum =
10 45
sum sum
sum = sum =
15 55
sum Sum

3). Write the MATLAB program to ask a number from a user, verify that the number is not negative.

Code:
clear all
close all
clc
Number='Enter a number';
x=input(Number);
if x<0
disp('your input is negative')
end
if x>0
disp('your input is positive')
end
if x==0
disp('your input is zero')
end

Result:
Enter a number 6
Your input is positive

4). Generate random integers between 100 and 1. Categorize them as small medium and large (set your
own threshold level.) Using if and else if command.

Code:
clear all
close all
clc
a = randi(100,1);
if a >= 70
disp('Large')
elseif a <= 69 && a > 45
disp('meduim')
else
disp('small')
end

Result:
a=
92
Large

5). Write a MATLAB code that considers a student pass if attendance is greater than or equal to 75 and
grade is greater than Or equal to 60 else FAIL.
Code:
clear all
close all
clc
Grade=input('Enter the Obtained Marks of Student');
Attendance=input('Enter the Attendance of Student');
if (Grade>=60) && (Attendance>=75);
disp('Student is Pass');
else
disp('Student is fail');
end

Result:
Enter the Obtained Marks of Student 79
Enter the Attendance of Student 76
Student is Pass
And,
Enter the Obtained Marks of Student 60
Enter the Attendance of Student 56
Student is fail

6) Make a MATLAB program that uses for loop, if and else if (nested if).

Code:
clear all
close all
clc
nrows = 4;
ncols = 6;
A = ones(nrows,ncols);
for c = 1:ncols
for r = 1:nrows

if r == c
A(r,c) = 2;
elseif abs(r-c) == 1
A(r,c) = -1;
else
A(r,c) = 0;
end

end
end
A

Result:
A=
2 -1 0 0 0 0
-1 2 -1 0 0 0
0 -1 2 -1 0 0
0 0 -1 2 -1 0

CONCLUSION:
In this lab we seek conditional (if), repeat (for) and or (else) loop in programming in MATLAB.
LAB NO: 09 (FOURIER SERIES AND FOURIER TRANSFORM)

AIM/OBJECTIVE:
To find the Fourier series coefficients and Fourier transform of different signals in MATLAB

EQUIPMENTS:
 PC
 MATLAB software.

THEORY:
A signal has one or more frequencies in it, and can be viewed from two different standpoints:
Time domain and Frequency domain.

Time‐domain figure: how a signal changes over time


Frequency‐domain figure: how much of the signal lies within each given frequency band
over a range of frequencies

Why frequency domain analysis?


 To decompose a complex signal into simpler parts to facilitate analysis
 Differential and difference equations and convolution operations in the time
domain become algebraic operations in the frequency domain.
 Fast Algorithm (FFT)

We can go between the time domain and the frequency domain by using Fourier series and Fourier
Transform.
A Fourier transform converts a signal in the time domain to the frequency domain (spectrum).
An Inverse Fourier transform converts the frequency domain components back into the original time
domain signal.

Fourier series and Fourier transform are used to convert a signal to frequency domain.

Fourier series:
Fourier series simply states that, periodic signals can be represented into sum of sines and cosines when
multiplied with a certain weight. It further states that periodic signals can be broken down into further
signals with the following properties.

 The signals are sines and cosines


 The signals are harmonics of each other
It can be pictorially viewed as
Fourier series can be generally written as

LAB TASK:
 Find Fourier coefficients of unit step function and ramp function.

MATLAB Program:
For ramp function
clear all
close all
clc
syms x
pi=3.14;
sum=0;
y=x;
a0=(1/pi)*int(y,x,-pi,pi);
for n=1:3
an=(1/pi)*int(y*cos(n*x),x,-pi,pi);
bn=(1/pi)*int(y*sin(n*x),x,-pi,pi);
sum=sum+(an*cos(n*x)+bn*sin(n*x));
end
ezplot(x,y,[-pi,pi]);
grid on;hold on;
ezplot(x,(sum+a0/2),[-pi,pi]);
Result:

MATLAB Program:
For unitstep function
clear all
close all
clc
syms x
pi=3.14;
sum=0
y=heaviside(x);
a0=(1/pi)*int(y,x,-pi,pi);
for n=1:5
an=(1/pi)*int(y*cos(n*x),x,-pi,pi);
bn=(1/pi)*int(y*sin(n*x),x,-pi,pi);
sum=sum+(an*cos(n*x)+bn*sin(n*x));
end
ezplot(x,y,[-pi,pi]);
grid on;hold on;
ezplot(x,(sum+a0/2),[-pi,pi]);
Result:
Fourier Transform:
The Fourier transformation is a mathematical formula that relates a signal sampled in time or space to
the same signal sampled in frequency. In signal processing, the Fourier transform can reveal important
characteristics of a signal, namely, its frequency components.
The Fourier transform simply states that that the non-periodic signals whose area under the curve is
finite can also be represented into integrals of the sines and cosines after being multiplied by a certain
weight.
The Fourier transform has many wide applications that include, image compression (e.g JPEG
compression), filtering and image analysis
Although both Fourier series and Fourier transform are given by Fourier, but the difference between
them is Fourier series is applied on periodic signals and Fourier transform is applied for non-periodic
signals.

Inverse Fourier Transform:

Mathematical Example:
MATLAB Program:
%MATLAB coding for fourier transform of square wave:
close all
clear all
clc
Fs = 150; % Sampling frequency
t = 0:1/Fs:1; % Time vector of 1 second
f = 5; % Create a sine wave of f Hz.
x = square(2*pi*t*f);

nfft = 1024; % Length of FFT

X = fft(x,nfft);

X = X(1:nfft/2);
% Take the magnitude of fft of x
mx = abs(X);
% Frequency vector
f = (0:nfft/2-1)*Fs/nfft;

% Generate the plot, title and labels.


figure(1);
plot(t,x);
title('Square Wave Signal');
xlabel('Time (s)');
ylabel('Amplitude');
figure(2);
plot(f,mx);
title('Power Spectrum of a Square Wave');
xlabel('Frequency (Hz)');
ylabel('Power');
LAB TASK:
 Find the Fourier transform of exponentially increasing and exponentially decaying
signal.

MATLAB Program:
%exponentially decaying
clear all
close all
clc
Fs = 150; % Sampling frequency
t = 0:1/Fs:1; % Time vector of 1 second
f = 5; % Create a exp wave of f Hz.
x = exp(2*pi*-t*f);
nfft = 1024; % Length of FFT
X = fft(x,nfft);
X = X(1:nfft/2);
% Take the magnitude of fft of x
mx = abs(X);
% Frequency vector
f = (0:nfft/2-1)*Fs/nfft;
% Generate the plot, title and labels.
figure(1);
plot(t,x);
title('exp decaying Signal');
xlabel('Time (s)');
ylabel('Amplitude');
figure(2);
plot(f,mx);
title('Power Spectrum of a exp decaying Signal');
xlabel('Frequency (Hz)');
ylabel('Power');

Result:
MATLAB Program:
%exponentially increasing
clear all
close all
clc
Fs = 150; % Sampling frequency
t = 0:1/Fs:1; % Time vector of 1 second
f = 5; % Create a exp wave of f Hz.
x = -exp(2*pi*-t*f);
nfft = 1024; % Length of FFT
X = fft(x,nfft);
X = X(1:nfft/2);
% Take the magnitude of fft of x
mx = abs(X);
% Frequency vector
f = (0:nfft/2-1)*Fs/nfft;
% Generate the plot, title and labels.
figure(1);
plot(t,x);
title('exp increasing Signal');
xlabel('Time (s)');
ylabel('Amplitude');
figure(2);
plot(f,mx);
title('Power Spectrum of a exp increasing Signal');
xlabel('Frequency (Hz)');
ylabel('Power');

Result:

CONCLUSION:
In this lab we observe Fourier series and Fourier Transform in programming using MATLAB.
LAB NO: 10 (LAPLACE AND Z-TRANSFORM)

AIM/OBJECTIVE:
The main aim/objective is how we insert Laplace and Z-Transform in programming using MATLAB software.

EQUIPMENTS:
 PC
 MATLAB software.

THEORY:
Transforms are used in science and engineering as a tool for simplifying analysis and look at data from another
angle.
For example, the Fourier transform allows us to convert a signal represented as a function of time to a function of
frequency. Laplace transform allows us to convert a differential equation to an algebraic equation.
Laplace transforms use the s-plane, and frequency response is computed on the imaginary axis s = jω . The Z
transform uses the z-plane, and the frequency response is computed on the unit circle jθ z = e .
The Laplace transform is appropriate for continuous-time systems, while the Z transform is appropriate for
discrete-time systems. In control system applications, discrete time systems are called sampled-data systems. In
signal processing applications, they are called digital filters or digital signal processors.
Laplace Transform:
The Laplace Transform is an integral transformation of a function f(t) from the time domain into the complex
frequency domain, giving F(s)

𝑓(𝑡) ( ) ∫ 𝑓(𝑡)𝑒 𝑑𝑡
 s: complex frequency
 Called “The One-sided or unilateral Laplace Transform”.

 In the two-sided or bilateral LT, the lower limit is -. We do not use this.

LAB TASK:
1). Find the Laplace transform of the given functions (exp, decaying sin and decaying cosine).

MATLAB Code:
clear all
close all
clc
syms t a b;
F=exp(-a*t)*sin(b*t);
L=laplace(F)
S=simplify(L)
pretty(S)

Result:
L=
b/((a + s)^2 + b^2)

S=
b/((a + s)^2 + b^2)
b
-------------
2 2
(a + s) + b

2). Find Laplace Transform of the given function


𝑓(𝑡) 𝑡𝑒 𝑒

MATLAB Code:
clear all
close all
clc
syms t a;
f=-1.25+3.5*exp(-2*t)*t+1.25*exp(-2*t);
L=laplace(f)
S=simplify(L)
pretty(S)

Result:
L =
5/(4*(s + 2)) + 7/(2*(s + 2)^2) - 5/(4*s)

S =
(s - 5)/(s*(s + 2)^2)

s - 5
----------
2
s (s + 2)

3). Find the inverse Laplace of the Question No 02 answer Or Cross-check.

MATLAB Code:
clear all
close all
clc
syms F s;
f=(s- 5)/(s*(s+2)^2);
L=ilaplace(f)
S=simplify(L)
pretty(S)

Result:
L =
(5*exp(-2*t))/4 + (7*t*exp(-2*t))/2 - 5/4

S =
(5*exp(-2*t))/4 + (7*t*exp(-2*t))/2 - 5/4

exp(-2 t) 5 t exp(-2 t) 7 5
----------- + ------------- - -
4 2 4

After the solution the above expression the resultant Transfer Function are same as Question
No 02 Transfer Function.
4). Find Laplace Transform of cos and sin function.

MATLAB Code:
% Cos Function % Sin Function
clear all clear all
close all close all
clc clc
syms t a w; syms t a w;
F=cos(t*w); F=cos(t*w);
L=laplace(F) L=laplace(F)
S=simplify(L) S=simplify(L)
pretty(S) pretty(S)

Result:

L = L =
s/(s^2 + w^2) w/(s^2 + w^2)

S = S =
s/(s^2 + w^2) w/(s^2 + w^2)

s w
------- -------
2 2 2 2
s + w s + w

5) Find Inverse Laplace transform of


( )
( )
( )

MATLAB Code:
clear all
close all
clc
syms F s;
f=(10*s+20)/(s^3+4*s^2+5*s);
L=ilaplace(f)
S=simplify(L)
pretty(S)

Result:
L =

4 - 4*exp(-2*t)*(cos(t) - sin(t)/2)

S =

4 - 4*exp(-2*t)*(cos(t) - sin(t)/2)

/ sin(t) \
4 - exp(-2 t) | cos(t) - ------ | 4
\ 2 /
Cross-Check MATLAB Code:
clear all
close all
clc
syms t a;
f=4-exp(-2*t)*(cos(t)- sin(t)/2)*4;
L=laplace(f)
S=simplify(L)
pretty(S)

Result:
L =
4/s - (4*(s + 2))/((s + 2)^2 + 1) + 2/((s + 2)^2 + 1)

S =
(10*(s + 2))/(s*(s^2 + 4*s + 5))

(s + 2) 10
----------------
2
s (s + 4 s + 5)

We see the given transfer Function in Question No 05 and the cross-check results are same.

CONCLUSION:
In this lab we observe Laplace and Z-Transform in MATLAB.

You might also like