自行完成:4-PSK、16-PSK仿真,并与8-PSK比较;或者,完成2FSK/2ASK仿真。
时间: 2024-02-05 20:13:05 浏览: 72
matlab_ASK、PSK和FSK信号的盲识别仿真,仿真产生各类信号,分别可进行大类间的识别和类内识别,统计识别准确率
5星 · 资源好评率100%
我可以为您提供一个基于Python的4-PSK和16-PSK仿真代码示例。请注意,由于缺乏具体的系统参数,此代码仅用于演示目的,您需要根据自己的系统参数进行修改。
```python
import numpy as np
import matplotlib.pyplot as plt
# 调制信号
def modulate(bits, M):
if M == 4:
symbols = np.array([1+1j, 1-1j, -1+1j, -1-1j]) / np.sqrt(2)
elif M == 16:
symbols = np.array([
1+1j, 1+3j, 3+1j, 3+3j,
1-1j, 1-3j, 3-1j, 3-3j,
-1+1j, -1+3j, -3+1j, -3+3j,
-1-1j, -1-3j, -3-1j, -3-3j
]) / np.sqrt(10)
else:
raise ValueError("M must be 4 or 16")
N = len(bits)
k = int(np.log2(M))
symbols_per_bit = int(N / k)
bits = bits[:symbols_per_bit*k]
bits = np.reshape(bits, (symbols_per_bit, k))
bits = np.packbits(bits, axis=1)
symbols = symbols[bits]
return symbols.flatten()
# 高斯白噪声
def awgn(signal, SNR_dB):
L = len(signal)
SNR = 10**(SNR_dB/10.0)
signal_power = np.sum(np.abs(signal)**2) / L
noise_power = signal_power / SNR
noise = np.sqrt(noise_power/2) * (np.random.randn(L) + 1j*np.random.randn(L))
return signal + noise
# 误码率
def ber(bits_tx, bits_rx):
return np.sum(bits_tx != bits_rx) / len(bits_tx)
# 模拟
M = 4
SNR_dB = 10
k = int(np.log2(M))
bits_tx = np.random.randint(0, 2, 10000*k)
symbols_tx = modulate(bits_tx, M)
symbols_rx = awgn(symbols_tx, SNR_dB)
bits_rx = np.unpackbits(np.array(np.round((symbols_rx.real + 2) / 2), dtype=np.uint8))
bits_rx = bits_rx[-len(bits_tx):]
print("M: %d, SNR: %d dB, BER: %.2e" % (M, SNR_dB, ber(bits_tx, bits_rx)))
M = 16
SNR_dB = 10
k = int(np.log2(M))
bits_tx = np.random.randint(0, 2, 10000*k)
symbols_tx = modulate(bits_tx, M)
symbols_rx = awgn(symbols_tx, SNR_dB)
bits_rx = np.unpackbits(np.array(np.round((symbols_rx.real + 2) / 2), dtype=np.uint8))
bits_rx = bits_rx[-len(bits_tx):]
print("M: %d, SNR: %d dB, BER: %.2e" % (M, SNR_dB, ber(bits_tx, bits_rx)))
M = 8
SNR_dB = 10
k = int(np.log2(M))
bits_tx = np.random.randint(0, 2, 10000*k)
symbols_tx = modulate(bits_tx, M)
symbols_rx = awgn(symbols_tx, SNR_dB)
bits_rx = np.unpackbits(np.array(np.round((symbols_rx.real + 2) / 2), dtype=np.uint8))
bits_rx = bits_rx[-len(bits_tx):]
print("M: %d, SNR: %d dB, BER: %.2e" % (M, SNR_dB, ber(bits_tx, bits_rx)))
```
您可以通过更改M和SNR_dB的值,以及添加其他的系统参数,来进行不同条件下的仿真。
阅读全文