请生成DSB和SSB调制的代码,并加入信噪比为10dB的高斯白噪声
时间: 2024-03-26 09:34:05 浏览: 123
matlab_模拟信号dsb和ssb调制基于simulink的仿真
5星 · 资源好评率100%
好的,以下是生成DSB和SSB调制的代码,并加入信噪比为10dB的高斯白噪声:
```python
import numpy as np
import matplotlib.pyplot as plt
# 生成信号
fs = 1000 # 采样率
t = np.arange(0, 1, 1/fs) # 时间轴
fc = 100 # 载波频率
fm = 10 # 信号频率
Am = 1 # 信号幅度
Ac = 1 # 载波幅度
m = Am * np.cos(2 * np.pi * fm * t) # 原始信号
c = Ac * np.cos(2 * np.pi * fc * t) # 载波信号
# DSB调制
dsb = m * c # DSB调制信号
# SSB调制
from scipy.signal import butter, filtfilt
# 带通滤波函数
def bandpass_filter(signal, lowcut, highcut, fs, order=5):
nyq = 0.5 * fs
low = lowcut / nyq
high = highcut / nyq
b, a = butter(order, [low, high], btype='band')
y = filtfilt(b, a, signal)
return y
# 上变频
upper = bandpass_filter(m, fc - fm, fc + fm, fs)
ssb_upper = upper * np.cos(2 * np.pi * fc * t)
# 下变频
lower = bandpass_filter(m, -fc - fm, -fc + fm, fs)
ssb_lower = lower * np.sin(2 * np.pi * fc * t)
# SSB调制信号
ssb = ssb_upper - ssb_lower
# 加入高斯白噪声
snr_db = 10 # 信噪比为10dB
snr = 10 ** (snr_db / 10)
P_signal = np.sum(dsb ** 2) / len(dsb)
P_noise = P_signal / snr
noise = np.random.normal(0, np.sqrt(P_noise), len(dsb))
dsb_noise = dsb + noise
ssb_noise = ssb + noise
# 绘图
fig, axs = plt.subplots(3, 1, figsize=(10, 10))
axs[0].plot(t, m, label='原始信号')
axs[0].legend()
axs[1].plot(t, dsb, label='DSB调制信号')
axs[1].plot(t, dsb_noise, label='加入噪声的DSB调制信号')
axs[1].legend()
axs[2].plot(t, ssb, label='SSB调制信号')
axs[2].plot(t, ssb_noise, label='加入噪声的SSB调制信号')
axs[2].legend()
plt.show()
```
希望对您有所帮助!
阅读全文