Re: rician random number

• To: mathgroup at smc.vnet.net
• Subject: [mg15145] Re: [mg15117] rician random number
• From: BobHanlon at aol.com
• Date: Wed, 16 Dec 1998 03:11:19 -0500
• Sender: owner-wri-mathgroup at wolfram.com

```In a message dated 12/12/98 7:21:11 AM, gcseng at yahoo.com writes:

>Anyone knows how to generate random number base on the rician
>probability density function.
>
>The rician pdf is given by:
>
>f(r)=(r/sigma^2)*exp(1)^(-1*(r^2+A^2)/(2*sigma^2))*Io(r*A/sigma^2)
>
>where 2*sigma^2 is the average power in the scatter component of the
>fade, and Io(.) is the modified Bessel function of the first kind and
>zeroth order.
>

See the notebook below.

Bob Hanlon
_____________________

Notebook[{
Cell["Needs[\"Statistics`ContinuousDistributions`\"];", "Input"],

Cell[TextData[{
"Unprotect[RicianDistribution];\nClear[RicianDistribution];\n\
RicianDistribution::\"usage\" = \n  \"RicianDistribution[A, \[Sigma]] \
represents the continuous Rician\n  distribution (also known as
Nakagami-Rice \
or n-distribution)\n  with parameters A and \[Sigma].  Special case:
Rayleigh \
(A\[NonBreakingSpace]= 0).\";\nRicianDistribution/: \n\t",
StyleBox["Domain",
FontColor->RGBColor[0, 0, 1]],
"[RicianDistribution[___]] := \n\t\tInterval[{0, Infinity}];\n\
RicianDistribution/: \n\t",
StyleBox["PDF",
FontColor->RGBColor[0, 0, 1]],
"[RicianDistribution[A_, \[Sigma]_], r_ /; !Positive[r]] := 0;\n\
RicianDistribution/: \n\t",
StyleBox["PDF",
FontColor->RGBColor[0, 0, 1]],
"[RicianDistribution[A_, \[Sigma]_], r_] :=\n\t\t\
(r/\[Sigma]^2)*Exp[-(r^2+A^2)/(2*\[Sigma]^2)]*BesselI[0,
r*A/\[Sigma]^2];\n\ RicianDistribution/: \n\t",
StyleBox["Moment",
FontColor->RGBColor[0, 0, 1]],
"[RicianDistribution[A_, \[Sigma]_], n_] := \n\t\t2^(n/2) \[Sigma]^n \
Gamma[1 + n/2] * \n\t\tLaguerreL[n/2, -A^2/(2 \[Sigma]^2)];\n\
RicianDistribution/: \n\t",
StyleBox["Mean",
FontColor->RGBColor[0, 0, 1]],
"[RicianDistribution[A_, \[Sigma]_]] := \n\t\t\
Evaluate[Moment[RicianDistribution[A, \[Sigma]],
1]];\nRicianDistribution/: \n\
\t",
StyleBox["Variance",
FontColor->RGBColor[0, 0, 1]],
"[RicianDistribution[A_, \[Sigma]_]] :=
\n\t\tEvaluate[Simplify[\n\t\t\t\ Moment[RicianDistribution[A,
\[Sigma]], 2] - \n\t\t\t\ Mean[RicianDistribution[A,
\[Sigma]]]^2]];\nRicianDistribution/: \n\t",
StyleBox["StandardDeviation",
FontColor->RGBColor[0, 0, 1]],
"[RicianDistribution[A_, \[Sigma]_]] := \n\t\t\
Evaluate[Sqrt[Variance[RicianDistribution[A, \[Sigma]]]]];\n\
RicianDistribution/: \n\t",
StyleBox["GeneralizedMean",
FontColor->RGBColor[0, 0, 1]],
"[RicianDistribution[A_, \[Sigma]_], t_] := \n\t\tSqrt[2] \[Sigma]
(Gamma[1 \
+ t/2] * \n\t\tLaguerreL[t/2, -A^2/(2 \[Sigma]^2)])^(1/t);\n\
RicianDistribution/: \n\t",
StyleBox["HarmonicMean",
FontColor->RGBColor[0, 0, 1]],
"[RicianDistribution[A_, \[Sigma]_]] := Evaluate[\n\t\t\
GeneralizedMean[RicianDistribution[A, \[Sigma]],
-1]];\nRicianDistribution/: \ \n\t",
StyleBox["GeometricMean",
FontColor->RGBColor[0, 0, 1]],
"[RicianDistribution[A_, \[Sigma]_]] := \n\t\tA*Exp[1/2*Gamma[0,
A^2/(2*\ \[Sigma]^2)]];\nRicianDistribution/: \n\t",
StyleBox["CDF",
FontColor->RGBColor[0, 0, 1]],
"[RicianDistribution[A_, \[Sigma]_], r_ /; !Positive[r]] := 0;\n\
RicianDistribution/: \n\t",
StyleBox["CDF",
FontColor->RGBColor[0, 0, 1]],
"[RicianDistribution[A_ /; A == 0, \[Sigma]_], r_] := \n\t\t1 - \
Exp[-(r^2/(2*\[Sigma]^2))]; (* Rayleigh *)\nRicianDistribution/: \n\t",
StyleBox["CDF",
FontColor->RGBColor[0, 0, 1]],
"[RicianDistribution[A_ /; A > 0, \n\t\t\[Sigma]_ /; \[Sigma] > 0], \
r_?NumericQ] := \n\t\tNIntegrate[PDF[RicianDistribution[A, \[Sigma]],
x], \n\t\
\t{x, 0, r}];\nRicianDistribution/: \n\t",
StyleBox["InverseCDF",
FontColor->RGBColor[0, 0, 1]],
"[RicianDistribution[A_ /; A == 0, \[Sigma]_], x_] := \n\t\t-I
\[Sigma] \ Sqrt[2 Log[1 - x]]; (* Rayleigh *)\nRicianDistribution/:
\n\t",
StyleBox["InverseCDF",
FontColor->RGBColor[0, 0, 1]],
"[RicianDistribution[A_ /; A > 0, \n\t\t\[Sigma]_ /; \[Sigma]  >0], x_
/; x \
== 0] := 0;\nRicianDistribution/: \n\t",
StyleBox["InverseCDF",
FontColor->RGBColor[0, 0, 1]],
"[RicianDistribution[A_ /; A > 0, \n\t\t\[Sigma]_ /; \[Sigma] > 0], x_
/; 0 \
< x < 1] := \n\t\tModule[{\[Mu] = Mean[RicianDistribution[A,
\[Sigma]]]}, \n\t\
\tr /. FindRoot[CDF[RicianDistribution[A, \[Sigma]], r] == x, \n\t\t{r,
0.9*\ \[Mu], 1.1*\[Mu]}]];\nRicianDistribution/: \n\t",
StyleBox["CharacteristicFunction",
FontColor->RGBColor[0, 0, 1]],
"[\n\t\tRicianDistribution[A_ /; A == 0, \[Sigma]_], t_] := \n\t\t\
Evaluate[CharacteristicFunction[\n\t\t\tRayleighDistribution[\[Sigma]],
t]];\n\
RicianDistribution/: \n\t",
StyleBox["Random",
FontColor->RGBColor[0, 0, 1]],
"[RicianDistribution[A_ /; A > 0, \[Sigma]_ /; \[Sigma] > 0]] :=
\n\t\t\ Sqrt[Random[NormalDistribution[A/Sqrt[2], \[Sigma]]]^2 +
\n\t\t\ Random[NormalDistribution[A/Sqrt[2],
\[Sigma]]]^2];\nRicianDistribution/: \n\t\ ",
StyleBox["RandomArray",
FontColor->RGBColor[0, 0, 1]],
"[RicianDistribution[\n\t\tA_ /; A > 0, \[Sigma]_ /; \[Sigma] > 0], \
n_Integer] :=\n  \t\tTable[Random[RicianDistribution[A, \[Sigma]]],
{n}];\n\ SetAttributes[RicianDistribution, ReadProtected];\n\
Protect[RicianDistribution];"
}], "Input"],

Cell[CellGroupData[{

Cell[TextData["PDF[RicianDistribution[A, \[Sigma]], r]"], "Input"],

Cell[BoxData[
\(TraditionalForm
\`\(\[ExponentialE]\^\(-\(\(A\^2 + r\^2\)\/\(2\ \[Sigma]\^2\)\)\)\
r\
\(\(I\_0\)(\(A\ r\)\/\[Sigma]\^2)\)\)\/\[Sigma]\^2\)], "Output"]
}, Open  ]],

Cell[CellGroupData[{

Cell[TextData[{
StyleBox["You can generate a Rician distribution by\n\n\tR = ",
"Text"],
Cell[BoxData[
\(TraditionalForm\`\ at \(X1\^2 + \ X2\^2\)\)]],
StyleBox["\n\t\nwhere X1 and X2 are Normal(", "Text"],
Cell[BoxData[
\(TraditionalForm\`A\/\ at 2\)]],
StyleBox[", \[Sigma])", "Text"]
}], "Text"],

Cell[CellGroupData[{

Cell["\<\
a = 1.; s = 1.3;
StringForm[\"Mean = ``, HarmonicMean = ``, \tGeometricMean = ``,
Variance = ``\", \tMean[RicianDistribution[a, s]],
\tHarmonicMean[RicianDistribution[a, s]],
\tGeometricMean[RicianDistribution[a, s]],
\tVariance[RicianDistribution[a, s]]]\ \>", "Input"],

Cell[BoxData[
FormBox[
InterpretationBox[
"\<\"Mean = \\!\\(TraditionalForm\\`1.86183681097358029`\\), \
HarmonicMean = \\!\\(TraditionalForm\\`1.19606693921935125`\\),
GeometricMean \
= \\!\\(TraditionalForm\\`1.58090709532633084`\\), Variance = \
\\!\\(TraditionalForm\\`0.91356368930372831`\\)\"\>",
StringForm[
"Mean = ``, HarmonicMean = ``, GeometricMean = ``, Variance =
``",
1.8618368109735803, 1.1960669392193513, 1.5809070953263309,
0.91356368930372822],
Editable->False], TraditionalForm]], "Output"] }, Open  ]],

Cell[CellGroupData[{

Cell["\<\
data = RandomArray[RicianDistribution[a, s], 100]; StringForm[\"Mean =
``, HarmonicMean = ``, \tGeometricMean = ``, Variance = ``\",
\tMean[data], HarmonicMean[data],
\tGeometricMean[data], Variance[data]]\ \>", "Input"],

Cell[BoxData[
FormBox[
InterpretationBox[
"\<\"Mean = \\!\\(TraditionalForm\\`1.95989245581850539`\\), \
HarmonicMean = \\!\\(TraditionalForm\\`1.21310954273725202`\\),
GeometricMean \
= \\!\\(TraditionalForm\\`1.6096711243730823`\\), Variance = \
\\!\\(TraditionalForm\\`1.17650576601308132`\\)\"\>",
StringForm[
"Mean = ``, HarmonicMean = ``, GeometricMean = ``, Variance =
``",
1.9598924558185054, 1.213109542737252, 1.6096711243730824,
1.1765057660130813],
Editable->False], TraditionalForm]], "Output"] }, Open  ]] },
Open  ]],

Cell["\<\
Plot[{PDF[RicianDistribution[a, s], r],  \tCDF[RicianDistribution[a, s],
r]}, {r, 0, 5},  \tPlotRange -> All];\ \>", "Input"]
},
FrontEndVersion->"Macintosh 3.0",
ScreenRectangle->{{0, 1024}, {0, 748}}, CellGrouping->Manual,
WindowSize->{611, 709},
WindowMargins->{{204, Automatic}, {Automatic, 0}}, ShowCellLabel->False,
MacintoshSystemPageSetup->"\<\
00<0001804P000000]P2:?oQon82n at 960dL5:0?l0080001804P000000]P2:001
0000I00000400`<300000BL?00400 at 0000000000000006P801T1T00000000000
00000000000000000000000000000000\>"
]

```

• Prev by Date: Mathlink and Visual C++
• Next by Date: Bug with ComplexExpand on PolyGamma?
• Previous by thread: RE: rician random number
• Next by thread: Re: rician random number