Weighted sum of cosines with different phase offsets 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?
 A: 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)$$
A: You just obtain a cosine
$$
\eqalign{
  & \sum\limits_{n = 1}^N {A_{\,n} \cos \left( {x + \phi _{\,n} } \right)}  = {\mathop{\rm Re}\nolimits} \left( {\sum\limits_{n = 1}^N {A_{\,n} e^{ix + i\phi _{\,n} } } } \right) =   \cr 
  &  = {\mathop{\rm Re}\nolimits} \left( {\left( {\sum\limits_{n = 1}^N {A_{\,n} e^{i\phi _{\,n} } } } \right)e^{ix} } \right) = {\mathop{\rm Re}\nolimits} \left( {\left( {Ce^{i\theta } } \right)e^{ix} } \right) =   \cr 
  &  = C\cos \left( {x + \theta } \right) \cr} 
$$
whatever be the number and value of the amplitudes and phases, as electrical engineers know very well.
