# Fitting a sine wave of known frequency through three points

We have a computationally expensive function of a large set of data and an angle, that is known to result in a sine wave:

$$f(\text{data}, \theta) \approx a \sin (\theta + b) + c$$

We want to find the constants $a$, $b$, and $c$, executing the function as few times as possible.

-
So, what is your question? – user21436 Mar 10 '12 at 12:33
@KannappanSampath: Given a function $f(\theta)$ which is known to give results of the form $a \sin(\theta+b) + c$, where $a$, $b$, and $c$ are unknown constants, how can these constants be found? For example, can these three constants be inferred from the values of $f(0)$, $f(\frac{2\pi}{3})$, and $f(-\frac{2\pi}{3})$? – Eric Mar 10 '12 at 22:54
Do you get to pick the thetas? If not, then there will be cases with no unique solution. E.g., I could give you $f(0)=0$, $f(\pi)=0$, and $f(2\pi)=0$, which has more than one solution in $a$, $b$, and $c$. – Ben Crowell Mar 12 '12 at 22:15

Yes, you can do it in 3 points, considering $f(0)$, $f(\pi)$, and $f(\frac{\pi}{2})$.

To find $c$:

\begin{aligned} f(0) + f(\pi) & = a\sin(0 + b) + a\sin(\pi + b) + 2c \\ & = a\sin b - a\sin b + 2c \\ & = 2c \\ \implies c & = \frac{f(0) + f(\pi)}{2} \end{aligned}

To find $a$:

\begin{aligned} (f(0) - c)^2 + (f(\tfrac{\pi}{2}) - c)^2 & = a^2\sin^2(0 + b) + a^2\sin^2(\tfrac{\pi}{2} + b) \\ & = a^2 \left(\sin^2(0 + b) + \sin^2(\tfrac{\pi}{2} + b)\right)\\ & = a^2 \left(\sin^2 b + \cos^2 b\right) \\ & = a^2 \\ \implies a & = \sqrt{(f(0) - c)^2 + (f(\tfrac{\pi}{2}) - c)^2} \end{aligned}

$b$ is now trivial to find:

\begin{aligned} f(0) &= a\sin b + c \\ \implies f(0) - c &= a\sin b \\ \implies \frac{f(0) - c}{a} &= \sin b \\ \implies b &= \sin^{-1}\frac{f(0) - c}{a} \end{aligned}

-