# Why do you get instantaneous phase by calculating correlation with a carrier signal?

I am somewhat new to DSP. I'm trying to implement BPSK by following this Python QAM tutorial.

My code seems to work, but I really just ported the tutorial's Python code to C++, and do not understand it. This is the part that confuses me the most:

# Demodulate in "real" and "imaginary" parts. The "real" part
# is the correlation with carrier. The "imaginary" part is the
# correlation with carrier offset 90 degrees. Having both values
# allows us to find QAM signal's phase.

for sample in samples:
t += 1
angle = CARRIER * t * 2 * math.pi / SAMPLE_RATE
real.append(sample * math.cos(angle))
imag.append(sample * -math.sin(angle))

for t in range(0, len(real)):
# This converts (real, imag) to an angle
angle = math.atan2(imag[t], real[t])
phase.append(angle)


I understand that this code is correlating the input signal with two identical carrier waves which are offset by 90º. I do not understand why that correlation has anything to do with phase.

I'd love an answer to any of the following questions:

• Why does this code work?
• What is the connection between correlation and phase?
• Is this a common, reliable method of calculating phase?
• Why does the FFT need so many samples to calculate phase, but this code just needs 1 sample?

Feel free to refer me to a signal theory or DSP book that answers these questions!

• It's actually not correlating by the two carriers. What you see there is just pointwise multiplication (or "mixing") by the generated carrier signals. This is different from correlation (which is often used in digital communications receivers). Jan 23 '13 at 17:48

This is the analytic signal. See wikipedia for better details.

Basically you are taking the carrier correlation, $f(x)$, and its Hilbert transform, $(h \ast f)(x)$ and combining them into a single complex valued signal, the analytic signal

$$f_A(x) = f(x) - i (h \ast f)(x)$$

which can be written as the complex exponential

$$f_A(x) = A(x) e^{i \phi(x)}$$

Why this is useful is that it performs a split of identity into seperate amplitude $A$ and phase $\phi$ components. Actually the Hilbert transform requires the entire signal to compute, but because you know the function of your signal already you only need the one sample.To localise the phase, you would use a bandpass filter.

• Thanks for the answer! What do you mean by "split of identity"? Also what does it mean to "localise" phase? Jan 28 '13 at 5:31
• Split of identity means the resulting expression has values invariant or equivariant to certain transformations. e.g. if the signal is multiplied by a scalar, $A$ changes but not $\phi$. if it is translated, both $A$ and $\phi$ are translated. If the signal is a sinusoid, changing the phase of the sinusoid changes $\phi$ but not $A$. Actually localisation applies both amplitude and phase. It refers to how much of the signal around a certain location is used to calculate $A$ and $\phi$. The Hilbert transform has an infinite impulse response and so uses the whole signal. Feb 11 '13 at 2:47
• Using a bandpass filter means only values close to the point are used. Feb 11 '13 at 2:47

This was finally was explained to me by the author of the tutorial:

Demodulation is achieved just by multiplying the signal again and using a low-pass filter because demodulation leaves a high-frequency (2 * carrier) undesirable "noise."

The modulator changes phase of the carrier. RX demodulates using two carriers, 90 degrees apart. The low-pass result of each demodulation will be proportional to the phase of the signal.

For example, if the original information was "angle = 90", the modulated signal will be $\sin (t)$

PSK detection yields

$y = \sin (t) \sin (t) = \frac{1 - \cos (2t)}{2}$

$x = \sin (t) \cos (t) = \frac{\sin (2t)}{2}$

If you pass both signals through a low-pass filter that removes the $2t$ frequency noise, you are left with

$y = \frac{1}{2}$

$x = 0$

and $\arctan(y, x)$ is 90 degrees. If the signal was 45 degrees, both demodulators would yield similar and positive values, once lowpassed.