%fftamps.m ,m-file function to find and plot the fourier amplitudes of the
%input waveform. Also calculates the variance. See main program series.m

  function [Ampl,Ay,Gy] = fftamps(y,dt,f1)

fn=1/(2*dt);
N=length(y);
Nf=N/2 + 1;
freq=fn * (0:(Nf-1)) / (Nf-1);
Y=fft(y);
Ay=conj(Y)/N;
Gy= 2 * abs(Ay).^2/f1;    % this is the spectral density - to find variance
Ay = Ay * 2;              % one-sided spectrum
Ampl(1)=.5*real(Ay(1));   % mean value will be stored in first Ampl 
Ampl(2:Nf)=abs(Ay(2:Nf)); % Amplitudes up to the Nyquist frequency

Ay(Nf+1:N)=[];            % Now that we have the single sided spectrum
%Ampl(Nf+1:N)=[];          % discard frequencies above the Nyquist freq.
Gy(Nf+1:N)=[];


