Is noise with awgn function or randn fucntion can guarantee SNR?
43 views (last 30 days)
Show older comments
I saw 2 ways to add WGN
1st is noise_power/sqrt(2)*(randn+1j*randn)
2nd is awgn(signal,SNR,signal_power)
I think these 2 method cant guarantee SNR because of random (of course awgn fucntion is random too)
Am i thinking right?
0 Comments
Answers (2)
Pooja Kumari
on 15 Sep 2023
Hello,
I understand that you want to know if two different methods of adding noise to a signal can guarantee SNR or not. There are two ways to add White Gaussian noise either by using “randn” function or by “awgn” function, we cannot guarantee SNR for real scenarios. However, the simulations for noise that we perform in MATLAB should achieve the exact noise levels as we want.
The “randn” function generates random numbers from a standard normal distribution, which can be used to generate Gaussian noise. However, using “randn” alone does not guarantee a specific SNR.
On the other hand, the “awgn” function in MATLAB is used to add additive white Gaussian noise (AWGN) to a signal. It allows you to specify the desired signal-to-noise ratio (SNR) to achieve a specific level of noise in the signal.
Here is a code snippet for your understanding:
t=linspace(0,10,1000);
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)
[x2,np]=awgn(x,SNR,'measured'); %noisy signal method 2
snr2 = snr(x2)
You can refer to the documentation for more information on “awgn” function :
You can refer to the below documentation for more information on “snr” function:
I hope this helps!
0 Comments
Marc
on 27 May 2025
Both “randn” and “awgn”, when used appropriately, can achieve a target SNR.
“randn” is more of a manual approach, as we will see below, while “awgn” has options to control its behavior and adapt the noise level to various situations.
As far as “guarantee” is concerned, on a small number of samples, the actual noise power can deviate from the target because sequences are random and will only converge towards their statistical average on longer runs.
The examples below use 50000 samples and they show a great match, but deviations are not only possible but expected on smaller numbers of samples (for example 1000). So, strictly speaking, you cannot “guarantee” a given noise level on short noise sequences, unless you measure the actual noise power and rescale the noise sequence appropriately.
That being said, you can generate a random Gaussian noise of power 1 (0 dB) with either method below:
% Noise of power 1
L = 50000; % length of the signal
n1_0dB = complex(randn(L,1),randn(L,1)) / sqrt(2);
snr = 0;
n2_0dB = awgn(complex(zeros(L,1)),snr);
fprintf('power_randn = %.2f power_awgn = %.2f\n',var(n1_0dB),var(n2_0dB))
power_randn = 1.00 power_awgn = 1.00
If you want to achieve an SNR of “snr” dBs and you assume/know that the power of the signal (as opposed to noise) is 0dB, you can ensure that ratio with either method below:
L = 50000; % length of the signal
snr = 10; % in dBs
n1_10dB = complex(randn(L,1),randn(L,1)) / sqrt(2) / 10^(snr/20);
n2_10dB = awgn(complex(zeros(L,1)),snr);
fprintf('power_randn = %.2f power_awgn = %.2f\n',var(n1_10dB),var(n2_10dB))
power_randn = 0.10 power_awgn = 0.10
Next, if you know the power of the input signal is P (say -10dB) and want and SNR = 10 dB, you can use either method below:
L = 50000; % length of the signal
signalP = -10; % dBW
snr = 10; % in dBs
n1_10dB_P = complex(randn(L,1),randn(L,1)) / sqrt(2) * 10^((signalP-snr)/20);
n2_10dB_P = awgn(complex(zeros(L,1)),snr,signalP);
fprintf('power_randn = %.2f power_awgn = %.2f\n',var(n1_10dB_P),var(n2_10dB_P))
power_randn = 0.01 power_awgn = 0.01
Finally, if you do not know the power of the signal and want it to be measured, you can use either method below:
L = 50000; % length of the signal
signal = 10^(-10/20) * exp(1j*(0:L-1)*2*pi*0.01); % complex sine wave frequency 0.01 and power -10dBW
P = 10*log10(var(signal)); % signal power in dBW
snr = 10; % in dBs
n1_10dB_Measured = complex(randn(L,1),randn(L,1)) / sqrt(2) * 10^((P-snr)/20);
n2_10dB_Measured = awgn(signal,snr,'measured');
fprintf('power_randn = %.2f power_awgn = %.2f\n',var(n1_10dB_Measured),var(n2_10dB_Measured-signal))
power_randn = 0.01 power_awgn = 0.01
Note that, in the case of noise added to a signal with fading, using the “measured” method yields a constant instantaneous SNR because the noise level fluctuates along the power of the signal. Commonly, in the case of fading, you want to consider that the power of the signal is known and set to the average signal power. This results in a time-varying SNR, as the noise power is fixed.
0 Comments
See Also
Categories
Find more on Beamforming and Direction of Arrival Estimation 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!