function fit = LSF(time, data)
% Simple LSF to model the diel cycles. Assumes 1 cycle per day (P1).
% Data is y values to model (DIC, O2). Time is time vector as a datetime
% value.
P1 = length(time)/numel(unique(day(time))); 
% If there is a diel cycle, three days should have three cycles so 
% dominant period (P1) is n_samples/#days
time = (1:1:length(time))'; % create evenly spaced time vector
A2 = [ones(length(time)) sin((2*pi*time)/P1) cos((2*pi*time)/P1)];
% 2*pi/P1 because one cycle completed every period
x2 = A2\data; % LSF
% B = x2(1);
% A = sqrt(sum(x2(2:end).^2));

fit = A2*x2;
end