clear
close ALL
format long e
T0 = 0.2;
x = 0.5;
T = x*T0;
tt = -0.1:0.001:0.1;
NN=100;
%NN=20;
nn = 1:NN;
for n=nn
 C(n) = x*sin(pi*n*x)/(pi*n*x);
 n=n+1;
end
m=1;
for t = tt 
 gpt = 2*C.* cos(2*pi*nn*t/T0);
 gptt(m) = sum(gpt) + 0.5;
 if(abs(t) < 0.25*T0)
     sq(m) = 1.0;
 else
     sq(m) = 0.0;
 end
 m=m+1;
end
Hp1 = plot(tt, gptt,'b');
hold on
Hp1 = plot(tt, sq,'k:');
set(Hp1,'LineWidth',2)
Ha = gca;
set(Ha,'Fontsize',16)
%Hx=xlabel('n');
%set(Hx,'FontWeight','bold','Fontsize',16)
Hx=ylabel('Amplitude');
set(Hx,'FontWeight','bold','Fontsize',16)
Hx=xlabel('Time (sec)');
set(Hx,'FontWeight','bold','Fontsize',16)
title('Partial sum for square wave','FontWeight','bold','Fontsize',16)

