# Describe a sine wave of known frequency with only two points

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!

-
Is there a DC offset to the signal or is it purely $f(t)=Y \sin (\omega t + \varphi)$ ? – ja72 May 6 '13 at 23:21
@ja72, I don't think there's $\omega$ since the frequency is known. – vadim123 May 6 '13 at 23:24
Ah, good point ja72. I am looking for a solution in which there can be a DC offset. – Kadaj Nakamura May 6 '13 at 23:24
@vadim123, yes, I suppose my notation isn't the best >_<;; So, in a system in which I did not know $\omega$, I think I would require at least 3 points. Since I know $\omega$, I believe it can be done in 2, I just cannot seem to arrive at a solution :'( – Kadaj Nakamura May 6 '13 at 23:26
@KadajNakamura - frequency is $f=\frac{\omega}{2 \pi}$. So $\omega$ is just frequency in rad/s. – ja72 May 7 '13 at 0:15

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)$$

-
This definitely looks promising! Thank you, @ja72 (especially considering how quickly you replied)! Have to run now, but will try it out later today/tomorrow =) Tried to bump it, but I don't have enough rep on here yet T^T – Kadaj Nakamura May 6 '13 at 23:59
Oh, I have a quick question -- can you point me in the right direction for this derivation? Is there a name for this type of problem or field that I can read up on it more? – Kadaj Nakamura May 7 '13 at 2:22
I used a 2x2 system to fit the function into the data points. Essentially this is a least squares fit, but with zero error. See edited reply for details. – ja72 May 7 '13 at 18:56
Awesome !! Thank you! – Kadaj Nakamura May 8 '13 at 2:59
Shouldn't the matrix inversion line read to the right of the determinate? --> \begin{pmatrix} \cos \omega t_2 & \mbox{-}\cos \omega t_1 \\ \mbox{-}\sin \omega t_2 & \sin \omega t_1 \end{pmatrix} – Kadaj Nakamura May 8 '13 at 3:28

According to the Nyquist limit, two samples are not enough to have it, considering that your signal is just a period of a sinus, corresponding to a sinc in frequency.

Imaging the two points are just the two zeros of your sinusoidal signal, how can you recover anything from that?

A good question would be how many points are then needed. I guess three, but does not have demonstration.

This is for total recovery of the signal. For just phase, two points are right.

-
Welcome to our site! – kjetil b halvorsen Jan 20 '15 at 10:32