0% found this document useful (0 votes)
1 views8 pages

Communications 4

The document outlines an experiment aimed at transforming random variables and deriving their probability density functions (PDFs) analytically, while also verifying the results through simulations using MATLAB R2024a. It covers various types of transformations, including univariate and multivariate cases, and provides MATLAB code for specific transformations such as Y=h^2, Y=h^3, Y=e^-h, Y=aX+b, and Z=X*Y. The conclusion emphasizes the learning outcomes regarding the derivation and simulation of PDFs for transformed random variables.

Uploaded by

nikkiant16
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views8 pages

Communications 4

The document outlines an experiment aimed at transforming random variables and deriving their probability density functions (PDFs) analytically, while also verifying the results through simulations using MATLAB R2024a. It covers various types of transformations, including univariate and multivariate cases, and provides MATLAB code for specific transformations such as Y=h^2, Y=h^3, Y=e^-h, Y=aX+b, and Z=X*Y. The conclusion emphasizes the learning outcomes regarding the derivation and simulation of PDFs for transformed random variables.

Uploaded by

nikkiant16
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

EXPERIMENT NO 4

AIM: To perform transformation of random variables.

OBJECTIVE: To derive the probability density function of the transformed random variable
analytically and verify the plot using the simulation

SOFTWARE USED: MATLAB R2024a version

THEORY:

The transformation of random variables refers to the process of finding the distribution of a new
random variable Y, which is a function of an original random variable X. This is a fundamental
concept in probability theory and statistics, commonly used when we want to analyze how
applying a function or transformation to a random variable affects its distribution.

Types of Transformations

1. Univariate Transformations (Single Random Variable): Consider a random variable X with a


known probability distribution, and let Y=g(X), where g is a function that transforms X into Y.

o Discrete Random Variables: For a discrete random variable XXX with probability mass
function P(X=x)), the new random variable Y=g(X) will have a probability mass function:

P(Y=y)=P(g(X)=y)
This involves determining the possible values of Y and summing the probabilities of the
corresponding X values.

o Continuous Random Variables: For a continuous random variable X with probability


density function (PDF) fX(x) and a transformation Y=g(X), the PDF of Y, denoted by fY(y) can be
derived using the change of variables formula, provided g is a monotonic function:

fY(y)=fX(g−1(y)⋅∣dg−1(y)/ dy∣

This method involves finding the inverse of g and adjusting for the scaling factor (derivative
of the inverse).

2. Multivariate Transformations (Joint Distributions of Multiple Variables): If X=(X1,X2,…,Xn)


is a vector of random variables, and we define a new vector of random variables Y=g(X) then the
transformation of the joint distribution involves more complex techniques like Jacobian
transformations for continuous variables. The probability density function of the transformed
variables is given by:

fY(y)=fX(x)⋅∣det(J(y))∣

where J is the Jacobian matrix of partial derivatives describing the transformation from X to Y
which is given by
CODE:

a. y=h2

%Code for transformed variable=h^2 where h is originally Rayleigh distributed


clc;
close all;
clear all;
x=0:0.1:10;
sigma=1;

%Analytically plotting the pdf of transformed rv


f=@(x) (1/2*sigma^2)*exp(-x/2*sigma^2);
p=plot(x,f(x));
p.LineWidth = 2;

%Simulation of transformed rv
hold on;
N=6000;
b=30;
h=random('Rayleigh',sigma,[1,N]);
transformed_variable=h.*h;
[ct,cn]=hist(transformed_variable,b);
A=trapz(cn,ct);
pdf=ct./A;
plot(cn,pdf,'*');
xlabel('Random variable x');
ylabel('f(x)');
title('Probability Density Function of transformed variable=h^2')
legend('Analytical','Simulated');
grid on;

b. y=h3

%Code for transformed variable=h^3 where h is originally Rayleigh distributed


clc;
close all;
clear all;
x=0:0.1:60;
sigma=0.99;

%Analytically plotting the pdf of transformed rv


f=@(x) (1./(3*(x.^(1/3)))*sigma.^2).*exp(-(x.^(2/3))/2.*sigma^2);
p=plot(x,f(x));
p.LineWidth = 2;

%Simulation of transformed rv
hold on;
N=5000;
b=30;
h=random('Rayleigh',sigma,[1,N]);
transformed_variable=(h.*h).*h;
[ct,cn]=hist(transformed_variable,b);
A=trapz(cn,ct);
pdf=ct./A;
plot(cn,pdf,'*');
xlabel('Random variable x');
ylabel('f(x)');
title('Probability Density Function of transformed variable=h^3')
legend('Analytical','Simulated');
grid on;

c. y=e-h

%Code for transformed variable=e^-h where h is originally Rayleigh distributed


clc;
close all;
clear all;
y=0.1:0.1:10;
sigma=1;

%Analytically plotting the pdf of transformed rv


pdf = (-log(y)) ./ (sigma^2 * y) .* exp(-(log(y)).^2 / (2 * sigma^2));
plot(y, pdf, 'LineWidth', 2);

%Simulation of transformed rv
hold on;
N=9000;
b=20;
h=random('Rayleigh',sigma,[1,N]);
transformed_variable=exp(-h);
[ct,cn]=hist(transformed_variable,b);
A=trapz(cn,ct);
pdf=ct./A;
plot(cn,pdf,'*');
xlabel('Random variable y');
ylabel('f(y)');
title('Probability Density Function of transformed variable=e^-h')
legend('Analytical','Simulated');
grid on;

d. Y=aX+b

%Code for transformed variable y=ax+b where x is originally Gaussian RV


clc;
close all;
clear all;
y=-5:0.1:10;
mu=0;
sigma=1;
a1=1;
b1=2;

%Analytically plotting the pdf of transformed rv


f=@(y) (1/(a1*sigma*sqrt(2*pi)))*exp(-((((y-b1)/a1)-mu).^2)/2*sigma.^2);
p=plot(y,f(y));
p.LineWidth = 2;

%Simulation of transformed rv
hold on;
N=6000;
b=20;
h=random('Normal',mu,sigma,[1,N]);
transformed_variable=(a1.*h)+b1;
[ct,cn]=hist(transformed_variable,b);
A=trapz(cn,ct);
pdf=ct./A;
plot(cn,pdf,'*');
xlabel('Random variable y');
ylabel('f(y)');
title('Probability Density Function of transformed variable=ax+b')
legend('Analytical','Simulated');
grid on;

e. Z=X*Y

%Code for Z=X*Y


mu=1;
sigma=4;
a1=2;
b1=4;

%simulation for computing pdf of product of two differenty distributed rv


N=10000;
b=20;
X=random('Uniform',a1,b1,[1,N]); %Generating X which is uniformly distributed
Y=random('Normal',mu,sigma,[1,N]); %Generating Y which is normally distributed
Z=X.*Y; %Multiplying two rvs
[ct,cn]=hist(Z,b);
A=trapz(cn,ct);
pdf=ct./A;
plot(cn,pdf,'LineWidth',2);
xlabel('Random variable Z');
ylabel('f(z)');
title('Probability Density Function of Z=X*Y')
grid on;
PLOTS

• y=h2

• y=h3
• y=e-h

• Y=aX+b
• Z=X*Y

CONCLUSION:

In this experiment, we learnt how to derive probability density function of a random variable if it is function of
another random variable of a certain distribution and plotted the respective analytical graphs and verified using
simulations.

You might also like