function [epoch, std, delay, rate] = fit_one_day(time, data)
% function [epoch, std, delay, rate] = fitday(time, data)
% Solves for RMS error, delay and rate at mid epoch
% by kaj.wiik@hut.fi (4 Mar 1996)

starttime = min(time);
endtime = max(time);

time = time - starttime; % 		Normalise time (start = 0)
p = polyfit(time, data, 1); % 		Least squares fit to a line
epoch = mean(time) + starttime;
std = sqrt(mean((polyval(p, time) - data).^2));
delay = polyval(p, mean(time));
rate = p(1);
