clear all
u=@(t)(t>=0);
r=@(t)t.*(t>=0);

xt=@(t)u(t+1)-u(t-1);
yt=@(t)r(t+1)-2*r(t)+r(t-1);
zt=@(t)(u(t+1)-u(t-1)).*cos(2*pi/4*t);

t=-50:0.01:50;

subplot(3,2,1)
plot(t,xt(t))
axis([-3 3 -0.3 1.3])
subplot(3,2,3)
plot(t,yt(t))
axis([-3 3 -0.3 1.3])
subplot(3,2,5)
plot(t,zt(t))
axis([-3 3 -0.3 1.3])
w=-20:0.01:20;
xw=[];
yw=[];
zw=[];
for i=w
    int=xt(t).*exp(j*i*t);
xw=[xw trapz(t,int)];
end

for i=w
    int=yt(t).*exp(j*i*t);
yw=[yw trapz(t,int)];
end

for i=w
    int=zt(t).*exp(j*i*t);
zw=[zw trapz(t,int)];
end
subplot(3,2,2)
plot(w,(1/(2*pi)*xw))
subplot(3,2,4)
plot(w,(1/(2*pi)*yw))
subplot(3,2,6)
plot(w,(1/(2*pi)*zw))