Unit step function - Explain this 10 line code?

1 Ansicht (letzte 30 Tage)
deltanabla
deltanabla am 20 Jan. 2015
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

Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by