%   Problem 6.5
%   Here the waveforms are reconstructed using a 
%   triangular characteristic pulse p(k), where k 
%   is an index from 1 to 20, representing time.
%
%   The function p(k) is in file p.m
%
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)*p(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)

   
