## Help on Noise Correlation Matrix

Started by 6 years ago●10 replies●latest reply 6 years ago●488 views**I was trying to create a Noise Cross Correlation Matrix in Matlab by using the following code:**

N = 100; % Number of Samples

r1 = rand(1,N) + 1i*rand(1,N);

r2 = rand(1,N) + 1i*rand(1,N);

corrMatrix = [ r1 ; r2 ]*[ r1' , r2' ]./N;

**The Correlation Matrix resulted in as below with some randomly generated sequence r1,r2:**

corrMatrix =

0.6851 0.5452 - 0.0260i

0.5452 + 0.0260i 0.7276

**My doubt here is that is this correlation matrix correctly generated? I was expecting a diagonal matrix but here the non-diagonal elements are non-zero? **

**Also is it that r1 and r2 are not independent of each other? **

**One more question, in terms of vector representation will it be correct to say that a vector R can be represented using r1 and r2, where R is a two dimensional vector (I was trying to link a real scenario to the vector space concepts and was getting confused)? Also how can we represent R in terms of its basis vectors? **

**I was trying to learn the concept de-correlation and any help here would be really appreciated! Thanks in advance! **

**#matlab**

#noisewhitening

Two noise vectors OF INFINITE LENGTH are mutually uncorrelated - taking 100 samples of two uncorrelated noise processes will not produce uncorrelated vectors..

More samples -> less correlation...

Thanks for the quick response. So that means for a real scenario we will never get a diagonal matrix. Fair enough!

While noise can certainly be uniform, was your intent to generate Gaussian noise instead? in MATLAB rand produces uniformly distributed data (between 0 and 1) while randn produces normally distributed data (with mean 0 and variance 1).

I *think* what you are really trying to compute can be accomplished as shown below. You can find the formula implemented by corrcoef in the documentation.

>> N = 1000; >> x = complex(rand(1,N),rand(1,N)); >> y = complex(rand(1,N),rand(1,N)); >> corrcoef(x,y) ans = 1.0000 + 0.0000i 0.0027 + 0.0130i 0.0027 - 0.0130i 1.0000 + 0.0000i

If you don't have access to corrcoef (can't recall if it requires a toolbox), you can compute from first principles as shown below. These are the off-diagonal elements of your covariance matrix. The diagonal elements are 1 by design.

>> num = dot(x-mean(x),y-mean(y)); >> den = sqrt(dot(x-mean(x),x-mean(x))*dot(y-mean(y),y-mean(y))); >> rho = num/den rho = 0.0027 + 0.0130i

As a final note, the terms correlation matrix and covariance matrix must be used cautiously when the mean of the underlying distributions is not zero.

Ya certainly my aim was to generate two gaussian noise sequences and show that they are uncorrelated then add some color to it afterwards and show that they are correlated. But the color seems to be added already :P

I checked out corrcoef function. It doesn't have any toolbox dependencies is what I see.

It appears my correlation matrix calculation has not been normalized to one and ofcourse the mean has to be shifted to zero. Using corrcoef did result in very small off-diagonal elements. But at this point your coefficient calculations are the perfect thing to follow :)

Thanks for your valuable points. Things are much more clear now. Highly appreciate it!

I believe rand(1,N) produces an 1 by N matrix of random numbers where each is uniformly distributed between 0 and 1. Why should the correlation of two non-zero mean vectors be zero?

Theoretically, the vectors should be gaussian distributed which should mean r1 and r2 are AWGN which further should imply that they are independent and hence r1 and r2 should be uncorrelated. But as dudelsound has mentioned lenght of the sequences should be infinite they are not uncorrelated.

From https://www.mathworks.com/help/matlab/ref/rand.htm

`X = rand`

returns a single uniformly distributed random number in the interval (0,1).

`X = rand(`

returns an `n`

)`n`

-by-`n`

matrix of random numbers.

`X = rand(`

returns an `sz1,...,szN`

)`sz1`

-by-...-by-`szN`

array of random numbers where `sz1,...,szN`

indicate the size of each dimension. For example, `rand(3,4)`

returns a 3-by-4 matrix.

It looks to me like each element of r1 and r2 will be uniformly distributed on [0,1] and for a long vector the mean will be about 1/2

Got your point. This makes sense. Sorry I didn't get your point earlier. Thanks!!

consider using:

corrMatrix = [ r1 ; r2 ]*[ r1.' , r2.' ]./N;

I tried using your expression but didn't see any difference. For complex vectors cross correlation, is hermetian transpose operation not needed? i.e. Rr1r2 = E[r1 r2'] (expectation)