2

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?

user16409
  • 367

2 Answers2

4

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)$$

  • I did for two terms but while generalizing for N terms I was running into weird expressions because I was telescoping sums. – user16409 Mar 07 '20 at 19:26
  • Once you have completed $N=2$ you can complete $N=3$ by replacing terms 1 and 2 with the combined cosine wave found in $N=2$ case then apply the exact same process. Essentially, by induction. –  Mar 07 '20 at 19:56
3

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.

G Cab
  • 35,272
  • The fact that it's another cosine (with amplitude and phase shift) seems to be assumed in the problem statement; what's significant here is that this answer gives a way to compute the amplitude and phase. – David K Mar 07 '20 at 19:22
  • @DavidK: ah, thanks: I was reading the question differently .. – G Cab Mar 07 '20 at 19:33
  • I thought you might have read the question differently; nevertheless, it's an elegant answer and the calculations in the other answer follow directly from it. – David K Mar 07 '20 at 19:39
  • @DavidK Thanks for the appreciation, but actually that's an elementary exercise for an engineer. – G Cab Mar 07 '20 at 19:46
  • Well, of course it's elementary for engineers, because this insight makes everything so much easier. https://math.stackexchange.com/questions/921956/why-use-complex-numbers-when-representing-periodic-signals/921979#921979 – David K Mar 07 '20 at 20:00
  • Yes indeed, this is an elegant solution. – user16409 Mar 07 '20 at 20:25