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

195 visualizzazioni (ultimi 30 giorni)
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 Commenti
Walter Roberson
Walter Roberson il 25 Ott 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 il 25 Ott 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 ??

Accedi per commentare.

Risposte (2)

Shubham Rawat
Shubham Rawat il 28 Ott 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 Commento
bob98
bob98 il 29 Ott 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.

Accedi per commentare.


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

Categorie

Scopri di più su Signal Generation and Preprocessing in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by