Given two sine waves of the same frequency, but different amplitudes and phases, how do they combine.

\[ A \sin(2\pi f t + \phi_1) \\ B \sin(2\pi f t + \phi_2) \\ \]Phase difference:

\[ \Delta\phi = \phi_2 - \phi_1 \\ \]Amplitude:

Note that the amplitude depends on the cosine of the phase difference. The sign of the phase difference does not matter because \[\cos(x) = \cos(-x)\] but it's not true for the sine, \[\sin(x) \neq \sin(-x)\]

\[ A_{sum} = \sqrt{ A^2 + B^2 + 2 A B \cdot \cos(\Delta\phi }) \\ \]Phase:

\[ \phi_{sum} = \text{atan2} (A \sin(\phi_1) + B \sin(\phi_2), A \cos(\phi_1) + B \cos(\phi_2)) \]Using complex numbers:

\[ X_{real} = A + B \cos(\Delta\phi) \\ X_{imag} = B \sin(\Delta\phi) \\ \\ A_{sum} = \sqrt{X_{real}^2 + X_{imag}^2 } \\ \phi_{sum} = \text{atan2}(X_{imag}, X_{real}) \]Which can be converted to decibels (dB).

\[ A_{dB} = 20 \cdot \log_{10} (A_{sum}) \]Which can be simplified into:

\[ \Delta\phi = \phi_2 - \phi_1 \\ A_{dB} = 10 \cdot \log_{10} ({ A^2 + B^2 + 2 A B \cos(\Delta\phi) }) \\ \phi_{sum} = \text{atan2}(B \sin(\Delta\phi), A + B \cos(\Delta\phi)) \\ \]Unequal amplitude. Values in dB must be converted to magnitude.

```
a = 1
b = 0.5
deltaPhase = phase2 - phase1
bCosDeltaPhase = b * cos(deltaPhase)
db = 10 * log10(a*a + b*b + 2 * a * bCosDeltaPhase)
bSinDeltaPhase = b * sin(deltaPhase)
phase = atan2(bSinDeltaPhase, a + bCosDeltaPhase)
```

Code language: Tagger Script (taggerscript)

Relative amplitude

```
a = 1
b = 0.5
b = b / a
a = 1
deltaPhase = phase2 - phase1
bSinDeltaPhase = b * sin(deltaPhase)
bCosDeltaPhase = b * cos(deltaPhase)
db = 10 * log10(1 + b*b + 2 * bCosDeltaPhase)
phase = atan2(bSinDeltaPhase, 1 + bCosDeltaPhase )
```

Code language: Swift (swift)

Equal amplitude

```
a = 1
b = 1
deltaPhase = phase2 - phase1
sinDeltaPhase = b * sin(deltaPhase)
cosDeltaPhase = b * cos(deltaPhase)
db = 10 * log10(2 + 2 * sinDeltaPhase)
phase = atan2(sinDeltaPhase, 1 + cosDeltaPhase)
```

Code language: Swift (swift)

\[
X_{real} = A \cos(\phi_1)+ B \cos(\phi_2) \\
X_{imag} = A \sin(\phi_1)+ B \sin(\phi_2) \\
\\
A_{sum} = \sqrt{X_{real}^2 + X_{imag}^2 } \\
\phi_{sum} = \text{atan2}(X_{imag}, X_{real})
\\
A_{sum} = \sqrt{\left( \sum_{i=1}^{n} A_i \cos(\phi_i) \right)^2 + \left( \sum_{i=1}^{n} A_i \sin(\phi_i)\right)^2} \\
\]
```
amplitude = [1, 1, 1];
phase = [0, 0, 0];
waveReal = sum(amplitude .* cos(phase));
waveImag = sum(amplitude .* sin(phase));
newAmplitude = sqrt(waveReal.^2 + waveImag.^2)
newPower = waveReal*waveReal + waveImag*waveImag
newDb = 10 * log10(newPower)
newPhase = atan2(waveReal, waveImag)
```

Code language: Matlab (matlab)

Is cos(phi_1 - phi2) == cos(phi2 - phi_1)?

Yes, (\cos(\phi_1 - \phi_2)) is equal to (\cos(\phi_2 - \phi_1)). This property stems from the fact that cosine is an even function, which means (\cos(-x) = \cos(x)) for any (x). Therefore, when you reverse the order of subtraction inside the cosine function, it doesn't change its value because (-(\phi_1 - \phi_2) = (\phi_2 - \phi_1)), and thus (\cos(\phi_1 - \phi_2) = \cos(-(\phi_1 - \phi_2)) = \cos(\phi_2 - \phi_1)).

But not for sine?

Correct, this property does not hold for the sine function. Unlike cosine, sine is an odd function, meaning (\sin(-x) = -\sin(x)) for any (x). Therefore, (\sin(\phi_1 - \phi_2) \neq \sin(\phi_2 - \phi_1)); instead, (\sin(\phi_1 - \phi_2) = -\sin(\phi_2 - \phi_1)). This reflects the sine function's sensitivity to the sign of its argument, which directly influences its symmetry properties.

The phase difference should be calculated as (phi_2 - phi_1)?

f (\phi_1) is the reference phase, then calculating the phase difference as (\phi_2 - \phi_1) makes sense. In this context, the phase difference indicates how much (\phi_2) leads or lags behind the reference phase (\phi_1).

- A positive value of (\phi_2 - \phi_1) would indicate that (\phi_2) leads (\phi_1).
- A negative value would indicate that (\phi_2) lags behind (\phi_1).

Using (\phi_1) as the reference point provides a clear baseline from which to measure all other phases, which is particularly useful in applications like signal processing, communication systems, or physics, where the timing between waves or signals relative to a reference is crucial.