function [a,b,f,t1]=myfft(time, data);
%myfft.m
%
% [a,b,f,t1]=myfft(time, data);
%with provided time and data vectors the function returns a, b, f and t1.
%a and b are the coefficients for the Fourier series, while f is the 
%frequencies. t1 is the t(1) value that need to be substracted from all different 
%times in Fourier series.
%this function assumes that the time vector  has equal gaps between its
%elements
if (length(time) ~= length(data))
	error('size of time and data vectors  mismatched');
end;
if (length(time) == 0);
	error('input is too short');
end;

n=length(data);
if(mod(n,2)~=0)%make sure we have even number of data
	data(end)=[];%delete last one.
end
y=fft(data);
N=length(y);
a = real( [y(1); 2*y(2:N/2+1) ] )/N;
b = [0; imag( y(2:N/2+1) ) ]*-2/N;
n = length(a);
dt = time(2) - time(1);
t1 = time(1);
f = 1/(N*dt)*[0:n-1];


