%
%sum a bunch of cosines to approximate an impulse
%
%clear any old variables
clear all
close all

%total length of time series in seconds
N=10;

%time step size in seconds
dt=0.02;

%length of vectors to create
M=N/dt;

%zero time reference point
ztime=M/2;

% time vector and impulse
t = ((1:M)-ztime)*dt;

% number of additional frequencies per plot
Nf = 4;
% number of plots
Np = 4;

myfig = figure;
set(myfig,'Position',[100 100 800 1000])
for j=1:Np,
  ncosine=0;
  imp=zeros(size(t));
  subplot(Np,1,j)
  hold on
  for i=1:Nf*j,
    d=cos(2*pi*t*i/N);
    plot(t,d,'r')
    imp=imp+d;
    ncosine=ncosine+1;
  end
  plot(t,imp,'b','LineWidth',2);
  title(['\fontsize{18}',num2str(ncosine),' summed cosines'])
  %xlabel(['\fontsize{16}','seconds'])
  xlabel('seconds','FontSize',16)
  xt=get(gca,'XTickLabel');
  set(gca,'FontSize',18)
  disp('press enter to continue');
  disp(' ')
  pause;
end
hold off

%orient tall
%print -dps sumcosine.ps
