+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

2020-05(15)

2020-06(49)

2020-07(37)

2020-08(41)

2020-09(68)

【Python】实现BPSK、QPSK、QAM信号调制

发布于2021-03-23 07:16     阅读(2635)     评论(0)     点赞(2)     收藏(3)


0

1

2

3

4

1 BPSK调制

# -*- coding:utf-8 -*-
 
import numpy as np
from math import pi
import matplotlib.pyplot as plt
import matplotlib
import math
 
 
 
#码元数
 
size = 10
sampling_t = 0.01
t = np.arange(0, size, sampling_t)
 

# 随机生成信号序列
a = np.random.randint(0, 2, size)
m = np.zeros(len(t), dtype=np.float32)
for i in range(len(t)):
    m[i] = a[math.floor(t[i])]
fig = plt.figure()
ax1 = fig.add_subplot(2, 1, 1)
 
ax1.set_title('generate Random Binary signal', fontsize = 20)
plt.axis([0, size, -0.5, 1.5])
plt.plot(t, m, 'b')

fc = 4000
fs = 20 * fc # 采样频率
ts = np.arange(0, (100 * size) / fs, 1 / fs)
coherent_carrier = np.cos(np.dot(2 * pi * fc, ts))
 
bpsk = np.cos(np.dot(2 * pi * fc, ts) + pi * (m - 1) + pi / 4)

# BPSK调制信号波形
ax2 = fig.add_subplot(2, 1, 2)
ax2.set_title('BPSK Modulation', fontsize=20)#, fontproperties=zhfont1
plt.axis([0,size,-1.5, 1.5])
plt.plot(t, bpsk, 'r')
plt.show()
print()

在这里插入图片描述

2 QPSK

from scipy import signal, special
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker 
from matplotlib.font_manager import FontProperties


t = np.arange(0,8.5,0.5)
# input
plt.subplot(4,1,1)
y1 = [0,1,1,0,1,1,0,0,0,1,1,0,1,1,0,0,0]
plt.plot(t,y1,drawstyle='steps-post')
plt.xlim(0,8)
plt.ylim(-0.5,1.5)
plt.title('Input Signal')

# I Signal
plt.subplot(4,1,2)
a = 1/np.sqrt(2)
tI = np.arange(0,9,1)
yI = [-a,a,-a,a,-a,a,-a,a,a]
plt.plot(tI,yI,drawstyle='steps-post')
plt.xlim(0,8)
plt.ylim(-2,2)
plt.title('I signal')

# Q signal
plt.subplot(4,1,3)
yQ = [a,-a,-a,a,a,-a,-a,a,a]
plt.plot(tI,yQ,drawstyle='steps-post')
plt.xlim(0,8)
plt.ylim(-1,1)
plt.title('Q Signal')

# QPSK signal
plt.subplot(4,1,4)
t = np.arange(0,9.,0.01)
def outputwave(I,Q,t):
    rectwav = []
    for i in range(len(I)):
        t_tmp = t[((i)*100):((i+1)*100)]
        yI_tmp = yI[i]*np.ones(100)
        yQ_tmp = yQ[i]*np.ones(100)
        wav_tmp = yI_tmp*np.cos(2*np.pi*5*t_tmp)-yQ_tmp*np.sin(2*np.pi*5*t_tmp)
        rectwav.append(wav_tmp)
    return rectwav
rectwav = outputwave(yI,yQ,t)
plt.plot(t,np.array(rectwav).flatten(),'r')
plt.xlim(0,8)
plt.ylim(-2,2)
plt.title('QPSK Signal')

plt.tight_layout()
plt.show()

在这里插入图片描述

3 QAM

4 参考资料

  1. python实现BPSK调制信号解调
  2. 深入浅出通信原理Python代码版
  3. Python实现M-QAM

原文链接:https://blog.csdn.net/weixin_43935696/article/details/115035737

0

1

2

3

4

5

6



所属网站分类: 技术文章 > 博客

作者:74873487

链接: https://www.pythonheidong.com/blog/article/901463/322b80495abb48dd80e6/

来源: python黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

2 0
收藏该文
已收藏

评论内容:(最多支持255个字符)