[Math] Fitting a sine function to data

numerical methodsregressiontrigonometry

I have a sequence of $n$ points $(x_i,y_i)$, for $i=1,\dots,n$. I would like to find the function, of the form $y=V\sin(x+\phi)$, which best fits the points. Which numerical method could I use? I have a slow system, with little memory, so I am searching for a fast and efficent method, even if not very accurate.

I have tried with gradient descent, but it is slow.

Best Answer

Here is a very simple-minded way.

First, set $V = \max(|y_i|)$.

Then, let $\phi_i =\arcsin(y_i/V)-x_i $.

Finally, $\phi =\frac1{n}\sum \phi_i $.

Note: If the data is over multiple sinusodial cycles, adjust $\phi_{i+1}$ so it differs from $\phi_i$ by less than $\pi$.

Related Question