How to generate two independent white noise

7 views (last 30 days)
Hello everyone. I am trying to generate two independent and uniformly distributed white noise e(t) and u(t) wich have "mean = 0" and "variance = 1". Since they are independent, their cross-correlation must be "0" for all time lags theoretically. So i have succesfully (i think) generated two white noises with "N = 100" samples using "rand" function but when i put them in "xcorr" function and plot the cross-correlation graphic, the values are not close to zero. Increasing the number of samples "N" does not get them closer to "0" (because i failed to satisfy independency i guess). Below is the code i wrote. Any help is much appreciated. Thank you.
N = 100; %number of samples
u = (2*rand(N, 1)-1)*sqrt(3);
e = (2*rand(N, 1)-1)*sqrt(3);
[ccf, lags] = xcorr(e, u);
figure();
stem(lags, ccf);
title('Cross Corelation of (eu)')
xlabel('Samples')
ylabel('Sample Values')
grid on;

Answers (2)

Image Analyst
Image Analyst on 26 Nov 2020
You say "Since they are independent, their cross-correlation must be "0" for all time lags theoretically." This is incorrect. Averaged over all shifts (lags) the average correlation should be zero, but this does not mean that for any given shift the product of all overlapping terms, then summed together, will give you zero. Why do you think it should? It should not, and it doesn't, which proves it, as expected.
  2 Comments
Mustafa Enes KIRMACI
Mustafa Enes KIRMACI on 26 Nov 2020
Thank you for fast response and correcting my knowledge. So can i prove that they are independent by taking the mean of the sample values? (like mean(ccf) for this code) If the mean value approaches to "0" by increasing the number of samples "N" does that mean they are independent? If not how can i prove it? Sorry if that is a silly question.
Image Analyst
Image Analyst on 26 Nov 2020
Just try it. Experiment around. You'll see that if you take the mean of ccf, it should be very small near zero. And if you increase N, the values of ccf will also increase.

Sign in to comment.


Paul Hoffrichter
Paul Hoffrichter on 26 Nov 2020
An easy way to think about the mean over a sample not being what you expected is to consider a fair coin having a head (H, give it a value = 1) and a tail (T, give it a value = -1). I think you will agree that the mean of flipping the coin an infinite amout of times is 0 = (1/2) * (+1) + (1/2) * (-1) = (1/2) + (-1/2) = 0.
But flip the coin only 20000 times. You would not expect exactly 10000 heads and 10000 tails. In any number of flips you rarely would get an equal number of heads and tails. So the average of the flips would usually not be zero.
  3 Comments
Paul Hoffrichter
Paul Hoffrichter on 27 Nov 2020
Here is a little script to try out.
N = 10:10:5e5;
r = [];
for ii = N
r = [ r 2*(randi([0 1]) - 0.5)];
rmean(ii) = mean(r);
end
plot(rmean); ylim( [-.04 +.04] )
One run produces:
Paul Hoffrichter
Paul Hoffrichter on 27 Nov 2020
If you use instead of the plot line:
semilogx(rmean)
you can see a better view of the approach towards 0:

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!