load harmonic_regression.mat

A = [sin(x) cos(x) ones(size(x,1),1)];
L = -y;

X = -inv(A'*A)*(A'*L)

Amp = sqrt(sum(X(1:2).^2))
phi = atan2(X(2),X(1))

% V = A*X + L;
% hold on
% plot (x,y,'*');
% grid on
% plot(x, Amp * sin(x+phi) + X(3),"-","linewidth",5)
% hold off
% print -djpg fig_harmonic.jpg
% pause

