【信号处理】绘制IQ信号时域图、星座图、功率谱

时域图

python 复制代码
# 导入相关的库
import pickle
import matplotlib.pyplot as plt
import numpy as np
from pathlib import Path
import os

with open(r"C:\0-数据集\公开\RML2016\RML2016.10a_dict.pkl", 'rb') as file:
    Xd = pickle.load(file, encoding='bytes')
snrs, mods = map(lambda j: sorted(list(set(map(lambda x: x[j], Xd.keys())))), [1, 0])
print(snrs)
print(mods)

def time_domain_rml2016(select_mod=b'PAM4',select_snr=16, select_num=10):

    print(select_mod, select_snr)

    path = Path("./time/" + str(select_mod) + '_' + str(select_snr))
    # print(path)
    if not path.exists():
        os.makedirs(path)

    for i in range(select_num):
        fig = plt.figure()
        plt.plot(Xd[select_mod, select_snr][i, 0])
        plt.plot(Xd[select_mod, select_snr][i, 1])
        name = str(select_mod) + '_' + str(select_snr) + '_' + str(i) + '.png'
        print(name)
        plt.axis('off')  # 关闭坐标轴
        plt.gca().set_frame_on(False)  # 关闭图形边框
        # 只保存散点图
        plt.savefig(path/name)
        # plt.show()

time_domain_rml2016()

星座图

把输入的IQ信号定义为信号的实部和虚部(但实际上IQ两路信号都是实信号)将I和Q分别作为横轴和纵轴,那么在复平面上每两个IQ值可以对应一个固定的点,将坐标图画出来就叫做星座图。

python 复制代码
# 导入相关的库
import pickle
import matplotlib.pyplot as plt
import numpy as np
from pathlib import Path
import os

with open(r"C:\0-数据集\公开\RML2016\RML2016.10a_dict.pkl", 'rb') as file:
    Xd = pickle.load(file, encoding='bytes')
snrs, mods = map(lambda j: sorted(list(set(map(lambda x: x[j], Xd.keys())))), [1, 0])
print(snrs)
print(mods)

def constellation_rml2016(select_mod=b'QPSK',select_snr=16, select_num=10):
    data = []
    # 遍历调制方式和信噪比,提取数据
    for mod in mods:
        for snr in snrs:
            if mod == select_mod and snr == select_snr:
                data.append(Xd[(mod,snr)])

    data = np.vstack(data)
    print(len(data))
    print(select_mod, select_snr)

    path = Path("./" + str(select_mod) + '_' + str(select_snr))
    # print(path)
    if not path.exists():
        os.makedirs(path)

    for i in range(select_num):
        x, y = data[i]
        fig = plt.figure()
        plt.scatter(x, y, c='blue')
        # plt.xlabel("I")
        # plt.ylabel("Q")
        name = str(select_mod) + '_' + str(select_snr) + '_' + str(i) + '.png'
        print(name)
        # 不显示坐标轴、标题等信息
        plt.axis('off')  # 关闭坐标轴
        plt.gca().set_frame_on(False)  # 关闭图形边框
        # 只保存散点图
        plt.savefig(path/name)
        # plt.show()

constellation_rml2016()

功率谱

python 复制代码
# 导入相关的库
import pickle
import matplotlib.pyplot as plt
import numpy as np
from pathlib import Path
import os

with open(r"C:\0-数据集\公开\RML2016\RML2016.10a_dict.pkl", 'rb') as file:
    Xd = pickle.load(file, encoding='bytes')
snrs, mods = map(lambda j: sorted(list(set(map(lambda x: x[j], Xd.keys())))), [1, 0])
print(snrs)
print(mods)

def spectrum_power_rml2016(select_mod=b'AM-DSB',select_snr=0, select_num=10):

    print(select_mod, select_snr)

    path = Path("./spectrum/" + str(select_mod) + '_' + str(select_snr))
    # print(path)
    if not path.exists():
        os.makedirs(path)

    for i in range(select_num):
        fig = plt.figure()

        data_I = Xd[select_mod, select_snr][i, 0]
        data_Q = Xd[select_mod, select_snr][i, 1]

        # 合成IQ信号
        data_IQ = data_I + 1j*data_Q

        # 功率谱分析:对IQ信号进行FFT,计算功率谱
        power_spectrum = np.abs(np.fft.fft(data_IQ)) ** 2
        # 计算频率轴
        frequencies = np.fft.fftfreq(len(power_spectrum), 1)  # 假设 time_step 为 1
        idx = np.argsort(frequencies)

        plt.plot(frequencies[idx], power_spectrum[idx])

        name = str(select_mod) + '_' + str(select_snr) + '_' + str(i) + '.png'
        print(name)
        plt.axis('off')  # 关闭坐标轴
        plt.gca().set_frame_on(False)  # 关闭图形边框
        # 只保存散点图
        plt.savefig(path/name)
        # plt.show()

spectrum_power_rml2016()

参考链接

RML2016.10a数据集画星座图、频域图、时域图
JoshiShamika/Deep-learning-for-Modulation-Recognition-on-RML2016.10a_dict-dataset

相关推荐
冷眼Σ(-᷅_-᷄๑)3 分钟前
初识Python:IDE篇
ide·python
EterNity_TiMe_3 分钟前
【论文复现】自动化细胞核分割与特征分析
运维·人工智能·python·数据分析·自动化·特征分析
yangpipi-5 分钟前
数据结构(C语言版)-2.栈和队列
c语言·开发语言·数据结构
还在学习进步8 分钟前
C语言第九周课——经典算法
c语言·开发语言·算法
阿七想学习10 分钟前
数据结构《链表》
java·开发语言·数据结构·学习·链表
极客代码12 分钟前
【Python TensorFlow】进阶指南(续篇二)
开发语言·人工智能·python·深度学习·tensorflow
计算机学姐26 分钟前
基于Python的高校成绩分析管理系统
开发语言·vue.js·后端·python·mysql·pycharm·django
VertexGeek27 分钟前
Rust学习(三):rust基础Ⅱ
开发语言·学习·rust
北京_宏哥30 分钟前
《最新出炉》系列入门篇-Python+Playwright自动化测试-50-滚动条操作
python·前端框架·测试
九年义务漏网鲨鱼33 分钟前
【人脸伪造检测后门攻击】 Exploring Frequency Adversarial Attacks for Face Forgery Detection
论文阅读·python·算法·aigc