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

조회 수: 194 (최근 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 CenterFile Exchange에서 Signal Generation and Preprocessing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by