# 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})$.

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

To find $c$:

\begin{aligned} f(0) + f(\pi) &= 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 b + a^2\cos^2 b= a^2 \\ \implies a &= \sqrt{(f(0) - c)^2 + (f(\tfrac{\pi}{2}) - c)^2} \end{aligned}

And finding $b$:

\begin{aligned} \frac{f(0) - c}{f(\tfrac{\pi}{2}) - c} &= \frac{a\sin b}{a\cos b} = \tan^{-1} b \\ \implies b &= \operatorname{atan2}\left(f(0) - c, f(\tfrac{\pi}{2}) - c\right) \end{aligned}

-