# Generate Complex White Gaussian Noise in MATLAB

In the followinf code I am trying to generate a Complex Gaussian Noise:

n_3 = sqrt(0.1)*randn(1,K);
n_4 = sqrt(0.1)*randn(1,K);
beta_NLoS = (n_3+1i*n_4); % CN(0,0.1)


Does my code do as intended?

If you want a Circular Complex Gaussian Noise (Independent):

vComplexNoise = sqrt(noiseVar / 2) * (randn(1, numSamples) + (1i * randn(1, numSamples)))


For correlated noise you'll need to define the Co Variance Matrix and use Cholesky Decomposition.

### Update

Following @Stanley Pawlukiewicz advise, run the following code:

numSamples = 100000;
noiseVar   = 4;

mA = sqrt(noiseVar / 2) * (randn(numSamples, 1) + (1i * randn(numSamples, 1)));

var(mA)


You should see result which is very close to noiseVar on the screen.

• so the code i written is just a complex gaussian ,not circular? Aug 22 '18 at 7:57
• vComplexNoise = sqrt(0.1 / 2) * (randn(1, K) + (1i * randn(1, k))) like this? Aug 22 '18 at 7:59
• Yep, just like you wrote above. Please mark this as answered.
– Royi
Aug 22 '18 at 8:13
• but is't the gaussian distribution $\frac{1}{\sqrt{\sigma^2 2*\pi}}$ Aug 22 '18 at 8:24
• The formula for the Gaussian distribution with the variance in the denominator is the distribution function itself, not the random data itself! Then randn function will produce a (real) Gaussian (normal) distribution with a normalized variance of 1. So to get any other variance you need to scale the magnitude of whatever is generated by the standard deviation. Hence sqrt(noiseVar/2). The reason for the divide by 2 as Royi pointed out is that you are generating independent sequences that will sum together. For the sum of independent random variables the variances add. Aug 22 '18 at 10:42