将具有特定SNR的随机噪声添加到信号

时间:2018-10-21 09:16:41

标签: matlab signal-processing noise

我有随机产生的信号,例如:

%frequency
f1 = 1000; f2 = 2000;
Fs = 8000; %sampling frequency

%amplitudes
amp1 = 0.75;
amp2 = 0.2;

%time
dt = 1/Fs
stopTime = 0.3;
t = 0:dt:stopTime;

%random noise
noise = randn(1,length(t))

%generated signal
Signal = amp1*sin(2*pi*f1*t) + amp2*sin(2*pi*f1*t) + noise;

现在我需要创建两个信号S1,S2,它们具有特定SNR的随机噪声。 添加到S1的噪声必须不相关,而添加到S2的噪声 这是我尝试过的:

%SNR in dB
SNR = [-80,-40,-20,0,20,40,80];

%S1,S2 = Signal + rand noise with SNR -40dB
S1 = awgn(Signal,SNR(2),'measured')
S2 = awgn(Signal,SNR(2),'measured')

这种正确的方法是否可以产生SNR在-80dB到+ 80dB范围内的随机噪声?添加到S1的噪声是否与添加到S2的噪声不相关?

1 个答案:

答案 0 :(得分:2)

您可以只计算信号的方差,并添加具有产生所需SNR所需方差的噪声。这是一些python代码作为示例

import scipy as sp
import scipy.fftpack as fft

# frequency
f1 = 1000.0
Fs = 8000.0  # sampling frequency

# amplitudes
amp1 = 0.75

# time
n = sp.arange(1024)

# Desired SNR in dB
SNR_dB = 40

# Desired linear SNR
snr = 10.0**(SNR_dB/10.0)
print "Linear snr = ", snr

# Measure power of signal
signal1 = amp1*sp.sin(2*sp.pi*f1/Fs*n)
p1 = signal1.var()
print "Power of signal1 = ", p1

# Calculate required noise power for desired SNR
n = p1/snr
print "Noise power = ", n
print "Calculated SNR =  %f dB" % (10*sp.log10(p1/n))

# Generate noise with calculated power
w = sp.sqrt(n)*sp.randn(1024)

# Add noise to signal
s1 = signal1 + w
  

添加到S1的噪声是否与添加到S2的噪声不相关?

是的