If XX has a uniform pdf from
00 to
11 (and zero elsewhere), and we
wish to generate YY using
Y=gX
Y
g
X
such that YY
has a Gaussian (normal) pdf of unit variance and zero mean, what is the required function
g.
g
.
?
(This function is often needed in computers, because standard random number generators tend to have uniform pdfs, while simulation of noise from the real world requires Gaussian pdfs.)
For these pdfs:
f
X
x={1 if 0≤x≤10 otherwise
f
X
x
1
0
x
1
0
(6)
f
Y
y=12πe−y22
f
Y
y
1
2
y
2
2
(7)
The corresponding cdfs are
F
X
x=∫−∞x
f
X
ud
u
={0 if x<0x if 0≤x≤11 if x>1
F
X
x
u
x
f
X
u
0
x
0
x
0
x
1
1
x
1
(8)
F
Y
y=∫−∞y
f
Y
ud
u
F
Y
y
u
y
f
Y
u
(9)
From our previous analysis, if
0≤g-1y≤1
0
g
y
1
F
Y
y=
F
X
g-1y=g-1y
F
Y
y
F
X
g
y
g
y
(10)
So,
g-1y=∫−∞y
f
Y
ud
u
g
y
u
y
f
Y
u
(11)
This integral has no analytic solution, so we cannot easily
invert this result to get
g.
g
.
. However a numerical (or graphical) solution is
shown in
Figure 2(a).
We can get an analytic solution to this problem as follows. If
we generate a 2-D Gaussian from polar coordinates, we need to
use two random variables to generate
rr and
θθ with the
correct distributions. In particular,
rr requires a Rayleigh
distribution which can be
integrated analytically and hence gives a relatively simple
analytic solution for
g.
g
.
.
Assuming we start with a uniform pdf from
00 to
11 as before,
generating θθ is easy as we
just scale the variable by
2π
2
to get random phases uniformly distributed from
00 to
2π
2
.
Once we have
rθ
r
θ
, we can convert to Cartesian components
x
1
x
2
x
1
x
2
to obtain two variables with Gaussian pdfs.
To generate rr correctly, we need
a Rayleigh pdf
f
R
r={re−r22 if r≥00 otherwise
f
R
r
r
r
2
2
r
0
0
(12)
So,
g-1y=∫−∞y
f
R
rd
r
=∫0yre−r22d
r
=−e−r22|0y=1−e−y22
g
y
r
y
f
R
r
r
0
y
r
r
2
2
0
y
r
2
2
1
y
2
2
(13)
To get
y=gx
y
g
x
, we just invert the formula for
x=g-1y
x
g
y
. Hence
x=1−e−y22
x
1
y
2
2
−y22=ln1−x
y
2
2
1
x
∀
x
,0≤x<1:y=gx=-2ln1−x
x
0
x
1
y
g
x
-2
1
x
(14)
This conversion is illustrated in
Figure 2(b).
Summarizing the complete algorithm:
-
Generate a 2-D random vector
x=(
x
1
x
2
)T
x
x
1
x
2
with uniform pdfs from
(
00
)T
0
0
to
(
11
)T
1
1
, by two calls to a standard random number generator function (e.g. rand() in Matlab; although this whole procedure is unnecessary in Matlab as there is already a Gaussian random generator, randn()).
-
Convert
x
1
x
1
into rr with
Rayleigh pdf using
r=g
x
1
=-2ln1−
x
1
r
g
x
1
-2
1
x
1
(15)
-
Convert
x
2
x
2
into θθ with
uniform pdf from 00 to
2π
2
using
-
Generate two independent random variables with Gaussian
pdfs of unit variance and zero mean using
y
1
=rcosθ
y
1
r
θ
and
y
2
=rsinθ
y
2
r
θ
-
Repeat steps 1 to 4 for each new pair of variables required.
y
1
y
1
and
y
2
y
2
may be scaled by
σσ to adjust their
variance, and an offset may be added in order to produce a
non-zero mean.