I am trying to implement an SDR transmitter and receiver based on the description here.
def sdr_transmitter(signal: np.ndarray, frequency: float, sample_period: float):
"""
Encode input signal in the form of IQ values to output signal.
"""
Is = signal[:, 0]
Qs = signal[:, 1]
t = np.arange(0, signal.shape[0] * sample_period, sample_period)
in_phase = Is * np.cos(2 * math.pi * frequency * t)
quadrature = Qs * np.sin(2 * math.pi * frequency * t)
signal = in_phase + quadrature
return signal
def sdr_receiver(signal: np.ndarray, frequency: float, sample_period: float):
"""
Takes the signal and extracts the in-phase and quadrature components.
In other words, extracts the cosine and sine components, the I and Q.
"""
t = np.arange(0, signal.shape[0] * sample_period, sample_period)
cos_wave = np.cos(2 * math.pi * frequency * t)
sin_wave = np.sin(2 * math.pi * frequency * t)
Is = signal * cos_wave
Qs = signal * sin_wave
output = np.stack([Is, Qs], axis=-1)
return output
and I test it like this:
sample_period = 0.02
Is = np.full(100, fill_value=1)
Qs = np.full(100, fill_value=1)
signal = np.stack([Is, Qs], axis=-1)
output = sdr_transmitter(signal, frequency=2, sample_period=sample_period)
signal_output = sdr_receiver(output, frequency=2, sample_period=sample_period)
where the signal
and signal_output
should equal. However, they do not. Since the Is
and Qs
are constant, I should get the same constant values after demodulation by the receiver. I believe that by multiplying by sin and cos waves, I should get those values thanks to the Frequency Shift Property (from here):
$$e^{2 \pi j f_0 t}x(t) \leftrightarrow X(f-f_0)$$
Thus, after subtraction of the frequency, the resulting frequency should be zero, which means that only constant values remain, and in fact, the constant values should be equal to the original Is
and Qs
. What I observed is the opposite; the frequency increased (see the plots below).
Transmitter: Let's look at the signals inside of the transmitter using the example above. Note that the in-phase signal overlaps with the cosine since the Is
are all equal to 1.
Receiver: Now, let's see what happens when the signal is multiplied by cosine and check whether the Is
are what we expect.
We can see that the Is
do not represent a constant function at 1, but instead, it is a wave with a higher frequency than the signal or the cosine.
Apparently, I misunderstood something and can't figure out what. Any advice will be appreciated. Thanks a lot!