function [t,ts]=myifft(f, pow,phase);

%computes a time series from a frequency and power distribution

%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=(((.5*pow(1))^.5))*ones(1,length(t));
for n=2:NF-1;
    ts=ts+((2*pow(n))^.5)*cos(2*pi*f(n)*t+phase(n)); %add in each component in the time domain
end
ts=ts+(pow(NF)^.5)*cos(2*pi*f(NF)*t+phase(NF)); %adjust for the nyquist frequency, the phase should automatically be zero for this component

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

%seems to work 1/02/08 AD






