How should I understand this code

1 回表示 (過去 30 日間)
ZhG
ZhG 2013 年 6 月 14 日
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 件)

カテゴリ

Help Center および File ExchangeRandom Number Generation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by