8 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;

Image Analyst
on 26 Nov 2020

Image Analyst
on 26 Nov 2020

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.

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
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:

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

Start Hunting!
## 0 Comments

Sign in to comment.