1
$\begingroup$
  1. rand() is for "Uniformly distributed pseudorandom numbers"

    I generate two rand arrays, and then use the cross-correlation (xcorr2) and the normalized cross correlation (normxcorr2) as follows:

    a = rand(512,512);
    b = rand(512,512);
    c = xcorr2(a,b);
    figure;surf(c);shading flat;axis tight;
    d = normxcorr2(a,b);
    figure;surf(d);shading flat;axis tight;
    

    The results are as follows:

    xcorr2 normxcorrs

    in which there is strong correlation in the xcorr2().

  2. randn() is for "Normally distributed pseudorandom numbers"

    The same as the above:

    a = randn(512,512);
    b = randn(512,512);
    c = xcorr2(a,b);
    figure;surf(c);shading flat;axis tight;
    d = normxcorr2(a,b);
    figure;surf(d);shading flat;axis tight;
    

    and the results are:

    xcorr2 normxcorr2

Then, my question is why there is apparent difference of xcorr2() for the two random data?

$\endgroup$
2
$\begingroup$

The reason for the difference is that rand() has an output range of $[0,1]$, and therefore you have a constant in both $a$ and $b$ in the first example. The other function randn() generates an output with zero mean. The constants are correlated. Try

a = -0.5 + rand(512,512);
b = -0.5 + rand(512,512);

or

a = rand(512,512);
b = rand(512,512);
a = detrend(a,'constant');
b = detrend(b,'constant');

and see if that is more like what you would expect...

$\endgroup$
1
  • 1
    $\begingroup$ Thank you, you are right. it is the cross correlation of the two dc signals. $\endgroup$ – lxg May 29 '16 at 7:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.