comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Normal Distributed Random Numbers
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Normal Distributed Random Numbers [message #26517] Tue, 04 September 2001 14:34
thompson is currently offline  thompson
Messages: 584
Registered: August 1991
Senior Member
"Kay Bente" <KBente@lycos.de> writes:

> Hi
> I have to create arrays with normal distributed random numbers, but with
> variable FWHM (Full width half max/standard deviation sigma?).
> I want to add normal distributed noise to an image, so that the values
> differ around a mean value.
> In IDL there is a procedure to create such arrays RandomN, but you can't
> change the FWHM and I can't find what FWHM the normal distribution there
> has.

> So I would be glad If somone can tell me how to create such arrays (maybe
> outof uniform distributed arrays created with RandomU, I have no idea.
> I'm using IDL 5.4

The RANDOMN() function creates a Gaussian distribution with an average of 0,
and a standard deviation of 1. Mathematically, this is written as

EXP(-0.5*X^2)

If you want a different distribution, e.g. a different average or a different
standard deviation, all you need to do is something

RanVals = AvgVal + Sigma*RANDOMN(Seed, Num)

For example,

RanVals = 500 + 3*RANDOMN(Seed, 10000)

would produce a bunch of random numbers with an average value of 500, and a
standard deviation of 3. In other words, most of the numbers would be between
497 and 503.

(The FWHM of this distribution is 2*Sigma*SQRT(2*ALOG(2)), or about 2.35*Sigma,
but I suspect you're really thinking about the standard deviation Sigma rather
than the FWHM.)

William Thompson
Re: Normal Distributed Random Numbers [message #26518 is a reply to message #26517] Tue, 04 September 2001 14:24 Go to previous message
James Kuyper is currently offline  James Kuyper
Messages: 425
Registered: March 2000
Senior Member
Kay Bente wrote:
>
> Hi
> I have to create arrays with normal distributed random numbers, but with
> variable FWHM (Full width half max/standard deviation sigma?).
> I want to add normal distributed noise to an image, so that the values
> differ around a mean value.
> In IDL there is a procedure to create such arrays RandomN, but you can�t
> change the FWHM and I can�t find what FWHM the normal distribution there
> has.

For a normal distribution, FWHM = 2*sqrt(alog(2))*(standard deviation)

RandomN produces a distribution with a mean of 0 and a standard
deviation of 1.0. Therefore, to create an array with a desired mean
value and a desired value for FWHM, use:

array = mean + fwhm*RandomN(Seed, N)/(2*sqrt(alog(2)))
Re: Normal Distributed Random Numbers [message #26519 is a reply to message #26518] Tue, 04 September 2001 14:04 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
"Kay Bente" <KBente@lycos.de> writes:

> Hi
> I have to create arrays with normal distributed random numbers, but with
> variable FWHM (Full width half max/standard deviation sigma?).
> I want to add normal distributed noise to an image, so that the values
> differ around a mean value.
> In IDL there is a procedure to create such arrays RandomN, but you can�t
> change the FWHM and I can�t find what FWHM the normal distribution there
> has.

From the IDL Reference Guide:

> The RANDOMN function returns one or more normally-distributed,
> floating-point, pseudo-random numbers with a mean of zero and a
> standard deviation of one.

So there you go, the deviates produced by RANDOMN have a gaussian
sigma of 1, like this:

S = RANDOMN(SEED, 1000)

And then it's well established for a gaussian distribution that if you
want a new mean, MU, and new gaussian sigma, SIG, then you would apply
the following formula:

SPRIME = S*SIG + MU

And, knowing that gaussian sigma is approximately SIG = FWHM / 2.35,
you are set. The key here is that SIG can be an array, not just a
scalar, so you can have a different value of SIG (and hence FWHM) for
each pixel.

Good luck,
Craig

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Normal Distributed Random Numbers
Next Topic: Speed penalty using START and COUNT with HDF_SD_GETDATA

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 17:03:02 PDT 2025

Total time taken to generate the page: 0.00698 seconds