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

169 views (last 30 days)
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 Comments
Walter Roberson
Walter Roberson on 25 Oct 2020
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 on 25 Oct 2020
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 ??

Sign in to comment.

Answers (2)

Shubham Rawat
Shubham Rawat on 28 Oct 2020
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 Comment
bob98
bob98 on 29 Oct 2020
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.

Sign in to comment.


Paul
Paul on 4 Nov 2020
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.

Categories

Find more on Signal Generation and Preprocessing in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!