Difference between randn() and awgn() in adding white noise to a signal

90 ビュー (過去 30 日間)
bob98
bob98 2020 年 10 月 25 日
回答済み: Paul 2020 年 11 月 4 日
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
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 ?
bob98
bob98 2020 年 10 月 25 日
Thank you for your answer, but i'm not sure what you mean by multiplier,standard deviation ? (sorry but i'm still an absolute beginner in Matlab..)
otherwise regarding your question, this is how the SNR of xn is defined, right ? noisy signal/ noise ??

サインインしてコメントする。

回答 (2 件)

Shubham Rawat
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))
  1 件のコメント
bob98
bob98 2020 年 10 月 29 日
Thank you for your clarification.
So as far as i understand we have here 2 different variance values 1st one is 4 the 2nd one is 10^(SNR/10).
So how does that influence the snr values (signal,noise) especially as the second one is given as input?
How do i get both methods to generate signals with the same SNR?
I look forward for your answer.

サインインしてコメントする。


Paul
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.

カテゴリ

Help Center および File ExchangeTransmitters and Receivers についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by