%   Problem 6.4
%   The waveforms in problem 6.1 are reconstructed
%   using a square characteristic pulse.
N=input('N= ')
M=input('M= ')
A=input('A= ')
phi=input('phi= ')
n=1:N;
v=A*cos(M*2*pi*n/N+phi);
Vr=zeros(N*10);
for n=1:N
   for k=1:20
      Vr(k+10*(n-1))=Vr(k+10*(n-1))+v(n)*p2(k);
   end
end

%   Ignoring the first 10 points
As=num2str(A);
As = ['A = ' As];
Ns = ['N = ' num2str(N)];
Ms = ['M = ' num2str(M)];
phis=['phi = ' num2str(phi)];

plot(10:length(Vr),Vr(10:length(Vr))),legend(As,Ns,Ms,phis)

   
