Proper generation of Complex white Gaussian noise using Matlab [closed]

I am not comfortable in using the Matlab's awgn() function as it is hard to understand what is actually going on. So, I wanted to confirm if the following way is correct to generate noisy samples of a particular snr of 30 dB and a particular variance for data in complex domain.

closed as unclear what you're asking by Peter K.♦Dec 7 '16 at 12:46

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• It's not clear what your question is? – Peter K. Dec 7 '16 at 12:46

Refer to the code below that generates some noise at a given SNR:

N = 100000;

% Generate some random signal
signal = randn(N, 1) + 1j*randn(N,1);

% Here, the signal power is 2 (1 for real and imaginary component)
signalPower_lin = 1/N*signal'*signal

% This corresponds to 3dB (assuming power=1 is 0dB)
signalPower_dB = 10*log10(signalPower_lin)

noisePower_dB = signalPower_dB - 30  % do 30dB SNR
noisePower_lin = 10^(noisePower_dB/10)

noise = sqrt(noisePower_lin/2) * (randn(N,1) + 1j*randn(N,1));



The program outputs:

signalPower_lin =

2.0042 + 0.0000i

signalPower_dB =

3.0193 + 0.0000i

noisePower_dB =

-26.9807 + 0.0000i

noisePower_lin =

0.0020 + 0.0000i


Note that generating a complex noise of variance 1, you need to do

noise = sqrt(1/2) * (randn(N,1) + 1j*randn(N,1))


Since each component (real and imaginary) needs to have variance 1/2, such that their sum becomes 1.

To answer your points: 1) As a rule of thumb when to use 20 and when to use 10: If you describe Powers or Energies, the factor is 10. If you describe amplitudes, the factor is 20. Then, in dB-scale both would have the same value, since:

\begin{align} P&=A^2 \text{ (Power = Amplitude squared)}\\ 10\log(P) &= 10\log(A^2)\\ &=20\log(A) \end{align}

So, anytime you use a values which creates something meaningful when squared (like amplitude), use 20. Everytime, you have something that is meaningful when taken the square root from (like Power), use 10.

Note that in my code, I use noise = sqrt(noise_power/2) * randn(...) to generate the noise, i.e. I transform the noise power into the noise amplitude prior to multiplying the normal random variable (which corresponds to changing the factor 10 to 20 in the exponent). Also remember the rule $$Var(aX) = a^2Var(X)$$ which is exactly the reason why you need to take the square root of the power, such that your resulting noise has the required power.

2) Here, I just transform noisePower_db into noisePower_linear, which is by definition linear=10^(db/10). Note that $10^{-SNR/10}$ is similar, since SNR=Signal/Noise, i.e. the noise is in the denominator (consider $10^{-1/x}=10^x$.

• Thank you once again. I am a bit confused due to the following points (1) In another answer by Hilmar, it is suggested to use 10^(-SNR/20), as we are summing amplitudes, which is noisePower_lin in your code but the denominator is 20 instead of 10. (2) In this formula noise_power_linear_scale = 10^(-SNR/ (?) ), we put a minus but you have not done so. Can you please clarify. – SKM Dec 6 '16 at 19:17
• I have added some more explanation on your two points. – Maximilian Matthé Dec 6 '16 at 19:42
• Thanks for the update. Two observations which I noticed -- (1) can you plz answer, why are you subtracting 30dB (the specific SNR value) in  noisePower_dB = signalPower_dB - 30  ? What formula have you used? (2) Also, sometimes the imaginary part of the signal and noise power in both linear and db scale has a significant value and is no longer zero as given in your example. But, noise power, signal power and variances always have real value. – SKM Dec 7 '16 at 0:42
• 1) SNR=30dB means 10*log(S_lin/N_lin)=30=10log(S_lin)-10*log(N_lin)=S_db-N_db. 2) Power is always a real value, as it is defined by $\int s(t)*conj(s(t))dt$ which is always real. If in a simulaton/calculation you got some significant non-zero imaginary part, there is very likely an error. In my code, the values of imaginary part are very small (e.g. 1e-18) which is just due to the numeric. – Maximilian Matthé Dec 7 '16 at 6:18
1. Since you are summing amplitudes you need to use 10^(-SNR/20).
2. You use gaussian distribution for the noise but uniform distribution for the signal. rand() and randn() work differently and result in different signal power.
• Thank you for your reply. But your first point is not clear...where should I use 10^(-SNR/20)? Will it be for both snr = 10.^(0.1.*30) or sigma2n = 10^(-SNR/10) where SNR = 30 Db – SKM Dec 6 '16 at 17:57