Difference between randn() and awgn() in adding white noise to a signal
133 次查看(过去 30 天)
显示 更早的评论
Hi everyone
I'm trying to add a white noise to my signal and simulate it for different SNR values.
But I'm not sure if i should use randn() or awgn().
For instance I don't understand why these two methods deliver different signals in my code.
t=linspace(0,120,8000);
x=sin(2*pi*0.01.*t+pi/3).*cos(2*pi*0.01.*t+pi/3); %Original signal
n=2*randn(size(x)); %white noise
xn=x+n; %noisy signal method 1
SNR=snr(xn,n);
x2=awgn(x,SNR,'measured'); %noisy signal method 2
subplot(2,1,1);plot(t,xn);
title('Signal with white noise using randn');
subplot(2,1,2);plot(t,x2);
title('Signal with white noise using awgn');
I'd be very grateful for your clarifications and suggestions!
2 个评论
Walter Roberson
2020-10-25
With that option to awgn, the multiplier for randn() is sqrt(10^(SNR/10)) .
Your original multiplier was 2.
In order for those to match, SNR would have had to have been log10(2^20) or about 6.02 but it is about 0.12
Question: are you sure you want to measure SNR of xn (noisy x) against n (noise), instead of measuring SNR of xn (noisy x) against x ?
回答(2 个)
Shubham Rawat
2020-10-28
Hi bob,
Here in xn the noise you are adding is
n = 2*randn(size(x)); % noise using multiplier 2
xn = x + n;
Whereas in x2,
SNR=snr(xn,n);
x2=awgn(x,SNR,'measured'); % noise using multiplier sqrt(10^(SNR/10))
Paul
2020-11-4
This seems to get closer to what you're expecting:
t = linspace(0,120,8000);
x = sin(2*pi*0.01.*t+pi/3).*cos(2*pi*0.01.*t+pi/3); % Original signal
S = RandStream.getGlobalStream;
S.reset;
noise = 2*randn(size(x));
xn1 = x + noise;
S.reset;
SNR = snr(x,noise); % use the nominal signal
xn2 = awgn(x,SNR,'measured');
max(abs(xn1-xn2))
ans =
4.8495e-02
I was hoping that xn1 == xn2. They are close, but not quite equivalent.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Transmitters and Receivers 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!