how to create a function that generates random numbers from a product of two exponential distribution ? (i.e. like gamrnd() is for gamma distribution)

38 次查看(过去 30 天)
I have a channel hsr from base station to IRS that follows complex normal distribution with zero mean and variance omegasr and another channel hr1 from IRS to user that also follows complex normal distribution with zero mean and variance omegar1, I want to generate random numbers for the distribution of square of mod of hsr*hr1 which I suppose would be the product of two exponential distribution

回答(2 个)

埃博拉酱
埃博拉酱 2024-11-3,9:07
You can use exprnd to get an exponentially distributed random variable.

Umar
Umar 2024-11-3,9:50

Hi @Mohd,

To achieve the desired outcome, set the variances for the two channels. Then, generate random samples from the complex normal distributions. Calculate the square of the modulus of the product of the two generated samples. Plot the histogram of the computed values to observe the distribution. Here is the complete MATLAB code that implements the above steps:

% Parameters
num_samples = 10000; % Number of random samples to generate
omega_sr = 1; % Variance for channel hsr
omega_r1 = 1; % Variance for channel hr1
% Step 1: Generate random samples from complex normal distributions
hsr = sqrt(omega_sr/2) * (randn(num_samples, 1) + 1i * randn(num_samples, 
1)); % hsr
hr1 = sqrt(omega_r1/2) * (randn(num_samples, 1) + 1i * randn(num_samples, 
1)); % hr1
% Step 2: Compute the product and its modulus squared
mod_squared_product = abs(hsr .* hr1).^2;
% Step 3: Visualize the results
figure;
histogram(mod_squared_product, 'Normalization', 'pdf');
title('Distribution of |hsr * hr1|^2');
xlabel('Value');
ylabel('Probability Density Function');
grid on;
% Step 4: Calculate theoretical distribution parameters
lambda_sr = 1/omega_sr; % Rate parameter for hsr
lambda_r1 = 1/omega_r1; % Rate parameter for hr1
% Theoretical PDF of the product of two exponential distributions
x = linspace(0, max(mod_squared_product), 1000);
theoretical_pdf = (lambda_sr * lambda_r1) * exp(-lambda_sr * x) .* exp(-  
lambda_r1 * x);
% Overlay theoretical PDF on histogram
hold on;
plot(x, theoretical_pdf, 'r-', 'LineWidth', 2);
legend('Simulated Data', 'Theoretical PDF');
hold off;

Please see attached.

In the above provided code snippet, the number of samples and the variances for both channels have been defined. The randn function generates samples from a standard normal distribution. For more guidance on this function, please refer to

https://www.mathworks.com/help/matlab/ref/randn.html

Then, scale these samples by the square root of half the variance to obtain complex normal samples. The modulus squared of the product is computed using the abs function, which returns the magnitude of the complex number. Finally, a histogram is plotted to visualize the distribution of the computed values. The theoretical probability density function (PDF) of the product of two exponential distributions is also calculated and overlaid on the histogram for comparison. By following the outlined steps, you can effectively simulate and visualize the desired distribution, enhancing your understanding of the underlying statistical properties.

Hope this helps.

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by