This is my first post on math.stackexchange (sorry if meta people remove the Hello (sometimes we do that over on stackoverflow ;P)!
I have a system wherein I know that the output is a sine wave, with a known frequency. My objective is to find the approximate (x,y) of the first peak (i.e., find the phase shift of the signal). An important point is that I do not need to know y, or the amplitude, of this peak. Essentially, I can poll the system at a given angular shift (represented by x), and receive a y value in return. I start with zero points, and want to poll the minimum number of x points in order to be able to know where to poll to receive a max y value.
I believe that I can describe the sine wave with only two points, yet I do not know how to calculate this (it's on a motion controller, so I have quite limited functionality). My thoughts so far: phase = -sin^-1(y) – wt + 2*pi*n, but I don't know how to easily fit this with two points.
Once I know the fitted sine wave, I will be able to determine which x should yield a max amplitude peak y, and then subsequently poll the x location.
If this can be done, the final solution would account for noise in the system (i.e. each y point polled will be within a given tolerance… thus, the two or more points polled to fit the sine wave would cause additive errors…), but I'll cross that bridge when I come to it.
Thanks! I think it's a pretty interesting problem 🙂 Let me know if you need any further clarification!
-Kadaj
Best Answer
Given the general equation $f(t) = Y \sin (\omega t + \varphi)$ where $\omega$ is known and two points, $y_1 = f(t_1)$ and $y_2=f(t_2)$ the solution is
$$ Y = \frac{ \sqrt{ y_1^2 + y_2^2 - 2 y_1 y_2 \cos (\omega(t_2-t_1))}}{\sin ( \omega(t_2-t_1))} $$
$$ \varphi = 2\pi - \tan^{-1} \left( \frac{y_2 \sin \omega t_1 - y_1 \sin \omega t_2}{y_2 \cos \omega t_1 - y_1 \cos \omega t_2} \right) $$
Why?
I expanded the sine function into two components
$$ f(t) = A \sin \omega t + B \cos \omega t $$
where $Y=\sqrt{A^2+B^2}$ and $\tan(\varphi) = \frac{B}{A}$. The two points are
$$ y_1 = A \sin \omega t_1 + B \cos \omega t_1 $$ $$ y_2 = A \sin \omega t_2 + B \cos \omega t_2 $$
or in matrix form
$$ \begin{bmatrix} y_1 \\ y_2 \end{bmatrix} = \begin{pmatrix} \sin \omega t_1 & \cos \omega t_1 \\ \sin \omega t_2 & \cos \omega t_2 \end{pmatrix} \begin{bmatrix} A \\ B \end{bmatrix} $$
with the inverse
$$\begin{pmatrix} \sin \omega t_1 & \cos \omega t_1 \\ \sin \omega t_2 & \cos \omega t_2 \end{pmatrix}^{-1} = \frac{1}{\sin( \omega (t_2-t_1))} \begin{pmatrix} \mbox{-}\cos \omega t_2 & \cos \omega t_1 \\ \sin \omega t_2 & \mbox{-}\sin \omega t_1 \end{pmatrix}$$
or
$$ \begin{bmatrix} A \\ B \end{bmatrix} = \frac{1}{\sin( \omega (t_2-t_1))} \begin{bmatrix} y_2 \cos \omega t_1 - y_1 \cos \omega t_2 \\ y_1 \sin \omega t_2 - y_2 \sin \omega t_1 \end{bmatrix} $$
So
$$ Y = \sqrt{A^2+B^2} = \sqrt{ \left( \frac{y_2 \cos \omega t_1 - y_1 \cos \omega t_2}{\sin( \omega (t_2-t_1))} \right)^2 + \left( \frac{y_1 \sin \omega t_2 - y_2 \sin \omega t_1}{\sin( \omega (t_2-t_1))} \right)^2 } $$
and
$$ \varphi = n \pi + \tan^{-1}\left( \frac{B}{A} \right) = n \pi + \tan^{-1}\left( \frac{y_1 \sin \omega t_2 - y_2 \sin \omega t_1}{y_2 \cos \omega t_1 - y_1 \cos \omega t_2} \right) $$