【频谱感知】生成数据集,使用DeepSig RadioML 2018.01A

很久之前做的这部分工作了,应该是去年把调制识别、频谱感知、频谱知识图谱等都做了一遍,现在主要工作是频谱异常检测和异常信号定位,看有人要代码就整理了一下

接上篇不完善的文章地址

记得下面代码是改编github上面的,github那个代码是rml2016数据集的且有问题,时间太长找不到原地址了

关键部分snr=(sum_pow-noise_pow)/noise_pow
反推出noise_pow,利用noise_pow生成复高斯噪声
noise = (np.random.randn(N) + 1j * np.random.randn(N)) / math.sqrt(2) * math.sqrt(avg_noise_pow)

排除17,18调制方式是因为对此种调制方式不太了解,变化太诡异,功率从一千涨到十万,
再除了图中前三个标注的功率范围,其他调制信号功率都是1000左右(1024个点,接近1024)

应该生成数据集用于调制识别没问题的,好像试过

原来‘z’标签为调制方式,新标签‘z’为信号1还是纯噪声0

在这里插入图片描述

import h5py
import numpy as np
import math

h5file = h5py.File('D:/RF_data/archive/GOLD_XYZ_OSC.0001_1024.hdf5', 'r')
out = h5py.File('D:/RF_data/archive/all_sencing.hdf5', 'w')
out_X = []
out_Y = []
out_Z = []

mods = [i for i in range(2)]
mods_ex = [17, 18]  # 排除17,18
for mod in mods:
    if mod in mods_ex:
        continue
    print(mod)
    for snr in range(26):
        start_index = 4096 * 26 * mod + 4096 * snr
        out_X.extend(h5file['X'][start_index:start_index + 1024])
        # 切两份,原信号一份,噪声一份
        out_Z.extend(h5file['Z'][start_index:start_index + 1024])
        out_Z.extend(h5file['Z'][start_index:start_index + 1024])

        new_class = [1, 0]
        new_class = np.expand_dims(new_class, 0)
        new_class = np.repeat(new_class, 1024, 0)
        out_Y.extend(new_class)
        new_snr = 10.0 ** (h5file['Z'][start_index][0] / 10.0)
        sig = h5file['X'][start_index, :, 0] + h5file['X'][start_index, :, 1] * 1j
        sum_pow = np.sum(np.abs(sig) ** 2)
        # 公式推导 ,new_snr=(sum_pow-noise_pow)/noise_pow
        noise_pow = sum_pow / (new_snr + 1)
        print(h5file['Z'][start_index][0],new_snr,sum_pow,noise_pow)
        avg_noise_pow = noise_pow / 1024.0
        for cout in range(1024):
            N = 1024
            noise = (np.random.randn(N) + 1j * np.random.randn(N)) / math.sqrt(2) * math.sqrt(avg_noise_pow)
            I, Q = np.real(noise).astype('float32'), np.imag(noise).astype('float32')
            temp = np.stack([I, Q], axis=1)
            out_X.append(temp)
        new_class = [0, 1]
        new_class = np.expand_dims(new_class, 0)
        new_class = np.repeat(new_class, 1024, 0)
        out_Y.extend(new_class)


    # aa = np.array(out_X)
    # bb = np.array(out_Y)
    # print(aa.shape,bb.shape)
out['X'] = out_X
out['Y'] = out_Y
out['Z'] = out_Z

print(out['Z'].shape,out['Y'].shape,)



  • 9
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值