本文介绍了向信号中添加具有特定SNR的随机噪声的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有随机产生的信号,例如:
I have randomly generated signal for example:
%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的噪声这是我尝试过的:
Now i need to create two Signals S1, S2 with random noise with specific SNR.Noise added to S1 must be uncorrelated with noise added to S2Here is what i tried:
%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的噪声不相关?
Is this correct approach to create random noise with SNR from range -80dB to +80dB? will noise added to S1 be uncorrelated with noise added to S2?
推荐答案
您可以只计算信号的方差,并添加具有产生所需SNR所需方差的噪声.这是一些python代码作为示例
You could just calculate variance of signal and add noise with variance required to produce desired SNR. Here is some python code as an example
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
是的
这篇关于向信号中添加具有特定SNR的随机噪声的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!