0% found this document useful (0 votes)
50 views27 pages

Name: Wisal Muhammad Department: Electrical Communication

This document contains information about plotting a continuous time sinusoidal signal in MATLAB. It discusses: 1. Defining variables such as frequency, time period, amplitude, and time vector. 2. Using commands like plot, hold on, grid on, xlabel, ylabel and title to generate and style the graph. 3. Plotting two signals (sine and cosine) on the same axis and using the legend command to identify the plots. The document provides the MATLAB code used to generate the plotted signal and discusses editing features like changing color, thickness, adding grid lines and labels. It also discusses identifying plots using the legend command.

Uploaded by

ZiYAD Ahmad
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)
50 views27 pages

Name: Wisal Muhammad Department: Electrical Communication

This document contains information about plotting a continuous time sinusoidal signal in MATLAB. It discusses: 1. Defining variables such as frequency, time period, amplitude, and time vector. 2. Using commands like plot, hold on, grid on, xlabel, ylabel and title to generate and style the graph. 3. Plotting two signals (sine and cosine) on the same axis and using the legend command to identify the plots. The document provides the MATLAB code used to generate the plotted signal and discusses editing features like changing color, thickness, adding grid lines and labels. It also discusses identifying plots using the legend command.

Uploaded by

ZiYAD Ahmad
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/ 27

Name: Wisal Muhammad

Department: Electrical Communication.


Registration no: 17PWELE5127.
Section: B.
Subject: signal and system
Submitted to: Sir Kifayat Ullah
Lab # 01
Plotting A Continuous Time Sinusoidal Signal
Continuous time signal:
A continuous time signal is the one whose value is defined at every instance till infinity. But in
MATLAB or in real time we can’t execute such a time signal so we will be using a discrete time
signal.
Basically we are making a discrete time signal but we plot it in such a way that it looks like a
continuous time signal because we don’t have infinite MEMORY or TIME.

Requirements:
So, for this purpose we need;
 A function.
 Input the value of independent variable.
 Get the value of the output variable.
So first we define a variable let say (t)

Declaring a variable:
f=1000;
T=1/f;
A=10;
t=0:T/100:5*T;
initial point =0
final point =5*T
step size =T/100
f=frequency
T=Time period
A=amplitude
The step size should be kept small so that the waveform comes out to be smooth
( ; ) SIGN:-
This semicolon in MATLAB has a specific purpose if it is not placed at the end of a statement then
the statement will not be terminated and all the values will appear on the command window.
(clear all)
Clears everything from the workspace.
(clc)
Clears the command window.

Main steps:
so, basically there are three main steps for plotting a continuous signal which are as follow;
 Define a variable.
 Define a function.
 Plot.

MATLAB code:
f=1000;
T=1/f;
A=10;
t=0:T/100:5*T;
x=A*sin(2*pi*f*t);
figure(1)
plot(t,x,'y--','linewidth',2)
grid on
hold on
y=A*cos(2*pi*f*t);
plot(t,y,'r','linewidth',1)
xlabel('Time in seconds')
ylabel('Voltage in volts')
title('Continuous sinusoidal wave')
legend([plot(t,x),plot(t,y)],'sint','cost')

Now let us discuss the ARTISTIC features ;

EDITTING A GRAPH (COMMANDS):


1) Changing the color of the graph:
Plot( t , y , ’r’ ); r=red color.
2) Thickness:
Plot( t , y , ’r’, ’linewidth’ , 3 ); linewidth by default is set to 1.
3) Grid.
grid on command is used for grid line to appear on the graph.
4) Label:
This feature is used to identify that which quality is being plotted against the x-axis and y-
axis and also for giving a title to the graph.
5) Changing style of the graph:
We can also change the style of the graph by using a dash, a steric or a dot symbol so that
we can differentiate between different graphs.
Command:
Plot( t , y , ’r--‘ , ’linewidth’ , 3);
6) Identification of polts:
Use legend to identify the plots.

RESULTS

Home Task # 01
To Draw Three Continuous Sinusoidal Waveform On Single Axis

Continuous Time Signal:


A continuous time signal is the one whose value is defined at every
instance till infinity. But in MATLAB or in real time we can’t execute such a time signal so we will
be using a discrete time signal.
Basically we are making a discrete time signal but we plot it in such a way that it looks like a
continuous time signal because we don’t have infinite MEMORY or TIME.

Requirements:
So, for this purpose we needed;
 A function.
 Input the value of independent variable.
 Get the value of the output variable.
So first we define a variable let say (t)

Declaring a variable:
f=1200;
T=1/f;
t=0:0.001:2*pi;
initial point =0
final point =2*pi
step size =0.001
f=frequency
T=Time period
The step size should be kept small so that the waveform comes out to be smooth
( ; ) SIGN:-
This semicolon in MATLAB has a specific purpose if it is not placed at the end of a statement then
the statement will not be terminated and all the values will appear on the command window.
(clear all) COMMAND:-
Clears everything from the workspace.
(clc) COMMAND:-
Clears the command window.

Main steps:
So, basically there are three main steps for plotting a continuous signal which are
as follow;
 Define a variable.
 Define a function.
 Plot.

MATLAB Code:
f=1200;
T=1/f;
t=0:0.001:2*pi;
a=sin(t);
hold on
b=sin(2*t);
hold on
c=sin(3*t);
hold on
plot(t,a,'g--',t,b,'r--',t,c,'b')
xlabel('Time in seconds')
ylabel('Voltage in volts')
title('Continuous sinusoidal wave')
grid on
legend([plot(t,a),plot(t,b),plot(t,c)],'sint','sin2t','sin3t')

Result:

Lab # 02
To plot an oscillatory signal in MATLAB.
The main equation of exponential continuous time signal is:
X(t)=Ceat where
C= magnitude of the function.
a= exponent of the function, it decide the type of the function’ if
a= positive value, function is exponentially rising.
a= zero, function is constant.
a= negative value, function is exponentially decaying.

MATLAB Code:

f=50;
T=1/f;
c=2;
t=0:T/20:40*T;
%case-1 (Increasing Oscillatory Signal)
a=2;
x1=sin(2*pi*f*t);
x2=c*exp(a*t);
x3=x1.*x2;
subplot(3,3,1);
plot(t,x1)
subplot(3,3,2);
plot(t,x2);
subplot(3,3,3);
plot(t,x3);
title('Increasing Oscillatory Signal')
xlabel('Time')
ylabel('Amplitude')
%case-2 (sustained Oscillatory Signal)
a=0;
y1=sin(2*pi*f*t);
y2=c*exp(a*t);
y3=y1.*y2
subplot(3,3,4);
plot(t,y1);
subplot(3,3,5);
plot(t,y2);
subplot(3,3,6);
plot(t,y3);
title('Sustained Oscillatory Signal');
xlabel('Time')
ylabel('Amplitude')
%case-3 (Decreasing Oscillatory Signal)
a=-2;
z1=sin(2*pi*f*t);
z2=c*exp(a*t);
z3=z1.*z2;
subplot(3,3,7);
plot(t,z1);
subplot(3,3,8);
plot(t,z2);
subplot(3,3,9);
plot(t,z3);
title('Decreasing Oscillatory Signal')
xlabel('Time')
ylabel('Amplitude')
RESULT:

Home Task No:02


MATLAB Code:
x=-10:0.01:10;
y=3*x.^4+2*x.^3+7*x.^2+2*x+9
plot(t,y);
xlabel('time')
ylabel('Magnitude')
title('Home Task No 2')
Plot:

Comments:
This is a parabolic graph representing a quadratic equation.

Lab # 03
To plot a discrete time signal in matlab.

Stem command:
We use stem command in order to draw discrete time signal.

MATLAB code:
n=0:5
a=2;
c=2;
y=c*a.^n;
stem(n,y)
xlabel('Time')
ylabel('Amplitude')
title('Discrete Time Signal')
grid on

Result:
Lab # 04
To Plot A Piecewise Signal In MATLAB
Piecewise signal:
A piecewise function is a function that is define on a sequence of intervals. A common
example is the absolute value.

MATLAB Code:
t0=-5:0.01:-3;
x0=zeros(size(t0));
t1=-3:0.01:-2;
x1=-t1-3;
t2=-2:0.01:-1;
x2=ones(size(t2));
t3=-1:0.01:0;
x3=2*ones(size(t3));
t4=0:0.01:1;
x4=ones(size(t4));
t5=1:0.01:2;
x5=-t5+2;
t6=2:0.01:5;
x6=zeros(size(t6));
x=[x0 x1 x2 x3 x4 x5 x6];
t=[t0 t1 t2 t3 t4 t5 t6];
plot(t,x);
xlabel('Time')
ylabel('Amplitude')
title('Piecewise Signal')
grid on
Result
Lab # 05
To Study Time Transformation of a Signal in MATLAB
Discrete Time Signal Time Shifting:
MATLAB Code:
%time shifting in discrete Time signal
t=[ 1 2 3 4 5 6 7 ];
x=[ 0 1 2 3 2 1 0 ];
subplot(1,3,1);
stem(t,x);
xlabel ('Time')
ylabel ('Amplitude')
title('Original Signal');
a=t+3 %Delayed signal by 3 units
subplot(1,3,2);
stem(a,x);
xlabel ('Time')
ylabel ('Amplitude')
title('Delayed Signal');
b=t-3 %Advanced Signal by 3 units
subplot(1,3,3)
plot(b,x);
xlabel ('Time')
ylabel ('Amplitude')
title('Advanced Signal')
Result:

Continuous time signal time shifting:


MATLAB Code:
t=0:0.01:3*pi;
y=sin(t); %Original signal
subplot(3,1,1);
plot(t,y);
xlabel('Time')
ylabel('Amplitude')
title('Original Signal')
y1=sin(t+1) %Advanced Signal
subplot(3,1,2);
plot(t,y1);
xlabel('Time')
ylabel('Amplitude')
title('Advanced signa');
y2=sin(t-1) %Delayed Signal
subplot(3,1,3);
plot(t,y2);
xlabel('Time')
ylabel('Amplitude')
title('Delayed Signal')
Result:
Time scaling:
MATLAB Code:
t=0:0.01:2*pi;
y=sin(t);
y1=sin(2*t) %compressed Signal
y2=sin(t/2) %Expanded signal
subplot(3,1,1);
plot(t,y);
xlabel('Time')
ylabel('Amplitude')
title('Original Signal');
subplot(3,1,2);
plot(t,y1)
xlabel('Time')
ylabel('Amplitude')
title('Compressed Signal')
subplot(3,1,3);
plot(t,y2)
xlabel('Time')
ylabel('Amplitude')
title('expanded Signal')
Result:

Time Reversal:
MATLAB Code:
t=0:0.01:3*pi;
y=sin(t);
y1=sin(-t);
subplot(2,1,1);
plot(t,y);
xlabel('Time')
ylabel('Amplitude')
title('Original Signal')
subplot(2,1,2);
plot(t,y1);
xlabel('Time')
ylabel('Amplitude')
title('Inverted Signal')
Result:

Lab # 06
Discrete Time Convolution In MATLAB
LTI System:
System that are both linear and Time Invariant.
The fundamental result in LTI system theory is that any LTI system can be characterized
entirely by a single function called system’s Impulse response.
The output of system is the convolution of the input to the system’s impulse response

Convolution:
If the input to the LTI system is unit impulse signal, the output is impulse response.
Similarly convolution is operation performed on system function and input to the system.
So convolution of input function and system function gives us output of that system.

MATLAB Code:
x=[1 0 2];
h=[1 -1];
y=conv(x,h);
subplot(3,1,1);
stem(x);
title('Input Signal');
subplot(3,1,2);
stem(h);
title('Impulse Response');
subplot(3,1,3);
stem(y);
title('Output signal')
Result:

Lab # 07
Differentiation in MATLAB
Ordinary derivative:
Used to find the difference between two consecutive elements in matrix.
Diff command is used

MATLAB code:

The diff command can also be used to find higher order derivative.

MATLAB Code:
%derivative
syms x f1 f2 f3 a b c d e f g h
f1=3*x^3+7*x^2+9*x-7
fprintf('The 1st derivative is\n')
a=diff(f1,x)
fprintf('The 2nd derivative is\n')
b=diff(a,x)
fprintf('The 3rd derivative is\n')
c=diff(b,x)
fprintf('The 4th derivative is\n')
d=diff(c,x)
Result:

Partial derivative:
Again diff command is used
MATLAB Code:

Result:

Solving integration:
Int command is used
MATLAB Code:

Result:

Solving differential equation:


2 2
d x/dt =30

MATLAB Code:

Result:
Lab # 08
Laplace Transformation In MATLAB
Laplace Transform:
Laplace transform is linear operator on a function x(t) with real arguments, which transform
it to a function X(s) with complex arguments s=a+ jw. In signal and system , the real
arguments usually represents time domain and complex argument usually repres ents
frequency domain.
x(t)----------------------------> X(S)

MATLAB Code:
clear all
clc
syms imp stp rmp parb x y t ex
imp=dirac(t)
stp=heaviside(t)
rmp=t
parb=t^2
x=sin(2*t)
y=cos(-2*t)
ex=exp(-3*t)
fprintf('The Laplace Transform of unit impulse signal\n')
laplace(imp)
fprintf('The Laplace Transform of unit step signal\n')
laplace(stp)
fprintf('The Laplace Transform of ramp signal\n')
laplace(rmp)
fprintf('The Laplace Transform of parabolic signal\n')
laplace(parb)
fprintf('The Laplace Transform of sine signal\n')
laplace(x)
fprintf('The Laplace Transform of cosine signal\n')
laplace(y)
fprintf('The Laplace Transform of exponential signal\n')
laplace(ex)

Result:
imp =
dirac(t)
stp =
heaviside(t)
rmp =
t
parb =
t^2
x=
sin(2*t)
y=
cos(2*t)
ex =
exp(-3*t)
The Laplace Transform of unit impulse signal
ans =
1
The Laplace Transform of unit step signal
ans =
1/s
The Laplace Transform of ramp signal
ans =
1/s^2
The Laplace Transform of parabolic signal
ans =
2/s^3
The Laplace Transform of sine signal
ans =
2/(s^2 + 4)
The Laplace Transform of cosine signal
ans =
s/(s^2 + 4)
The Laplace Transform of exponential signal
ans =
1/(s + 3)

LAB # 09
Z-Transform In MATLAB
Z-Transform:
Laplace Transform is equivalent to Z-transform.
Z-Transform is the general case of DTFT.
DTFT Convert continuous time signal to frequency domain representation.
Z-transform has ‘z’ which is also complex variable.

MATLAB Code:
clear all
clc
syms n w a b c d e f g h
fprintf('Z-Transform of unit impulse signal is\n')
a=ztrans(kroneckerDelta(n))
fprintf('Z-Transform of shifted unit impulse signal is\n')
b=ztrans(kroneckerDelta(n-1))
fprintf('Z-Transform of unit step signal is\n')
c=ztrans(heaviside(n))
fprintf('Z-Transform of cosine signal is\n')
d=ztrans(cos(w*n))
fprintf('Z-Transform of sine signal is\n')
e=ztrans(sin(w*n))
fprintf('Z-Transform of n signal is\n')
f=ztrans(n)
fprintf('Z-Transform of n^2 signal is\n')
g=ztrans(n^2)
fprintf('Z-Transform of 2^n*u[n] signal is\n')
h=ztrans((2^n)*heaviside(n))

Result:

Z-Transform of unit impulse signal is


a=
1
Z-Transform of shifted unit impulse signal is
b=
1/z
Z-Transform of unit step signal is
c=
1/(z - 1) + 1/2
Z-Transform of cosine signal is
d=
(z*(z - cos(w)))/(z^2 - 2*cos(w)*z + 1)
Z-Transform of sine signal is
e=
(z*sin(w))/(z^2 - 2*cos(w)*z + 1)
Z-Transform of n signal is
f=
z/(z - 1)^2
Z-Transform of n^2 signal is
g=
(z*(z + 1))/(z - 1)^3
Z-Transform of 2^n*u[n] signal is
h=
2/(z - 2) + 1/2

Lab # 10
To Find Step And Impulse Response Of A System In MATLAB
MATLAB Code:
clear all
clc
num=[2 2]
den=[1 11 30]
c=tf(num,den) %transfer function calculated from num and den
figure(1)
step(c) %step response of transfer function c
title('The Step Response')
figure(2)
impulse(c) %impulse response of transfer function c
title('The Impulse Response')
figure(3)
pzmap(c) %poles and zeros plot of transfer function c
title('The Poles Zeros Plot')

Results:
Lab # 11
Introduction To Simulink In MATLAB
MATLAB and Simulink are two different pieces of software with radically different
approaches to modelling of signals and system. MATLAB is an imperative programming
language, whereas Simulink is a block diagram language. Simulink is use d for a variety of
purpose, but mainly for the simulation of real time systems. The function of Simulink is very
similar to that of electronic work bench or circuit designer.
How to Launch Simulink:
The Simulink can be launched by typing ‘Simulink’ in the MATLAB command window. When
we do so, a window pops up

In the Simulink library browser shown in above figure is a list of toolboxes on the left and a list of
components on the right. Whenever a particular toolbox is selected the list of components in
that toolbox appears on the righthand side.

Using Simulink:
To create a simulation in Simulink, a new file is created first. In this file, objects from the Simulink
library browser are inserted. If we are not sure in which tool box the object would lie, we can use
the search command. After the object has been found right click on the object and select insert.
The object is automatically inserted in the simulation file.

Making Simulations:
To make a simulation, add the components in a Simulink file, and then make the connections
required by dragging the connectors of different blocks. Once the connections are made, save
the file and then click the play button at the top of the win

Results:
It is the plots of original sine signal and amplified sine signal by factor of 4.

Lab # 12
To Solve Differential Equations In Matlab Simulink
Differential Equation:
Y’’-5Y+6=0

Circuit Diagram:

Results:
Lab # 13
To Find Step And Impulse Response In MATLAB Simulink
Step response:
Circuit Diagram:

Result:

Impulse response:
Circuit Diagram:

Result:
Lab # 14
Introduction To GUI

What is GUI:
 Graphical user interface.
 Facilitates the end user of the program.
How to open:
 Type guide in command window.
 Choose blank GUI(default).
Multiply Two Numbers in GUI:
 Open GUI.
 Drag and Drop.
 Two Edit text components(For numbers to be Multiplied).
 One static Text component(For displaying Result).
 One pushbutton(For executing).

Get and Set Function:


Get function means get graphs object properties
Get(h, ‘property name’) returns the value of the property ‘Property name’ of the graphics
identified by h
Set function sets graphics object properties
Set(h, ‘property name’ , ‘property value’)

Multiply Two Numbers in GUI:


Multiply Two Numbers in GUI:

Multiply Two Numbers in GUI:

Lab Report:15
USING “fvtool” in MATLAB
Using fvtool to Determine:
 Magnitude Response.
 Phase Response.
 Pole-zero plot.
 Impulse Response.
 Step Response.

FV Tool:
FV Tool is a filter Visualization Tool.
It is a Graphical User Interface (GUI) that allows you to analyze digital filters .
fvtool (num ,den) launches the filter visualization Tool and compute the magnitude
Response for the filter defined by numerator and denominator coefficients in vectors num
and den.
MATLAB code:

Result:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy