Filter löschen
Filter löschen

How should I understand this code

3 Ansichten (letzte 30 Tage)
ZhG
ZhG am 14 Jun. 2013
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.

Akzeptierte Antwort

Wayne King
Wayne King am 14 Jun. 2013
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 Kommentar
ZhG
ZhG am 14 Jun. 2013
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by