code
Modify the code Code_02_03.py. What if, instead of using ? = 716? rad, we use ? = 12? rad for the phase shift? Try different values for ?.
import numpy as np
# import scipy.signal as signal
import matplotlib.pyplot as plt
if __name__ == '__main__':
# Test bench area
print("Hello")
T = 0.00005 # Sampling period (sec)
fs = 1 / T # Sampling frequency (20KHz)
N = 1000 # Number of samples
t = np.arange(0.0, N * T, T) # N samples for total interval
f = np.arange(0.0, (N / 2) * (fs / N) / 1000, (fs / N) / 1000) # N / 2 samples for Nyquist interval (KHz)
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Transmission:
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Signal 1 with 100, 200 and 300 Hz components:
g1 = np.cos(2 * np.pi * 100 * t) + 0.1 * np.sin(2 * np.pi * 200 * t) + 0.4 * np.cos(2 * np.pi * 300 * t) # %Sign1
# Signal 2 with 100, 200 and 300 Hz components:
g2 = 0.4 * np.sin(2 * np.pi * 100 * t) + 0.1 * np.cos(2 * np.pi * 200 * t) + np.sin(2 * np.pi * 300 * t) # %Sign2
# Quadrature modulation with 1KHz carriers:
s = g1 * np.cos(2 * np.pi * 1000 * t) - g2 * np.sin(2 * np.pi * 1000 * t) # QAM signal
S = np.fft.fft(s)
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Reception:
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# 1KHz local oscillator:
teta = np.pi * 1 / 8 # Angle of phase with respect to the carrier
lo_i = np.cos(2 * np.pi * 1000 * t + teta) # Local oscillator in phase
lo_q = -np.sin(2 * np.pi * 1000 * t + teta) # Quadrature local oscillator
# Unfiltered demodulated channels:
y1 = s * lo_i
y2 = s * lo_q
# LP filter with cutoff at 1000 Hz (baseband):
# b_lp with 32 Coefficients for the FIR filter:
b_lp = signal.firwin(32, 0.1) # Taps, Cutoff = 2*1KHz/20KHz
# Filtered demodulated channels:
z1 = signal.lfilter(b_lp, 1, y1)
Z1 = np.fft.fft(z1)
z2 = signal.lfilter(b_lp, 1, y2)
Z2 = np.fft.fft(z2)
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Graphics:
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
fig1, axarr = plt.subplots(2, 1)
axarr[0].plot(t, s)
axarr[0].set_title('QAM signal s (t)')
axarr[0].set_xlabel('Time[s]')
axarr[1].stem(f[0:100], abs(S[0:100]))
axarr[1].set_title('|S(f)|')
axarr[1].set_xlabel('Frecuency[KHz]')
fig1.subplots_adjust(hspace=0.5)
fig2, axarr = plt.subplots(2, 1)
axarr[0].plot(t, z1)
axarr[0].set_title('Demodulated signala z1(t)')
axarr[0].set_xlabel('Time[s]')
axarr[1].stem(f[0:100], abs(Z1[0:100]))
axarr[1].set_title('|Z1(f)|')
axarr[1].set_xlabel('Frequency[KHz]')
fig2.subplots_adjust(hspace=0.5)
fig3, axarr = plt.subplots(2, 1)
axarr[0].plot(t, z2)
axarr[0].set_title('Demodulated signal z2 (t)')
axarr[0].set_xlabel('Time[s]')
axarr[1].stem(f[0:100], abs(Z2[0:100]))
axarr[1].set_title('|Z2(f)|')
axarr[1].set_xlabel('Frequency[KHz]')
fig3.subplots_adjust(hspace=0.5)
plot.show()
Step by step
Solved in 3 steps with 4 images