signal and system basic matlab programs
TRANSCRIPT
-
7/29/2019 signal and system basic MATLAB Programs
1/16
Assignment # 1
-
7/29/2019 signal and system basic MATLAB Programs
2/16
Part A: Plotting Original Signal
t1= -5 : 5
x=[0,0,0,0,1,0,1,1,1,1,1]
plot(t1,x)
-5 -4 -3 -2 -1 0 1 2 3 4 5-1
-0.5
0
0.5
1
1.5
2
time
x(t)
Question 1 Part (a) Original Signal
-
7/29/2019 signal and system basic MATLAB Programs
3/16
Part b: Even Part of a Signal
t2=-fliplr(t1);
x1=[0 0 0 0 1 0 1 1 1 1 1];x2=fliplr(x1);
x= x1+x2;
y=0.5*x;
plot(t2,y)
-5 -4 -3 -2 -1 0 1 2 3 4-1
-0.5
0
0.5
1
1.5
2Question 1 Part (b) Even Part of a Signal
time
x(t)
-
7/29/2019 signal and system basic MATLAB Programs
4/16
Part (c): Odd Part of a signal
clc
t2=-fliplr(t1);
x1=[0 0 0 0 1 0 1 1 1 1 1];
x2=fliplr(x1);x= x1-x2;
y=0.5*x;
plot(t2,y)
-5 -4 -3 -2 -1 0 1 2 3 4 5-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
time
x(t)
Question 1 Part (c) Odd Part of a signal
-
7/29/2019 signal and system basic MATLAB Programs
5/16
PART (a):
t1=-5:0.1:-4;
x1=zeros(1,11);
t2=-4:0.1:-3;
x2=ones(1,11);
t3=-3:0.1:-1;
x3=2*ones(1,21);
t4=-1:0.1:1;x4=3*ones(1,21);
x=[x1 x2 x3 x4];
t=[t1 t2 t3 t4];
negx=fliplr(x);
negt=-fliplr(t);
fx=[x negx];
ft=[t negt];
plot(ft,fx)
-5 -4 -3 -2 -1 0 1 2 3 4 50
0.5
1
1.5
2
2.5
3
3.5
4Question 2 Part (a)
time
x(t)
-
7/29/2019 signal and system basic MATLAB Programs
6/16
PART (b):
t=-[1,0];
xt=[0,-1];
t1=[0,1];
xt1=[0,1];
t2=[1,2];
xt2=[1,1];
t3=[2,3];
xt3=[1,0];
x=[xt xt1 xt2 xt3];
t=[t t1 t2 t3];
plot (t,x)
-2 -1 0 1 2 3 4-1.5
-1
-0.5
0
0.5
1
1.5Question 2 Part (b)
time
x(t)
-
7/29/2019 signal and system basic MATLAB Programs
7/16
PART (c):
t0=[-3 -2];
t1=[-2,-1];
t2=[-1,0];t3=[0,1];
t4=[1,2];
t5=[2,3];
x0=[0,0];
x1=[1,1];
x2=[-1,-1];
x3=[-1,0];
x4=[1,1];
x5=[0,0];
x=[x0 x1 x2 x3 x4 x5];
t=[t0 t1 t2 t3 t4 t5];
plot (t,x)
-4 -3 -2 -1 0 1 2 3 4-1.5
-1
-0.5
0
0.5
1
1.5Question 2 Part(c)
time
x(t)
-
7/29/2019 signal and system basic MATLAB Programs
8/16
PART (a):
A=5Vp-p, F= 20Hz, T =
=
= 50ms.
Since Duty cycle is 0.6, which means that 60% of the time, signal remains positive and
remaining 40% the signal will be negative. In our case, the signal will be positive for
30msec and negative for 20msec.
MATLAB Code:
t1=-110:0.1:-100;t2=-100:0.1:-70;t3=-70:0.1:-50;t4=-50:0.1:-20;t5=-20:0.1:0;t6=0:0.1:30;t7=30:0.1:50;t8=50:0.1:70;t9=70:0.1:100;t10=100:0.1:110;x1=zeros(1,101);x2=5*ones(1,301);
x3=-5*ones(1,201);x4=5*ones(1,301);x5=-5*ones(1,201);x6=5*ones(1,301);x7=-5*ones(1,201);x8=5*ones(1,301);x9=-5*ones(1,201);x10=zeros(1,101);t=[t1 t2 t3 t4 t5 t6 t7 t8 t9 t10];y=[x1 x2 x3 x4 x5 x6 x7 x8 x9 x10];plot (t,y)
Note: I have calculated the size of x1 to x10 by getting the size of t1 to t10 respectively
by whos command at command window, the above code is written in M-File. Below is
the respective plot.
-
7/29/2019 signal and system basic MATLAB Programs
9/16
-100
-80
-60
-
40
-20
0
20
40
60
80
100
-6 -4 -2 0 2 4 6
Question3part(a)20HzSquarewa
veof0.6DutyCycle
time
x(t)
-
7/29/2019 signal and system basic MATLAB Programs
10/16
PART (b):
A=5Vp-p,
MATLAB Code:
clct=[-100 -100 -75 -50 -50 -25 0 0 25 50 50 75 100 100];x=[ 0 -5 0 5 -5 0 5 -5 0 5 -5 0 5 0];plot (t,x)
-100 -80 -60 -40 -20 0 20 40 60 80 100-6
-4
-2
0
2
4
6Question 3 Part(b) Sawtooth Wave of 20Hz
time
x(t)
-
7/29/2019 signal and system basic MATLAB Programs
11/16
PART (a):
clc
y=0;for t=-15:0.1:15;
for n=-2:0.1:2;y=y+exp(-(t-3*n)^t);endplot(t,y)
end
As seen from the plotthe plot has no point in this time range, and as we cannot plot
the whole graph, by this small time range it is clear that the given signal is not periodic.
14 14.2 14.4 14.6 14.8 15 15.2 15.4 15.6 15.8 160
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1Question 4 Part (a)
time
x(t)
-
7/29/2019 signal and system basic MATLAB Programs
12/16
PART (b):
clcsyms tfor n=-5:0.1:5;x=exp(-2*t)*exp(n)*heaviside(2*t-n);endezplot(x
It is clear from the graph that the signal is not periodic, because the constant
exponential signal is multiplying with the original signal
2.5 3 3.5 4 4.5 5
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
(5221823812744079 heaviside(t - 5/2))/(35184372088832 exp(2 t))
t
x(t)
-
7/29/2019 signal and system basic MATLAB Programs
13/16
PART (a): Plotting Original Signal
xt=[0 1 1 2 2 -1 0];t= [-1 0 1 1 2 2 3];plot(t,xt)
PART (a): Shifting Signal i.e. x(t+2)
st=(t-2)
plot(st,xt)
-1 -0.5 0 0.5 1 1.5 2 2.5 3-1.5
-1
-0.5
0
0.5
1
1.5
2
2.5Question 5 Part (a) Original Signal x(t)
time
x(t)
-3 -2.5 -2 -1.5 -1 -0.5 0 0.5 1-1.5
-1
-0.5
0
0.5
1
1.5
2
2.5Question 5 Part (b) Shifted Signal x(t+2)
time
x(t)
-
7/29/2019 signal and system basic MATLAB Programs
14/16
PART (c): Scaling Signal i.e. x(t/3+2)
sct=st*3;
plot(sct,xt)
PART (d): Flipping the Signal i.e. x(2-t/3)
ft=-fliplr(sct);
fxt=fliplr(xt);
plot(ft,fxt)
PART (a):
-10 -8 -6 -4 -2 0 2 4-1.5
-1
-0.5
0
0.5
1
1.5
2
2.5Question 5 Part (c) Scaled Signal x(t/3+2)
time
x(t)
-4 -2 0 2 4 6 8 10-1.5
-1
-0.5
0
0.5
1
1.5
2
2.5Question 5 Part (d) Flipped signal x(2-t/3)
time
x(t)
-
7/29/2019 signal and system basic MATLAB Programs
15/16
MATLAB Code:
clear allclcsyms tsyms Tyt=exp(-2*t);magnitude = [abs(yt)]^2;energy= int(magnitude,0,inf)p= int(magnitude,-T,T)
power=limit((1/(2*T))*energy,T,inf)
Output in Command Window:
energy = 1/4
p = sinh(4*T)/2
power = 0
-
7/29/2019 signal and system basic MATLAB Programs
16/16
PART (b):
MATLAB Code:
clear allclcsyms tsyms T
yt=1/2*cos(4*pi*t);magnitude = [(yt)]^2;energy = int(magnitude,-inf,inf)p= int(magnitude,-T,T)power = limit(1/(2*T) * p, T,inf)
Output in Command Window:
energy = Inf
p = T/4 + sin(8*pi*T)/(32*pi)
power = 1/8