How should I understand this code

3 次查看(过去 30 天)
Hello,
I have a code segment of generating gaussian noise, but I don't understand why it does so.
p=1+rand(1)*99; Gaussian_noise=rand(n,m)*(p-50);
rand(1) generates a 1-by-1 matrix from uniform distribution [0 1], right? but why it multiply a 99? And then it generate a matrix as the same size of an image I(n,m) And then subtract 50 and multiply again
Thanks.

采纳的回答

Wayne King
Wayne King 2013-6-14
This does not look like it produces white Gaussian noise. For example:
n = 1000;
m = 1;
p=1+rand(1)*99; Gaussian_noise=rand(n,m)*(p-50);
hist(Gaussian_noise)
figure;
qqplot(Gaussian_noise)
Just use randn()
If you want a matrix of Gaussian white noise
X = randn(256,256);
That is zero mean, variance 1. Add a constant and scale to obtain a different mean and variance.
  1 个评论
ZhG
ZhG 2013-6-14
Thanks very much Wayne, but I just don't understand as well. Is this knowledge from Signal Processing.
rand(1) or rand(n,1) generates data set of uninform distribution in the interval (0,1) It multiplys 99, then it maps this interval to (0,99), right? But why it plus an extra 1? And for the second line, Gaussian_noise = rand(n,m) * (p-50), I just don't understand it completely.

请先登录,再进行评论。

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by