Reputation: 7359
I'm just trying to program a function for a discrete-time unit step from say, -10 to 10, so that I can perform other operations on it to test some things such as u[n-1], u[2n], u[-n], etc. I haven't used Matlab in quite a while and can't seem to get it working. Or is it easier to use WolframAlpha for this? Would someone show me how to do this with either way please?
Upvotes: 0
Views: 149
Reputation: 1389
t=-10:10;
stepFCT=zeros(1,length(t));
%%%%%%u[n-1]%%%%%%
for i=1:length(t);
if t(i)-1>=0
stepFCT(i)=1;
else
end
end
figure(1)
stem(t,stepFCT)
%%%%%%u[2n]%%%%%%
stepFCT=zeros(1,length(t));
for i=1:length(t);
if 2*t(i)>=0
stepFCT(i)=1;
else
end
end
figure(2)
stem(t,stepFCT)
%%%%%%u[-n]%%%%%%
stepFCT=zeros(1,length(t));
for i=1:length(t);
if -t(i)>=0
stepFCT(i)=1;
else
end
end
figure(3)
stem(t,stepFCT)
Please try these codes.
Upvotes: 1