Random numbers from complex PDF
4 views (last 30 days)
Show older comments
Alex Kurek
on 21 Apr 2016
Edited: Roger Stafford
on 21 Apr 2016
Hi,
I need to generate random complex numbers. My PDF looks like this:
[X, Y] = meshgrid( span, span );
alfaJ = X + 1i*Y;
PDF = 1/(pi*(G-1)) * exp( -abs(alfaJ).^2 / (G-1) );
This PDF looks like this:
And I try to do this to get random numbers:
rePDF = sum(PDF, 1);
reSum = cumsum (rePDF); % is this CDF ok?
nearestRe = abs(reSum - rand);
nearestIm = abs(reSum - rand);
[~, A_Re] = min(nearestRe);
[~, A_Im] = min(nearestIm);
And finally I have:
A = A_Re + 1i*A_Im;
But histograms of A_Re and A_Im are not symetricall and generally i think those random numbers are to large. What is wrong? Is this approach not suited for complex numbers?
Cheers, Alex
2 Comments
jgg
on 21 Apr 2016
You don't seem to be using the covariance of the value when you compute your random numbers, which is why things are messed up. There's nothing special about complex numbers; this is equivalent to trying to sample from a multivariable distribution.
If you know this is normal with a given covariance, you can use mvnrnd.
If it's something else, the best way to do it would be to sample real number first, then using the conditional PDF, sample the complex number afterwards. You need to use use the conditional PDF, though, not the unconditional PDF (which I think is what's going on here)
Accepted Answer
Roger Stafford
on 21 Apr 2016
Edited: Roger Stafford
on 21 Apr 2016
The probability of lying inside a circle about the center with radius R in the X-Y plane is
P = 1-exp(-R^2/(G-1))
Therefore
R = sqrt(-(G-1)*log(1-P))
Consequently you can generate n random values for X and Y using the 'rand' function by:
R = sqrt(-(G-1)*log(rand(n,1)));
T = 2*pi*rand(n,1);
X = R.*cos(T);
Y = R.*sin(T);
Or you can express it as:
alpha = R.*exp(1i*T);
0 Comments
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!