Generating random noise in matlab
When I add Gaussian noise to an array sho开发者_高级运维uldnt the histogram be Gaussian? Although the noise is random, the distribution should be gaussian right? That is not what I get.
A=zeros(10);
A=imnoise(A,'gaussian');
imhist(A)
Two things could be going on:
You don't have enough of a sample size, or
The default mean of imnoise with gaussian distribution is 0, meaning you're only seeing the right half of the bell curve.
Try
imhist(imnoise(zeros(1000), 'gaussian', 0.5));
This is what your code is doing:
A = zeros(10);
mu = 0; sd = 0.1; %# mean, std dev
B = A + randn(size(A))*sd + mu; %# add gaussian noise
B = max(0,min(B,1)); %# make sure that 0 <= B <= 1
imhist(B) %# intensities histogram
can you see where the problem is? (Hint: RANDN returns number ~N(0,1)
, thus the resulting added noise is ~N(mu,sd)
)
Perhaps what you are trying to do is:
hist( randn(1000,1) )
imnoise() is a function that can be applied to images, not plain arrays.
Maybe you can look into the randn() function, instead.
You might not see a bell-curve with a sampling frame of only 10.
See the central limit theorem.
http://en.wikipedia.org/wiki/Central_limit_theorem
I would try increasing the sampling frame to something much larger.
Reference:
Law of Large Numbers
http://en.wikipedia.org/wiki/Law_of_large_numbers
精彩评论