How to generate two independent white noise
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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;
0 commentaires
Réponses (2)
Image Analyst
le 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 commentaires
Image Analyst
le 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.
Paul Hoffrichter
le 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 commentaires
Paul Hoffrichter
le 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
le 27 Nov 2020
If you use instead of the plot line:
semilogx(rmean)
you can see a better view of the approach towards 0:
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!