Hi , please what is the difference between randn and awgn , when adding white gaussian noise to get snr = 10dB , also I see difference in result when using snr function .

3 views (last 30 days)
P_rms = rms(signal)^2; %
noisy_signal_1 = awgn(signal,10,'measured');
noisy_signal_2 = signal+0.1*P_rms*randn(L_t,1);
snr1=snr(signal,awgn(signal,10,'measured'))
snr2=snr(signal,noisy_signal_2)
var1=var(noisy_signal_1);
var2=var(noisy_signal_2);

Answers (1)

Meg Noah
Meg Noah on 7 Aug 2025
They are the same.
% signal is a sine wave of 2 Hz
nSamples = 10000;
f = 2; % [Hz]
time = linspace(0, 2, nSamples+1);
signal = sin(2*pi*f*time);
% calculate the signal power
signalPower = sum((signal).^2)./nSamples;
% SNR in db is 10log(Psignal/Pnoise)
snrDb = 10; % [dB]
% noise power such that signal power is 10 dB more
% 10 = 10 log (Ps / Pn)
% Pn is variance which for zero mean gaussian noise
% is essentially - square sum of all samples -> divided by numSamples
noiseStd = sqrt(signalPower / 10^(snrDb/10));
noiseMean = 0;
% generate the gaussian white noise
noiseValues = noiseStd*randn(nSamples,1) + noiseMean;
% verify the Signal-to-Noise value
noisePower = sum(noiseValues.^2)/numel(noiseValues);
SNR = 10*log10(signalPower/noisePower);
fprintf(1,"noiseStd: model input: %f simulation output: %f\n", noiseStd, std(noiseValues));
noiseStd: model input: 0.223607 simulation output: 0.224735
fprintf(1,"SNR: %f\n", SNR);
SNR: 9.956735
% compare to awgn
noisedSignal = awgn(signal,10,'measured');
awgnNoiseValues = noisedSignal - signal;
awgnNoisePower = sum(awgnNoiseValues.^2)/numel(awgnNoiseValues);
SNR = 10*log10(signalPower/awgnNoisePower);
fprintf(1,"awgnNoiseStd: simulation output: %f\n", std(awgnNoiseValues));
awgnNoiseStd: simulation output: 0.223148
fprintf(1,"SNR: %f\n", SNR);
SNR: 10.018253

Categories

Find more on Propagation and Channel Models 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!