load harmonic_regression.mat

A = [sin(x) cos(x)];
L = -y;

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

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

V = A*X + L;
A'*V
sum(V'*V)

hold on
plot (x,y,'*');
grid on
plot(x, Amp * sin(x+phi),"-","linewidth",5)
hold off
print -djpg fig_harmonic.jpg
pause

