Unit step function - Explain this 10 line code?

조회 수: 1 (최근 30일)
deltanabla
deltanabla 2015년 1월 20일
i Folks,
I have difficulty understanding what is happening with this code. It is meant to simulate the unit step function
(t-a)=1 for t>a and (t-a)=0 for t<a
The resulting output is vector of 0's and 1's when its inside another function. However, when I extract the function for simplicity to show here, it just calculates a bunch of 1's. In either case, i dont understand the 3rd last line...
function y = h(t)
t = linspace(0,36*pi,2^15)';
y = zeros(size(t));
for k = 1:length(t)
if t(k)>0
y(k) = 1;
else
y(k) = 0;
end
end
function y = U(t,i,N,Tc)
y = 0;
N=1;
Tc=6.28;
for i=1:N
for n=1:100
y = y + h(t-(((n-1)*N+i-1)/N)*Tc) - h(t-(((n-1)*N+i)/N)*Tc);
end
end
Thanks

답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by