if modulation == 'QPSK':
constellation = torch.tensor([0.707+0.707j, 0.707-0.707j,
-0.707+0.707j, -0.707-0.707j])
bits_mapping = torch.tensor([
[0,0], [0,1], [1,0], [1,1]
], dtype=torch.int64)
threshold = 0.707 # 决策边界
elif modulation == '16QAM':
scale = 1/torch.sqrt(torch.tensor(10.0))
constellation = torch.tensor([
(-3-3j)*scale, (-3-1j)*scale, (-3+1j)*scale, (-3+3j)*scale,
(-1-3j)*scale, (-1-1j)*scale, (-1+1j)*scale, (-1+3j)*scale,
(1-3j)*scale, (1-1j)*scale, (1+1j)*scale, (1+3j)*scale,
(3-3j)*scale, (3-1j)*scale, (3+1j)*scale, (3+3j)*scale
], dtype=torch.complex64)
bits_mapping = torch.tensor([
[0,0,0,0], [0,0,0,1], [0,0,1,0], [0,0,1,1],
[0,1,0,0], [0,1,0,1], [0,1,1,0], [0,1,1,1],
[1,0,0,0], [1,0,0,1], [1,0,1,0], [1,0,1,1],
[1,1,0,0], [1,1,0,1], [1,1,1,0], [1,1,1,1]
], dtype=torch.int64)
threshold = scale * 2.0 # 决策边界
elif modulation == '64QAM':
scale = 1/torch.sqrt(torch.tensor(42.0))
levels = [-7, -5, -3, -1, 1, 3, 5, 7]
constellation = torch.tensor([i + 1j*q for i in levels for q in levels]) * scale
bits_mapping = torch.tensor([
[int(b) for b in f"{i:06b}"]
for i in range(64)
], dtype=torch.int64)
threshold = scale * 2.0
else:
raise ValueError(f"不支持的调制方式: {modulation}") 在这段代码中将constellation 和 bit mapping 都是用循环生成的方式来简化代码
最新发布