clear all;
close all;
N1 = 100;
N2 = 400;
N = N1+N2;
E = eye(N);
j = sqrt(-1);
w0 = 2*pi/N1;
s = [cos(5.0*1*w0*(0:N1-1)) zeros(1,N2)];
%create the basis set pf normalized orthogonal basis vectors
% the norm of exp(j*w0*k*(0:N-1)) is 1/sqrt(N)
for k=0:N-1
    B(:,k+1) = 1/sqrt(N)*exp(j*2*pi/N*k*(0:N-1));
end;
figure
subplot(2,1,1)
plot(s,'o');
%compute decomposition coefficients
c = B'*s(:);
omega = (2*pi/N)*(0:N-1);
subplot(2,1,2);
plot(omega, abs(c),'r-s')
hold on;
plot(omega,abs(fft(s))/sqrt(N),'m-.');
sh = B*c;
subplot(2,1,1);
hold on;
plot(real(sh),'r.'); % use real part to exclude numerical error
% and not ashow the small values in the imag part
%We can also verify Parseval's relation
s(:)'*s(:)
c(:)'*c(:)

