simple quastion about randn and mean of random noise

2 views (last 30 days)
hi, i'm a bit confused and need your help.
i know that mean(sum(n))=sum(mean(n)) where n is a random noise with zero mean and N0 variance.
but when im writing : n=randn(1000,1)
mean(sum(n))=-32.... sum(mean(n))=~0
whats the diference and how its get along with E(sum(n))=sum(E(n))??
thanks in advance...

Accepted Answer

Rick Rosson
Rick Rosson on 28 Jul 2011
The variable n is a column vector of 1000 instances of a Random Variable of mean 0 and variance 1.
In the first case, if you take the sum of a column vector, it returns a single value, which is simply the sum across all 1000 elements of the column vector. If you take the mean of a single value, you will get the value itself, which in this case is ~32.
In the second case, if you take the mean of 1000 values, it will return a single value that represents the arithmetic average of those 1000 values. Since you generated them from a Random Variable with mean 0, it should be approximately 0. If you then sum across that single value, you will again get the same value, which is ~0.
So the results you are describing are expected.
I think what you may want to do is to create a matrix of randomly generated values, and then try the same experiment where you treat each column of the matrix as a separate trial, with each trial drawing 1000 values from your random variable.
So please try the following:
X = randn(1000,200);
and then repeat the test.
HTH.
Rick
  5 Comments
Matt Tearle
Matt Tearle on 28 Jul 2011
sorry, not sure what you mean by "add noise to a signal in length 10". in terms of signals, i guess you'd think of X as 200 signals, each of 1000 samples. (if that helps)

Sign in to comment.

More Answers (2)

Matt Tearle
Matt Tearle on 28 Jul 2011
n = randn(1000,1) creates a vector (1000-by-1), so sum(n) is the sum of the thousand random numbers. Taking the mean is then the mean of a single value (ie the value itself).
Similarly, mean(n) calculates the mean of the 1000 numbers (should be about 0), then sum adds that one number.
Perhaps you wanted to do n = randn(1000); instead? Then mean(sum(n)) and sum(mean(n)) will be equal to within roundoff.

the cyclist
the cyclist on 28 Jul 2011
I believe that the first mathematical statement you wrote is intended to be a statement about two different distributions. The MATLAB code you wrote was just one instance, so I am not sure how helpful that is.
Here is some code that might help you visualize what is going on. It is related to what Rick wrote. The math statement seems intuitively correct to me, but I'd have to think carefully about it. My code suggests that the two sides of the equation do not actually have the same distribution.
NTIMES_TO_TEST = 2000;
SAMPLESIZE = 1000;
NTRIALS_OF_SAMPLE = 500;
[meansum,summean] = deal(nan(NTIMES_TO_TEST,1));
for nt = 1:NTIMES_TO_TEST
if round(nt/100)==(nt/100)
disp(['Iteration: ',num2str(nt),' out of ',num2str(NTIMES_TO_TEST)])
end
r1 = randn(SAMPLESIZE,NTRIALS_OF_SAMPLE);
r2 = randn(SAMPLESIZE,NTRIALS_OF_SAMPLE);
meansum(nt) = mean(sum(r1));
summean(nt) = sum(mean(r1));
end
NBINS = 25;
figure
subplot(2,1,1), hist(meansum,NBINS)
set(gca,'XLim',[-4 4])
title('Distribution of mean of sum')
subplot(2,1,2), hist(summean,NBINS)
set(gca,'XLim',[-4 4])
title('Distribution of sum of mean')

Community Treasure Hunt

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

Start Hunting!