%% Line spectrum of Fourier series coefficients
%% by B. Boulet, 2005
% signal amplitude and period
A=1;
T=1;
% number of harmonics
N=10;
%First compute the ak's
a0=0;
spectrum=zeros(1,2*N+1);
for k=-N:N
% spectral coefficients of sawtooth signal
   if k>0
      eval(['a' num2str(k) '=-j*A/(k*pi)'])
      eval(['spectrum(k+N+1)=a' num2str(k)]);    
   elseif k<0
      eval(['a_' num2str(abs(k)) '=-j*A/(k*pi)'])      
      eval(['spectrum(k+N+1)=a_' num2str(abs(k))]);
   end
eval(['spectrum(N+1)=a0']);
end
% Line spectrum
K=[-N:N];
subplot(211)
stem(K,abs(spectrum),'.-')
subplot(212)
stem(K,phase(spectrum),'.-')
