Weighted sum of cosines with different phase offsets

trigonometric seriestrigonometry

A finite sum of cosine functions weighted with different amplitude and phase, but with a fixed frequency,$$f(x) = \sum_{n=1}^{N}A_{n}cos(x+\phi_{n})$$
the question is if I were to fit $f(x)$ with $cos(x)$, what will be the amplitude and phase offset?

Best Answer

We have: $$ \sum_{n=1}^{N}A_n\cos(x+\phi_n)=A\cos(x+\phi)$$ Use the angle-sum formula $\cos(x+\phi)=\cos x\cos\phi-\sin x\sin\phi$: $$ \sum_{n=1}^{N}A_n(\cos x\cos\phi_n-\sin x\sin\phi_n)=A(\cos x\cos\phi-\sin x\sin\phi) $$ $$ \iff \cos x\sum_{n=1}^{N}A_n\cos\phi_n-\sin x\sum_{n=1}^{N}A_n\sin\phi_n=\cos x(A\cos\phi)-\sin x(A\sin\phi) $$ By equating the coefficients on $\cos x$ and $\sin x$ we get: $$ A\cos\phi = \sum_{n=1}^{N}A_n\cos\phi_n $$ $$ A\sin\phi = \sum_{n=1}^{N}A_n\sin\phi_n $$ Square both equations and add: $$ A^2 = \left( \sum_{n=1}^{N}A_n\cos\phi_n \right)^2 + \left( \sum_{n=1}^{N}A_n\sin\phi_n \right)^2 $$ $$ \implies A = \sqrt{\left( \sum_{n=1}^{N}A_n\cos\phi_n \right)^2 + \left( \sum_{n=1}^{N}A_n\sin\phi_n \right)^2} $$ To find angle, divide $A\sin\phi$ by $A\cos\phi$: $$ \tan\phi = \frac{A\sin\phi}{A\cos\phi} = \frac{\sum_{n=1}^{N}A_n\sin\phi_n}{\sum_{n=1}^{N}A_n\cos\phi_n } $$ To recover the angle without using piecewise definition of $\arctan$ I reccomend using the $\mbox{atan}2$ function, so that $$\phi=\mbox{atan}2\left(\sum_{n=1}^{N}A_n\sin\phi_n,\sum_{n=1}^{N}A_n\cos\phi_n\right)$$