Help writing a Unit Step function for a signal!

조회 수: 21 (최근 30일)
dominik landowski
dominik landowski 2016년 10월 2일
댓글: Arthur Sherman 2018년 6월 22일
This is NOT homework but part of a project and no matter how many times I've googled this I just keep getting confused.
I am asked to put this function into MatLab, and then have it plot it. Then delay the signal by two seconds (t-2), and plot that on a separate graph.
I have scanned what is being asked of me into a pic so you can understand this better, my problem is I do not know where to start.

답변 (2개)

KSSV
KSSV 2016년 10월 3일
clc; clear all ;
T = linspace(0,7) ;
V = zeros(size(T)) ;
for i = 1:length(T)
t = T(i) ;
if t<=2
v = exp(-2*t) ;
elseif t>2 && t<=3
v = 10*t-30 ;
elseif t >3 && t <= 5
v = -10*t+50 ;
elseif t > 5 && t <= 7
v = 10*t-70 ;
end
V(i) = v ;
end
plot(T,V)
The above code defines v(t). I hope you should proceed with the other questions.
  댓글 수: 1
dominik landowski
dominik landowski 2016년 10월 3일
Thank you sooo much! I was doing it differently and getting close using t.*(heaviside(t) - heaviside(t-delay)) I could not get it to plot out 100% correct though it was roughly the graph I needed.

댓글을 달려면 로그인하십시오.


Sally Al Khamees
Sally Al Khamees 2017년 2월 21일
If you have R2016b, you can just use the piecewise function:
t= linspace(0,7);
syms y(t)
y(t) = piecewise(t<=2,exp(-2*t),2<t<=3,10*t-30,3<t<=5,-10*t+50, 5<t<=7, 10*t-70);
fplot(y)
xlim([-1,7])
ylim([-20.0 20])
  댓글 수: 1
Arthur Sherman
Arthur Sherman 2018년 6월 22일
piecewise requires the Symbolic Toolbox. - Artie Sherman

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by