向信号中添加指定信噪比dB的高斯白噪声做法

发布时间 2023-10-01 21:20:45作者: clayyjh

1、Matlab

直接调用函数awgn: https://ww2.mathworks.cn/help/comm/ref/awgn.html#mw_c6871974-86ae-4fe3-a574-c5c7da623e38

 

2、Python

def awgn(signal, desired_snr, signal_power):
    """
    Add AWGN to the input signal to achieve the desired SNR level.
    """
    # Calculate the noise power based on the desired SNR and signal power
    noise_power = signal_power / (10**(desired_snr / 10))
    
    # Generate the noise with the calculated power
    noise = np.random.normal(0, np.sqrt(noise_power), len(signal))
    
    # Add the noise to the original signal
    noisy_signal = signal + noise
    
    return noisy_signal

 

参考:https://saturncloud.io/blog/python-numpy-implementing-an-additive-white-gaussian-noise-function/