Is there any way to find the parameters of a sine wave ($A$, $w$, and $ \phi $ for $A \sin(wt+\phi)$ ) using just three points (samples)?
Thank you in advance for your help.
Is there any way to find the parameters of a sine wave ($A$, $w$, and $ \phi $ for $A \sin(wt+\phi)$ ) using just three points (samples)?
Thank you in advance for your help.
Sort of. The problem is this:
Suppose you tell me that
$$ f(0) = 0\\ f(\pi) = 0\\ f(2\pi) = 0\\ $$
That's 3 data points, right? One answer is that $f(x) = \sin(x)$, but another, equally good answer, is that $f(x) = \sin(2x)$. The problem is that these two functions happen to take on the same values at the same points, so from the point of view of just this small sample, they "look the same". This is called "Aliasing".
If you're willing to say that you want to find the solution with $w$ as small as possible, then there's some hope for you. But in general the problem's not solvable.
There's a second problem not addressed even by limiting to the Nyquist frequency: your Fourier series doesn't have enough terms. Suppose that your three values are $y_1 = y_2 = y_3 = 4$. What band-limited function fits these? Answer: $4 \cos(0 t)$. You need that constant term, or the problem's still unsolvable.
I'm now going to talk about how I'd solve the problem, assuming that the values of $f$ are given at the points $t_1 = 0$, $t_2 = 1$, and $t_3 = 2$ and that the constant term in the Fourier series is zero.
If your arguments for the known points are at the equispaced points $s_1, s_2, s_3$, then you can take the solution $f$ that I find and transform it by $g(s) = f( \frac{s - s_1}{s_2 - s_1})$, which will alter the values of $\omega$ and $\phi$, but not $A$.
Let's suppose that the known values are $y_1, y_2,$ and $y_3$. So we want to have $$ A\sin(\omega \cdot 0 + \phi) = y_1 \\ A\sin(\omega \cdot 1 + \phi) = y_2 \\ A\sin(\omega \cdot 2 + \phi) = y_3, $$ right? Let's rewrite that slightly:
$$ A\sin(\phi) = y_1 \\ A\sin(\omega+ \phi) = y_2 \\ A\sin(2\omega + \phi) = y_3. $$ Apply the addition formula for sine to get
$$ A\sin(\phi) = y_1 \\ A\sin(\omega ) \cos(\phi) + A\cos(\omega ) \sin(\phi) = y_2 \\ A\sin(2\omega ) \cos(\phi) + A\cos(2\omega ) \sin(\phi) = y_3. $$ Note that $A\sin(\phi)$ appears in the second term of the last two equations; we can replace it with $y_1$ in these to get
$$ A\sin(\phi) = y_1 \\ A\sin(\omega ) \cos(\phi) + y_1 \cos(\omega ) = y_2 \\ A\sin(2\omega ) \cos(\phi) + y_1 \cos(2\omega ) = y_3. $$
Now apply the double-angle formulas to the third equation to get
$$ A\sin(\phi) = y_1 \\ A\sin(\omega ) \cos(\phi) + y_1 \cos(\omega ) = y_2 \\ 2A\sin(\omega )\cos(\omega) \cos(\phi) + y_1 (2\cos^2(\omega ) - 1) = y_3. $$ Multiply the second equation by $2 \cos(\omega)$ to get
$$ A\sin(\phi) = y_1 \\ 2A\sin(\omega ) \cos(\omega) \cos(\phi) + 2 y_1 \cos^2(\omega ) = 2y_2 \cos(\omega) \\ 2A\sin(\omega )\cos(\omega) \cos(\phi) + y_1 (2\cos^2(\omega ) - 1) = y_3. $$
Subtract the third from the second to get
$$ A\sin(\phi) = y_1 \\ 2 y_1 \cos^2(\omega ) - y_1 (2\cos^2(\omega ) - 1) = 2y_2 \cos(\omega) - y_3. . $$
Now notice that in the last equation, $\phi$ has disappeared, as has $A$. The only remaining variable is $\omega$. Denoting $\cos(\omega)$ by $c$ for a moment, that last equation now reads
$$ 2 y_1 c^2 - 2y_1 c^2 + y_1 = 2y_2 c - y_3. . $$
or
$$ \frac{y_1 + y_3}{2y_2} = \cos(\omega). $$
From this you can determine the cosine of $\omega$, and hence can find $\omega$ (up to sign, which shouldn't surprise you: a solution $(A, \omega, \phi)$ to the original equation leads to an alternative solution $(-A, -\omega, -\phi)$ that works equally well).
[Note: this requires that the quotient $(y_1 + y_3) / (2y_2)$ be between $-1$ and $1$; I suspect that this is a consequence of the "no DC term" assumption, but I might also have made an algebra mistake.]
You then can use $\sin(\omega)$ and the second equation (in its second form) to determine $A \cos(\phi)$. Once you know $A \sin(\phi)$ and $A \cos(\phi)$, you can either determine $\phi$ using the "atan2" function, or you can compute $(A \sin \phi)^2 + (A \cos \phi)^2$, which is just $A^2$, and thus compute $A$, up to sign, and hence compute (from the first equation) $\phi$, up to sign.
This can probably all be expressed more elegantly with complex exponentials, but I figured that in this case I'd go through the algebra instead.