Random numbers from complex PDF
4 ビュー (過去 30 日間)
古いコメントを表示
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/162135/image.png)
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 件のコメント
jgg
2016 年 4 月 21 日
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)
採用された回答
Roger Stafford
2016 年 4 月 21 日
編集済み: Roger Stafford
2016 年 4 月 21 日
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 件のコメント
その他の回答 (0 件)
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!