Computer Assignment 5
EC2010 Probabilistic Analysis of Signals and Systems (3-1)
Sums of Random Variables and Central Limit Theorem
Capt Joseph Kronlage USMC – Capt Phillip Graham USMC – LTJG Vasileios
Koulountzos HN
Report Summary
The objective of this project is to empirically study the sums of random variables and
demonstrate the Central Limit Theorem (CLT). We will generate Gaussian random
variables using uniform and exponential random variables. By computing the
probability density function (PDF) and cumulative distribution function (CDF), we will
observe how the distributions approach the Gaussian shape.
This report presents the experimental setup, calculations, and results obtained for
different random variable summations.
Part 1: Discussion of Results
1. Analysis of Summed Uniform Random Variables
We generate six sequences of uniform random variables in the range [-0.5, 0.5],
each with 10,000 samples. Using these sequences, we define two new random
variables:
a) PDF and CDF Estimation
To estimate the PDF and CDF, we construct histograms with 25 bins and
normalize them, producing the plots illustrated in Figures 1 through 4.
We observe that:
The shape of the empirical PDF of Y1 (Figure-1) closely resembles a
Gaussian distribution due to the CLT.
Figure-1: PDF of Random Variable Y1
The PDF of Y2 (Figure-2) also resembles a Gaussian shape but is
skewed due to the differing weights assigned to each.
Figure-2: PDF of Random Variable Y2
The CDF of both distributions (Figure-3 and Figure-4) align well with
the theoretical Gaussian CDF.
Figure-3: CDF of Random Variable Y1
Figure-4: CDF of Random Variable Y2
b) Mean and Variance Estimation
Theoretically, for Y1:
6
𝐸[𝑌1 ] = ∑ 𝐸[𝑋𝑖 ] = 6 ⋅ (0) = 0
𝑖 =1
6
𝑉𝑎𝑟[𝑌1 ] = ∑ 𝑉𝑎𝑟[𝑋𝑖 ] = 6 ⋅ (
𝑖 =1
1
1
)=
12
2
Empirical estimates are computed in MATLAB and closely match
theoretical values, as it is presented in the following Figure-5.
For Y2, the theoretical mean and variance are computed as:
𝐸[𝑌2 ] = 𝐸[𝑋1 ] + 0.5 ⋅ 𝐸[𝑋2 ] + 0.8 ⋅ 𝐸[𝑋3 ] + 1.8 ⋅ 𝐸[𝑋4 ] + 0.3 ⋅ 𝐸[𝑋5 ]
+ 0.5 ⋅ 𝐸[𝑋6 ] = 0
𝑉𝑎𝑟[𝑌2 ] = 𝑉𝑎𝑟[𝑋1 ] + 0.52 ⋅ 𝑉𝑎𝑟[𝑋2 ] + 0.82 ⋅ 𝑉𝑎𝑟[𝑋3 ] + 1.82 ⋅ 𝑉𝑎𝑟[𝑋4 ]
+0.32 ⋅ 𝑉𝑎𝑟[𝑋5 ] + 0.52 ⋅ 𝑉𝑎𝑟[𝑋6 ] = 0.5
The computed values confirm the expected behavior, as it is
presented in the following Figure-5.
Figure-5: Mean and Variance Matlab Computations
c) Comparison to Gaussian Distribution
By overlaying a theoretical Gaussian curve (matching the empirical mean
and variance) onto the estimated PDFs and CDFs:
The distributions approximate a Gaussian shape.
Y1 follows a more symmetric Gaussian shape due to equal weighting
(Figure-1 and Figure-3).
Y2 exhibits some skewness due to its weighted summation (Figure-2 and
Figure-4).
2. Analysis of Summed Exponential Random Variables
We generate 20 sequences of IID exponential random variables with
𝜆𝑖 = 0.5𝑖 parameters. The sum of these variables is analyzed:
a) PDF and CDF Estimation
The PDF of 𝑌𝑒𝑥𝑝 exhibits a bell shape, validating the CLT (Figure-6).
Figure-6: PDF of Random Variable 𝑌𝑒𝑥𝑝
The empirical CDF closely matches the Gaussian CDF (Figure-7).
Figure-7: CDF of Random Variable 𝑌𝑒𝑥𝑝
b) Mean and Variance Estimation
The theoretical mean and variance for 𝑌𝑒𝑥𝑝 are given by:
20
𝐸[𝑌𝑒𝑥𝑝 ] = ∑
𝑖 =1
1
𝜆𝑖
20
1
𝑉𝑎𝑟[𝑌𝑒𝑥𝑝 ] = ∑ 2
𝜆𝑖
𝑖 =1
Where the exponential distribution rate parameter 𝜆𝑖 is given as 𝜆𝑖 = 0.5𝑖.
To determine the mean, we see that each random variable 𝑋𝑖 follows an
exponential distribution with the rate parameter given, and substituting 𝜆𝑖 =
0.5𝑖 we get
20
20
𝑖=1
𝑖=1
1
1
𝐸[𝑌𝑒𝑥𝑝 ] = ∑
= 2∑
0.5𝑖
𝑖
The resulting summation we get is the harmonic series.
Similarly, substituting 𝜆𝑖 to determine the variance gives:
20
20
𝑖=1
𝑖=1
1
1
𝑉𝑎𝑟[𝑌𝑒𝑥𝑝 ] = ∑
= 4∑ 2
2
(0.5𝑖)
𝑖
We see here that the resulting summation is the p-series.
The computed empirical values by Matlab match the theoretical
expectations closely (Figure-8).
Figure-8: Mean and Variance Matlab Computations
c) Comparison to Gaussian Distribution
The PDF and CDF of 𝑌𝑒𝑥𝑝 closely align with the Gaussian curve
(Figure-6 and Figure-7).
The more exponential random variables we sum, the better the
approximation to a Gaussian.
3. Conclusions
This experiment successfully demonstrates the Central Limit Theorem:
Summing uniform or exponential IID random variables results in
distributions approaching Gaussian forms.
The weighted sum of uniform variables still converges but retains
some skewness.
As more exponential variables are summed, the distribution shape
becomes increasingly Gaussian.
Empirical means and variances match theoretical calculations,
validating the results.
Part 2: MATLAB Code
% EC2010
% Computer Assignment 5
% LTJG Vasileios Koulountzos HN - Capt Joseph Kronlage USMC – Capt Phillip
Graham USMC
clc; clear; close all;
%% Generate Uniform Random Variables and Compute Y1, Y2
N = 10000;
X = rand(6, N) - 0.5; % Uniform distribution in range [-0.5, 0.5]
Y1 = sum(X, 1);
Y2 = X(1, :) + 0.5*X(2, :) + 0.8*X(3, :) + 1.8*X(4, :) + 0.3*X(5, :) +
0.5*X(6, :);
%% Plot PDF and CDF for Y1 and Y2
figure;
histogram(Y1, 25, 'Normalization', 'pdf'); hold on;
x = linspace(min(Y1), max(Y1), 100);
plot(x, normpdf(x, mean(Y1), std(Y1)), 'r', 'LineWidth', 2);
title('PDF of Y1'); xlabel('Y1'); ylabel('Density'); grid on;
hold off;
figure;
cdfplot(Y1); hold on;
plot(x, normcdf(x, mean(Y1), std(Y1)), 'r', 'LineWidth', 2);
title('CDF of Y1'); xlabel('Y1'); ylabel('Cumulative Probability'); grid
on;
hold off;
figure;
histogram(Y2, 25, 'Normalization', 'pdf'); hold on;
x = linspace(min(Y2), max(Y2), 100);
plot(x, normpdf(x, mean(Y2), std(Y2)), 'r', 'LineWidth', 2);
title('PDF of Y2'); xlabel('Y2'); ylabel('Density'); grid on;
hold off;
figure;
cdfplot(Y2); hold on;
plot(x, normcdf(x, mean(Y2), std(Y2)), 'r', 'LineWidth', 2);
title('CDF of Y2'); xlabel('Y2'); ylabel('Cumulative Probability'); grid
on;
hold off;
%% Compute Theoretical Mean and Variance
mean_Y1 = mean(Y1);
var_Y1 = var(Y1);
mean_Y2 = mean(Y2);
var_Y2 = var(Y2);
fprintf('Y1: Mean = %.4f, Variance = %.4f\n', mean_Y1, var_Y1);
fprintf('Y2: Mean = %.4f, Variance = %.4f\n', mean_Y2, var_Y2);
%% Generate Exponential Random Variables
lambda = 0.5 * (1:20);
X_exp = zeros(20, N);
for i = 1:20
X_exp(i, :) = exprnd(1/lambda(i), [1, N]);
end
Y_exp = sum(X_exp, 1);
%% Plot PDF and CDF for Y_exp
figure;
histogram(Y_exp, 25, 'Normalization', 'pdf'); hold on;
x = linspace(min(Y_exp), max(Y_exp), 100);
plot(x, normpdf(x, mean(Y_exp), std(Y_exp)), 'r', 'LineWidth', 2);
title('PDF of Y_{exp}'); xlabel('Y_{exp}'); ylabel('Density'); grid on;
hold off;
figure;
cdfplot(Y_exp); hold on;
plot(x, normcdf(x, mean(Y_exp), std(Y_exp)), 'r', 'LineWidth', 2);
title('CDF of Y_{exp}'); xlabel('Y_{exp}'); ylabel('Cumulative
Probability'); grid on;
hold off;
%% Compute Theoretical Mean and Variance
mean_Y_exp = sum(1 ./ lambda);
var_Y_exp = sum(1 ./ (lambda .^ 2));
fprintf('Y_exp: Mean = %.4f, Variance = %.4f\n', mean_Y_exp, var_Y_exp);