Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

clear all;

xx = [0:0.5:7]; % Define range of values for x


N = 10^6; % Number of samples
xi = 10/log(10); % Conversion factor for dB to linear scale

% Define mu and sigma values for each case (modify as needed)


mu_dB_1 = 4;
sigma_dB_1 = 8;
mu_dB_2 = 8;
sigma_dB_2 = 4;
mu_dB_3 = 5;
sigma_dB_3 = 5;
mu_dB_4 = 10;
sigma_dB_4 = 10;

% Convert dB values to linear scale


mu_1 = 10^(mu_dB_1/10);
sigma_1 = 10^(sigma_dB_1/10);
mu_2 = 10^(mu_dB_2/10);
sigma_2 = 10^(sigma_dB_2/10);
mu_3 = 10^(mu_dB_3/10);
sigma_3 = 10^(sigma_dB_3/10);
mu_4 = 10^(mu_dB_4/10);
sigma_4 = 10^(sigma_dB_4/10);

% Generate lognormal random variables for each case


RV_1 = lognrnd(mu_1./xi,sigma_1./xi,1,N);
RV_2 = lognrnd(mu_2./xi,sigma_2./xi,1,N);
RV_3 = lognrnd(mu_3./xi,sigma_3./xi,1,N);
RV_4 = lognrnd(mu_4./xi,sigma_4./xi,1,N);

% Calculate the CDFs using the built-in function


CDF_1 = logncdf(xx, mu_1, sigma_1);
CDF_2 = logncdf(xx, mu_2, sigma_2);
CDF_3 = logncdf(xx, mu_3, sigma_3);
CDF_4 = logncdf(xx, mu_4, sigma_4);
% Theoretical CDF (for comparison)
CDF_LT_1= qfunc((mu_1-10.*log10(xx)./sigma_1));
CDF_LT_2= qfunc((mu_2-10.*log10(xx)./sigma_2));
CDF_LT_3= qfunc((mu_3-10.*log10(xx)./sigma_3));
CDF_LT_4= qfunc((mu_4-10.*log10(xx)./sigma_4));

% Plot the results


hold on;
plot(xx,CDF_1,'black-', 'DisplayName', 'mu = 4 dB, sigma = 8 dB, Simulation');
plot(xx,CDF_LT_1,'blacko','DisplayName','mu = 4 dB, sigma = 8 dB, Theory');
plot(xx,CDF_2,'blue-', 'DisplayName', 'mu = 8 dB, sigma = 4 dB, Simulation');
plot(xx,CDF_LT_2,'blue*','DisplayName','mu = 8 dB, sigma = 4 dB, Theory');
plot(xx,CDF_3,'g-', 'DisplayName', 'mu = 5 dB, sigma = 5 dB, Simulation');
plot(xx,CDF_LT_3,'g+','DisplayName','mu = 5 dB, sigma = 5 dB, Theory');
plot(xx,CDF_4,'r-', 'DisplayName', 'mu = 10 dB, sigma = 10 dB, Simulation');
plot(xx,CDF_LT_4,'rd','DisplayName','mu = 10 dB, sigma = 10 dB, Theory');
legend('show');
xlabel('x');
ylabel('CDF');
title('log-normal CDFs');

You might also like