我正在使用python执行qpsk调制的代码。我必须一个接一个地附加具有不同相移的正弦波。我已经尝试了append函数,但是代码仍未提供所需的期望输出。如何正确绘制qpsk调制波形?
编辑:这是代码
from numpy.fft import rfft, irfft, rfftfreq
from scipy.signal import hilbert
import matplotlib.pyplot as plt
import numpy as np
import gen_binary as gb
#data input
data_in=[]
freq=1000
T=1
t=np.arange(0,T,1/freq)
tb=0.1
samples=int(tb*freq)
sym=int(np.floor(np.size(t)/samples))
rand_n=np.random.rand(sym)
rand_n[np.where(rand_n>=0.5)]=1
rand_n[np.where(rand_n<0.5)]=0
data_in=rand_n
print(len(data_in))
#carrier signal
fc=100
amp=1
sine_wave=amp*np.sin(2*np.pi*fc*t)
#qpsk modulation
qpsk1=0
qpsk2=0
qpsk3=0
qpsk4=0
qpsk=[]
for i in range(0,len(data_in),2):
if(data_in[i]==0 and data_in[i+1]==0):
angle1 = 225
dt=np.arange(0,0.25,1/freq)
qpsk1=amp*np.sin(2*np.pi*fc*dt - angle1)
# qpsk.append(qpsk1)
elif(data_in[i]==0 and data_in[i+1]==1):
angle2= 135
dt=np.arange(0.25, 0.50, 1/freq)
qpsk2=amp*np.sin(2*np.pi*fc*dt - angle2)
# qpsk.append(qpsk2)
elif(data_in[i]==1 and data_in[i+1]==0):
angle3= 315
dt=np.arange(0.50,0.75,1/freq)
qpsk3=amp*np.sin(2*np.pi*fc*dt - angle3)
# qpsk.append(qpsk3)
elif(data_in[i]==1 and data_in[i+1]==1):
angle4= 45
dt=np.arange(0.75,1.00,1/freq)
qpsk4=amp*np.sin(2*np.pi*fc*dt - angle4)
qpsk=qpsk1+qpsk2+qpsk3+qpsk4
plt.plot(qpsk)
plt.title("Modulated signal")
plt.xlabel("Time")
plt.ylabel("Amplitude")
plt.show()