function [t,ts]=myifft_coef(f, A,B);

%computes a time series from frequency vector and corresponding Sine and
%Cosine Coefficients

%%INPUTS

%f = vector of frequencies, may be generated by myfft_coef

%A =Cosine coefficients for corresponding frequencies, assumes the time
%        series starts at time 0

%B =Sine coefficients for corresponding frequencies, assumes the time
%        series starts at time 0


%first, find the time vector corrsponding to the frequency vector
NF=length(f);
delf=f(2:NF)-f(1:NF-1);
if (delf==(mean(delf))) == 0;
    error('input frequency vector mus be evenly spaced')
end

ny=max(f); %the nyquist frequncy;
delt=1/(2*ny); %time step
fund=1/f(2); %fundamental period;

t=0:delt:fund-delt;

ts=A(1)*ones(1,length(t));
for n=2:NF;
    ts=ts+(A(n))*cos(2*pi*f(n)*t)+B(n)*sin(2*pi*f(n)*t); %add in each component in the time domain
end


figure(11); clf;
plot(t,ts);
title('TIME SERIES FROM INVERSE FOURIER TRANSFORM', 'FontSize', 18)

%seems to work 1/08/08 AD






