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!