# Chaitanya's Random Pages

## February 20, 2013

### Summing two sinusoids where one has double the frequency of the other

Filed under: mathematics — ckrao @ 11:10 am

In this post we look at the sum two sinusoids of different amplitude and phase but where one has twice the frequency of the other. How should we choose the phase so that the sum has minimal peak?

Mathematically, given a constant $A > 0$ we wish to find

$\displaystyle \min_{\phi} \max_x \sin 2x + A \sin (x + \phi ).$

The sum can take a variety of forms, two of which are shown in red below ($A=2, \phi = 0$ and $A=1, \phi=\pi/3$).

We claim that a value of $\phi$ for which the peak value of $\sin 2x + A \sin (x + \phi )$ is maximised is $\phi = 3 \pi/4$ as illustrated below (again $A = 2$).

We see here the two sinusoids reach their minimum at $x = 3\pi /4$, resulting in a minimum value of $-A -1$ for the sum. However the maximum value is only $1.5$ for the case $A=2$. Hence we make the observation that finding the lowest peak is different from finding the minimum deviation from zero.

I initially approached this problem using the method of Lagrange multipliers. Consider the problem of finding the maximum value of $f(x) = \sin 2x + A \sin (x + \phi )$ where $A$ and $\phi$ are fixed. We write

\begin{aligned} f(x) &= 2 \sin x \cos x + A (\sin x \cos \phi + \cos x \sin \phi )\\ &= 2(uv + ru + sv),\end{aligned}

where $u = \cos x, v = \sin x$ are variables and $r = \frac{A}{2} \cos \phi, s = \frac{A}{2} \sin \phi$ are constants. Hence we wish to maximise $uv + ru + sv$ subject to $u^2 + v^2 = 1$. By the method of Lagrange multipliers, at the maximum the gradient vector of the objective function is parallel to the gradient of the constraint. In other words, $(v + r, u + s) \parallel (u, v)$. Hence there exists a constant $\lambda$ so that

$\displaystyle v + r = \lambda u \ \ \ \ \ (1)$
$\displaystyle u + s = \lambda v \ \ \ \ \ (2)$

Solving these two equations for $u$ and $v$ gives $u = (\lambda r + s)/(\lambda^2 -1)$ and $v = (r + \lambda s)/(\lambda^2 -1)$. Then the condition $u^2 + v^2 = 1$ gives us the quartic equation

$\displaystyle (\lambda r + s)^2 + (r + \lambda s)^2 = (\lambda^2 - 1)^2. \ \ \ \ \ (3)$

By multiplying (1) by $u$ and (2) by $v$ and adding, we obtain

\begin{aligned} 2(uv + ru + sv) &= 2(\lambda - uv)\\ &= 2 \left( \lambda - (\lambda r + s)(r + \lambda s) / (\lambda^2 -1)^2 \right), \end{aligned}

where $\lambda$ is one of the solutions of (3).

Unfortunately only for a few special cases does the solution in $x$ have a “nice” form. So this approach to finding the best $\phi$ was not appealing.

After conjecturing that the best $\phi$ is $3\pi/4$, one alternative approach is to proceed as follows. We firstly note that for $\phi = 3 \pi /4$,

\begin{aligned} \sin 2x + A \sin (x + \phi) &= 2 \sin x \cos x + A \frac{\sqrt{2}}{2} \left(\cos x - \sin x \right)\\ &= 1 - (\cos x - \sin x)^2 + A \frac{\sqrt{2}}{2} \left(\cos x - \sin x \right)\\ &= -(\cos x - \sin x - A \frac{\sqrt{2}}{4})^2 + 1 + \frac{A^2}{8}\\ &\leq \begin{cases} 1 + \frac{A^2}{8} & \text{if } A \leq 4\\ -(-\sqrt{2} - A \frac{\sqrt{2}}{4})^2 + 1 + \frac{A^2}{8} = A-1 & \text{if } A > 4. \end{cases}\end{aligned}

Hence the maximum value is $1 + A^2/8$ or $A - 1$ depending on how large $A$ is.

Now we wish to show that for other values of $\phi$ there exists $x$ for which this maximum value is exceeded. Firstly note that the more interesting case is $A < 4$ since when $A \geq 4$, we can achieve a minmax value of $A-1$ by aligning the peak of $A \sin (x + \phi )$ with the trough of $\sin 2x$ (e.g. for $\phi = 3 \pi/4$), obtaining a sum value of $A - 1$ at $x = -\pi/4$. This is at the local maximum since here,

$f'( -\pi/4) = 2 \cos (-\pi/2) + A \cos (-\pi/4 + 3\pi/4) = 0 +0 = 0$

and

$f''(-\pi /4) = -2 \sin \pi /2 - A \sin (-\pi / 4 + 3\pi /4) = -2 - A < 0$.

From now on we consider $A < 4$.

Choose $x$ such that $\sin (x + \phi) = \frac{A}{4}$ (i.e. $x + \phi$ is kept constant). Then $\cos (x + \phi) = \pm \sqrt{1 - A^2/16}$,

$\sin 2(x + \phi ) = 2 \sin (x + \phi ) \cos (x + \phi ) = \pm \frac{A}{2} \sqrt{1 - A^2/16}$ and

$\cos 2(x + \phi ) = 2 \cos^2 (x + \phi ) - 1 = 2(1 - A^2/16) - 1 = 1 - A^2/8$. Then

\begin{aligned} \sin 2x &= \sin(2(x + \phi ) - 2\phi )\\&= \sin 2(x+\phi ) \cos 2\phi - \cos 2(x + \phi ) \sin 2\phi \\ &= \pm \frac{A}{2} \sqrt{1 - A^2/16} \cos 2\phi - (1 - A^2/8) \sin 2\phi. \end{aligned}

Write this as $g(\phi) = C_1 \cos 2\phi + C_2 \sin 2\phi$, and note that $C_1 \neq 0$. We wish to show if $\sin 2\phi \neq -1$ there exists $\phi$ close to $3\pi/4$ such that $g(\phi ) > -C_2$. We use the fact that near $\phi = 3\pi/4$, $\cos 2\phi = 2(\phi-3\pi/4) + o((\phi-3\pi/4)^2)$ while $\sin 2\phi = -1 + (2(\phi-3\pi/4))^2/2 + o((\phi-3\pi/4)^3)$. In particular for all $\phi$ sufficiently close (but not equal) to $3\pi/4$,

$\displaystyle \left| \cos 2\phi \right| > 2 \epsilon - \frac{(2\epsilon)^3}{3!}$

$\displaystyle \left| 1 + \sin 2\phi \right| < (2 \epsilon^2),$

where $|\phi - 3\pi/4| := \epsilon > 0$. Furthermore choose $\epsilon$ so that $4\epsilon^2 < 3$ (i.e. $(2 \epsilon)^3/6 < \epsilon$) and $\frac{1}{2\epsilon} \geq \left| C_2/C_1 \right|$. We then find

\begin{aligned} \left| \frac{\cos 2\phi}{1 + \sin 2\phi} \right| &> \frac{2\epsilon - (2 \epsilon)^3/3!}{2 \epsilon^2} \\ &> \frac{\epsilon}{2\epsilon^2}\\ &= \frac{1}{2 \epsilon}\\ &\geq \left| \frac{C_2}{C_1} \right|. \end{aligned}

It follows that

$-C_2(1 + \sin 2\phi ) \leq \left| C_2(1 + \sin 2\phi ) \right| < \left| C_1 \cos 2\phi \right| = C_1 \cos 2\phi$,

or $C_2 (1 + \sin 2\phi) + C_1 \cos 2\phi > 0$, where $C_1 \cos 2\phi = \pm \frac{A}{2} \sqrt{1 - A^2/16} \cos 2\phi$ can be chosen to be positive for some $\phi, x$. Hence we have $\sin 2x = C_1 \sin 2\phi + C_2 \cos 2\phi > -C_2$ as desired and

\begin{aligned}\sin 2x + A \sin (x + \phi ) &> -C_2 + \frac{A^2}{4}\\ &= ( 1 - A^2/8) + \frac{A^2}{4} \\ &= 1 + \frac{A^2}{8}. \end{aligned}

Hence we would have an $x$ for which the claimed maximum value of $(1 + A^2/8)$ has been exceeded. We conclude that we must have $\cos 2 \phi = 0$ and $\sin 2\phi = -1$ (e.g. when $\phi = 3\pi/4$), leading to the minmax value of $1 + A^2/8$.

Recapping, we have shown that

$\displaystyle \min_{\phi} \max_x \sin 2x + A \sin (x + \phi ) = \begin{cases} 1 + A^2/8 & \text{ if } A \leq 4\\ A - 1 & \text{ if } A > 4.\end{cases}$

It is interesting to see that the behaviour of the minmax changes from being quadratic to linear in $A$ as $A$ exceeds $4$. For the examples plotted above, $A = 2$, leading to a minmax value of $1 + 2^2/8 = 3/2$ as we found in the third graph.

If we wish to find $\min_{\phi} \max_x A_1 \sin 2x + A_2 \sin (x + \phi )$ where $A_1, A_2 > 0$, we simply write this as $\min_{\phi} \max_x A_1 ( \sin 2x + A \sin (x + \phi )$ where $A = A_2/A_1$ and use the above result to obtain the following:

$\displaystyle \min_{\phi} \max_x A_1 \sin 2x + A_2 \sin (x + \phi ) = \begin{cases} A_1 + A_2^2/8A_1 & \text{ if } A_2 \leq 4A_1\\ A_2 - A_1 & \text{ if } A_2 > 4A_1 \end{cases}$