Anda di halaman 1dari 13

MATLAB SEMINAR REPORT APPLIED MATHEMATICS

Team members: Vikram Krishnaswamy and Hao-Chih,LIN

ISAE/AESS-1

Part 1 - The uniform distribution


Let X denote a continuous random variable uniformly distributed on the interval [a; b].
Question 1.
Recall the expression of its PDF and derive analytically its mean and variance.
Answer 1:
The expression of a continuous uniform PDF:
1
f x ( x )= ba for a x b ------ (1.a)
0 otherwise

Mean of a continuous uniform distribution:


From the definition of the Expected Value:
b

1
dx
x ba

x f x ( x ) dx =

{X}
=

1
x2
2(ba)

----- According to (1.a)

=
a

(b+a)(ba)
b a
=
2(ba)
2(ba)
----- (1.b)

b+a
2

Variance of a continuous uniform distribution:


Start from the definition of the Variance:
E {( XE { X })

V (X)

x 2 f x ( x)dx(

E { X 2 } ( E { X })2

b+a 2
) ----- Using the result from (1.b)
2
b

1
b+ a 2
1
b+ a 2
dx
=
x3
= x
ba
2
2
3 ( ba )
a
a
3
3
2
2
b a
b + 2ab +a

=
3 (ba)
4
2
2
2
2
(ba)(b + ab+a ) b + 2ab +a

3 (ba)
4
2
2
2
(b +ab +a ) b + 2ab +a2
b22 ab+ a2
=
=

12
3
4
2
( ba )
----- (1.c)
12
2

( ) [

] ( )

Question 2.
Plot the PDF. Verify that the sum of the PDF is unity. Verify that the theoretical mean
and variance are in accordance with the numerical values obtained with Matlab.
Answer 2:
Here, we set a = 0 and b = 1.
Theoretical mean:

b+a 1+0
=
2
2

= 0.5

(1.b)

( ba )2 ( 10 )2
(1.c)
=
=0.083 3
12
12
The numerical values of mean and variance are 0.5 and 0.083 3 respectively. (see Appendix 1 for
part 1 MATLAB code.) The following figure shows the PDF of a continuous uniform distribution on
the interval [0, 1]:
Theoretical variance:

Figure 1.1: PDF of Uniform DIstribution

Question 3.
Draw N samples from the distribution. Plot these N realizations. Using these samples, compute
the empirical i) mean; ii) variance; iii) PDF. Verify that the sum of the empirical PDF is unity. In the
same figure, plot the theoretical PDF with that obtained with the samples.
Answer 3:
Here we set N = 100. The figure with N-samples and the empirical PDF is as follows:

Figure 1.2: Empirical and Theoretical PDF

The empirical mean of the 100-sample distribution is 0.518046, and its variance is 0.080124. The
sum of the empirical PDF is 1.047120. This is greater than 1, but this is likely due to the low number
of bins in the histogram. Increasing this number would remove the discrepancy.
Part 2 - The Gaussian distribution
(Let X denote a real Gaussian random variable with mean and standard deviation .)
Question 1.

Recall the expression of its PDF and derive analytically its mean and variance.
Answer 1.
The expression of a Gaussian PDF:
2

1
f x ( x )=
e
2 2

( x )
2
2

Mean of a Gaussian distribution:


Start from the definition of the Expected Value:
+

{ X } x f x ( x )dx= x

[ ( x ) + ]

2 2

1
= ( x )
e

2 2
+

1
e
2 2
e

( x )
2
2

( x )
2
2

( x )
2
2

------ (2.a)

dx

dx
+

1
dx +
e

2 2
( x )

( x)
2
2

dx
2

( x )

( 2 ) x+2 e 2 dx + 1 2 e 2 dx
2
= 2

The right integral part is equal to

f x ( x ) dx

from (2.a). The complete

integral over the pdf is 1, so the right part now becomes: ( 1) .


{X}=
=

( x )

1 ( 2)
e 2 +
2
2
1
( 2 ) [ 00 ] + = ------ (2.b)
2
2
2

Variance of a Gaussian distribution:


Start from the definition of the Variance:
+

V ( X ) E {( XE { X }) }= ( x )2 f x (x ) dx
2

V ( X ) ( x )

2 2

( x )
2
2

dx

x
, then dx= 2 2 d
2
2
+
1
2 2
e 2 2 d
V (X) 2
2

2
+
2
2 +
2 2
2 2
2

e d= e d
2

2
we let =

By using integration by parts with = , ' = e

V (X)

([

2 2
1
1

e d
2
2

For the first part, by L'Hpital's rule, we could get

lim

1
= lim

2 e
e

( )
2

= 0,

and the same for

2 2
1
2
0
e d =
e d

= ( usingGaussian integral ) ----- (2.c)

V (X)

Question 2.
Plot the PDF. Verify that the sum of the PDF is unity. Verify that the theoretical mean
and variance are in accordance with the numerical values obtained with Matlab.
Answer 2:
Here, we set mean =0.0 and standard deviation = 1.0 . The numerical values of mean
and variance are 0.0 and 1.0 respectively. (see Appendix 2 for Part 2 MATLAB code). The PDF of
Gaussian distribution with =0.0 , = 1.0 is shown below:

Figure 2.1: PDF of Gaussian Distribution

Question 3.
Draw N samples from the distribution. Plot these N realizations. Using these samples, compute
the empirical i) mean; ii) variance; iii) PDF. Verify that the sum of the empirical PDF is unity. In the
same figure, plot the theoretical PDF with that obtained with the samples.
Answer 3:
Here, we set N = 500. The figure with N-samples and the empirical PDF is as follows:

Figure 2.2: 500-sample Empirical Distribution and Gaussian Fit

The empirical mean of the 500-sample distribution is -0.074879, and its variance is 1.009664.
The sum of the PDF is 1.002004. (See Appendix 2 for MATLAB code.)
Part 3 - Experimental data
In this third part, we study experimental data. Samples were collected on a radar system while
pointing towards the sky during a sunny day. In that case only thermal noise is present in the data.
Note that the samples are complex-valued (IQ-receiver). The random variable X representing the
collected sampled can thus be decomposed into a real part and an imaginary part denoted as X R and
XI respectively.
Question 1.
Load the data stored in the MAT-file noise.mat. Once loaded, take a look at the available
variables in the MATLAB workspace with the command whos.
Answer 1:
See Appendix 3.1 for MATLAB whos() output.
Question 2.
Construct two vectors: one containing the real part of the samples, and one containing the
imaginary part of the samples.
Answer 2:
See Appendix 3.2 for Part 3 MATLAB code.
Question 3.
For each vector, plot the realizations and the empirical PDF.
Answer 3:
The noise signal is plotted separately, in real and imaginary parts, in the following figure:

Figure 3.1: Real and Imaginary Components of Signal

Histograms of the data and fitted PDFs for each component are shown below:

Figure 3.2: Noise Amplitude Histogram and PDF for each Signal Component

Question 4.
Infer the type of distribution that could follow both random variables X R and XI. Using Matlab
functions, fit the empirical PDFs to the type of distribution inferred. What are the values of the
parameters of the fitted PDFs?
Answer 4:
Both real part and imaginary part vector are fitted based on Matlab General model Gauss2.
The general equation is:
xb1
c1

xb2
c2

( ) +a e ( )
f ( x )=a e

For the real signal component, the parameters of the fitted PDF are:
a1=0.5268,b 1=0.007966, c1 =1.065,a 2=0.01925, b2=0.287, c 2=0.1534
For the imaginary part vector, the parameters of the fitted PDF are:
a1=0.003051, b1=0.3737, c 1=0.01337, a2=0.5354,b2 =0.007875, c2 =1.049

Question 5.
Compute the correlation coefficient between XR and XI.
Answer 5:
The definition of correlation coefficient is:

= x, y
x y
where x , y is the covariance between random variables X and Y, and x means the standard
deviation of X. The correlation coefficient between XR and XI, as found by the part 3 MATLAB
code, is:
= -0.01577.
Question 6.
Plot the empirical joint PDF of XR and XI. From your observations propose a distribution that
could describe appropriately the vector [XR XI]T.
Answer 6:
Plot the empirical joint PDF of XR and XI.
The following figure is an empirical joint PDF of XR and XI:

Figure 3.3: Empirical Joint PDF of XR and XI, in Heatmap and 3D forms

Propose a distribution that could describe appropriately the vector [XR XI]T.
The covariance matrix of joint PDF is symmetric as well as semi-positive, and the plotting
result from figure 3.3 looks like typical Bivariate normal distribution model. Thus, we proposed
Bivariate normal distribution to fit the empirical joint PDF. The probability density function of
multivariate normal distribution in bivariate case is:
f XY ( x , y )=

1
2 X Y 1

exp
2

[( ) ( )

x X 2 xY 2
( x X )( yY )
1
+
2
2
X
Y
X Y
2( 1 )

]}

-----

(3.a)

It was found that (from question.5):


X =3.7570e-17,Y =9.0001e-16 , X =0.7362, Y =0.7517, X Y =0.0087, = 1.577307e-02.
The following figure shows a mesh-grid bivariate normal distribution, with the above
parameters, overlaying an experimental PDF surface, as in Fig. 3.3b.

Figure 3.4: Proposed Distribution overlaid on Fig. 3.3b

The proposed distribution and the experimental distribution are very similar, indicating that our
assumption is correct that the empirical joint PDF could be described appropriately in Bivariate
normal distribution model.

APPENDIX
1. Part 1 MATLAB Code
%%
% File name: Uniform_Distribution.m
% Developer: Vikram Krishnaswamy AND Hao-Chih,LIN
% Date: 16/09/2016
%%

clear
clc
% Define parameters
a = 0;
b = 1;
range = b-a;
interval = 0.01;
% Plot PDF
x = a-range:interval:b+range;
y = unifpdf(x, a, b);
figure(1);
plot(x,y,'LineWidth',3);
hold on;
xlabel('x values');
ylabel('Probability Density');
title('The Uniform distribution');
% Show the sum of PDF is unity
distro_sum = integral(@(x)unifpdf(x,a,b), -inf, inf);
fprintf('The sum of PDF is: %f\n',distro_sum);
% Compute the theoretical mean value
meanfunction = @(x) x * unifpdf(x,a,b);
theorMean = integral(meanfunction,-inf,inf, 'ArrayValued',true);
fprintf('The theoretical mean is: %f\n',theorMean);
% Compute the theoretical variance value
varifunction = @(x) ((x - theorMean)^2) * unifpdf(x,a,b);
theorVariance = integral(varifunction, -inf, inf, 'ArrayValued', true);
fprintf('The theoretical variance is: %f\n',theorVariance);
% Compare the theoretical result with numerical result
[numerMean, numerVariance] = unifstat(0,1);
fprintf('The numerical mean is: %f\n',numerMean);
fprintf('The numerical variance is: %f\n',numerVariance);
% Draw N samples from distribution, plot N samples
N = 100;
n = unifrnd(a,b, N, 1);
pedef = unifpdf(n,a,b); % PDF of N samples
plot(n, pedef, 'r*');
% Compute the empirical mean and variance, PDF
randmean = mean(n);
randvari = var(n);
fprintf('The empirical mean of N-samples is: %f\n',randmean);
fprintf('The empirical variance of N-samples is: %f\n',randvari);
fprintf('For the PDF of N-samples, please check variable "pedef"\n');
% Plot the theoretical PDF with that obtained with the N-samples
histsamples = 20;
[hist_f, hist_x] = hist(n,histsamples);
histPDF = hist_f/trapz(hist_x,hist_f);
bar(hist_x, histPDF,'y');
fprintf('The sum of the empirical PDF is: %f\n', sum(histPDF) * ( hist_x(2)hist_x(1) ) );

% Put the legend info on the figure


legend('Original uniform distribution','N-samples','Histogram of empirical PDF');
hold off;

2. Part 2 MATLAB Code

%%
% File name: Gaussian_Distribution.m
% Developer: Vikram Krishnaswamy AND Hao-Chih,LIN
% Date: 16/09/2016
%%
clear
clc
% Define parameters
mu = 0;
sigma = 1;
xaxis_min = -20;
xaxis_max = 20;
interval = 0.001;
% Plot PDF
x = xaxis_min:interval:xaxis_max;
y = normpdf(x, mu, sigma);
figure(1);
plot(x,y,'LineWidth',4);
hold on;
xlabel('x values');
ylabel('Probability Density');
title('The Gaussian distribution');
% Show the sum of PDF is unity
distro_sum = integral(@(x)normpdf(x,mu,sigma), -inf, inf);
fprintf('The sum of PDF is: %f\n',distro_sum);
% Compute the theoretical mean value
meanfunction = @(x) x * normpdf(x,mu,sigma);
theorMean = integral(meanfunction,-inf,inf, 'ArrayValued',true);
fprintf('The theoretical mean is: %f\n',theorMean);
% Compute the theoretical variance value
varifunction = @(x) ((x - theorMean)^2) * normpdf(x,mu,sigma);
theorVariance = integral(varifunction, -inf, inf, 'ArrayValued', true);
fprintf('The theoretical variance is: %f\n',theorVariance);
% Compare the theoretical result with numerical result
[numerMean, numerVariance] =normstat(mu,sigma);
fprintf('The numerical mean is: %f\n',numerMean);
fprintf('The numerical variance is: %f\n',numerVariance);
% Draw N samples from distribution, plot N samples
N = 500;
n = normrnd(mu, sigma, N, 1);
pedef = normpdf(n, mu, sigma); % PDF of N samples
plot(n, pedef, 'r*');
% Compute the empirical mean and variance, PDF
randmean = mean(n);
randvari = var(n);
fprintf('The empirical mean of N-samples is: %f\n',randmean);

fprintf('The empirical variance of N-samples is: %f\n',randvari);


fprintf('For the PDF of N-samples, please check variable "pedef"\n');
% Plot the theoretical PDF with that obtained with the N-samples
histsamples = 50;
[hist_f, hist_x] = hist(n,histsamples);
histPDF = hist_f/trapz(hist_x,hist_f);
bar(hist_x, histPDF,'y');
fprintf('The sum of the empirical PDF is: %f\n', sum(histPDF) * ( hist_x(2)hist_x(1) ) );
% Fit a normal dist to check the pdf
PD = fitdist(n, 'normal');
plot(hist_x, pdf(PD, hist_x), 'g--', 'LineWidth',2);
% Put the legend info on the figure
legend('Original gaussian distribution','N-samples','Histogram of empirical
PDF','Fitted normal distribution');
axis tight;
hold off;

3.1 Part 3 MATLAB whos() Output


The "whos" command result:
Name
Size
noise
1x1
3.2 Part 3 MATLAB Code

Bytes
80176

Class
struct

Attributes

%%
% File name: Experimental_Distribution.m
% Developer: Vikram Krishnaswamy AND Hao-Chih,LIN
% Date: 17/09/2016
%%
clearvars,clc,close all
%---------------------------------------------------------% Question.1: Data File Input
noise = load('noise.mat');
fprintf('The "whos" command result:\n');
whos('noise');

%---------------------------------------------------------% Question.2: Construct two vectors


realpart = real(noise.x_samp);
imagpart = imag(noise.x_samp);
maxr = max(realpart);
minr = min(realpart);
maxi = max(imagpart);
mini = min(imagpart);
[rr, cr] = size(realpart);
[ri, ci] = size(imagpart);

%---------------------------------------------------------% Question.3: Plot the realizations and the empirical PDF for each vector.
% Question.4: Fit the empirical PDFs to the type of distribution inferred.
figure;
hold on;
histsamples = 25;

% Realizations of real part


realpoints = subplot(4,4,[1 5]);
plot(1:length(realpart), realpart, 'r.');
% Empirical PDF of real part
realprob = subplot(4,4,[9 13]);
[hist_f, hist_x] = hist(realpart,histsamples);
realpdf = hist_f/trapz(hist_x,hist_f);
bar(hist_x, realpdf, 'y');
legend('Histogram of empirical PDF');
hold on;
% Fit the empirical PDF of real part
realfit = fit(hist_x.', realpdf.', 'gauss2');
plot(realfit, hist_x, realpdf);
hold off;
fprintf('For the parameters of the real part fitted PDFs, please check the
variable "realfit"\n');
%fprintf('The sum of the empirical PDF is: %f\n', sum(realpdf) * ( hist_x(2)hist_x(1) ) );
% Realizations of imag part
imagpoints = subplot(4,4,[4 8]);
plot(1:length(imagpart), imagpart, 'b.');
% Empirical PDF of imag part
imagprob = subplot(4,4,[12 16]);
[hist_f, hist_x] = hist(imagpart,histsamples);
imagpdf = hist_f/trapz(hist_x,hist_f);
bar(hist_x, imagpdf, 'y');
legend('Histogram of empirical PDF');
hold on;
% Fit the empirical PDF of imag part
imagfit = fit(hist_x.', imagpdf.', 'gauss2');
plot(imagfit, hist_x, imagpdf);
hold off;
fprintf('For the parameters of the imag part fitted PDFs, please check the
variable "imagfit"\n');
%fprintf('The sum of the empirical PDF is: %f\n', sum(imagpdf) * ( hist_x(2)hist_x(1) ) );

%---------------------------------------------------------% Question.5: Correlation between the two PDFs


realsig = std(realpart);
imagsig = std(imagpart);
gamma = mean((realpart - mean(realpart)).*(imagpart - mean(imagpart))); %
Covariance between realpart and imagpart
rho = gamma/(realsig*imagsig);
fprintf('\nThe correlation coefficient between the real and imaginary parts is:
%d\n', rho);

%---------------------------------------------------------% Question.6: Bivariate Probability Distribution Plot


[jointpdf, combbars_cell] = hist3([realpart imagpart],
[histsamples,histsamples]);
combbars_array = cell2mat(combbars_cell);
bar_axis_imag = combbars_array(1:length(combbars_array)/2);
bar_axis_real = combbars_array(length(combbars_array)/2+1:end);
% normalize the histogram data
jointpdf = jointpdf/(trapz(bar_axis_imag,trapz(bar_axis_real,jointpdf)));

bivarpdf_surf = subplot(4, 4, [2 6] );
[X,Y] = meshgrid(bar_axis_real,bar_axis_imag);
surf(X,Y,jointpdf); % surf 3D figure
bivarpdf_sc = subplot(4, 4, [10 14] );
imagesc(bar_axis_real,bar_axis_imag,jointpdf); % imagesc 2D figure
colorbar('south');
% Plot the Bivariate Gaussian Fit of Joint PDF
bivargauss = subplot(4, 4, [7 11] );
Bi_mean = [mean(realpart), mean(imagpart)];
Bi_cov = [var(realpart), gamma; gamma, var(imagpart)];
Bi_cov_eigen = eig(0.5*(Bi_cov+Bi_cov')); % Check if the covariance matrix is
semipositive or not.
x1 = -2.5:.2:2.5;
x2 = -2.5:.2:2.5;
[X1,X2] = meshgrid(x1,x2);
F = mvnpdf([X1(:) X2(:)],Bi_mean,Bi_cov);
F = reshape(F,length(x2),length(x1));
surf(X,Y,jointpdf,'FaceAlpha',0.8,'EdgeColor','none'); hold on;
surf(x1,x2,F,'FaceAlpha',0.6, 'FaceColor', 'green');
hold off;
legend('Histogram of PDF','Bivariate Gaussian Fit','Location','north');

%---------------------------------------------------------% Plot prettification


axis(bivarpdf_surf, 'tight');
axis(bivarpdf_sc, 'tight');
axis(bivargauss, 'tight');
axis([realpoints imagpoints], [-500 5500 -4 4]);
title(realpoints, 'Real Part of Input Signal');
title(imagpoints, 'Imaginary Part of Input Signal');
title(realprob, 'Distribution and PDF of Real Component');
title(imagprob, 'Distribution and PDF of Imaginary Component');
title(bivarpdf_surf, 'Joint PDF of Real and Imaginary Components (surf)');
title(bivarpdf_sc, 'Joint PDF of Real and Imaginary Components (imagesc)');
title(bivargauss, 'Bivariate Gaussian Fit of Joint PDF');
xlabel(realpoints, 'Time [arbitrary units]');
xlabel(imagpoints, 'Time [arbitrary units]');
xlabel(realprob, 'Amplitude');
xlabel(imagprob, 'Amplitude');
xlabel(bivarpdf_surf, 'Imaginary Distribution');
xlabel(bivarpdf_sc, 'Imaginary Distribution');
xlabel(bivargauss, 'Imaginary Distribution');
ylabel(realpoints, 'amplitude');
ylabel(imagpoints, 'amplitude');
ylabel(realprob, 'probability density');
ylabel(imagprob, 'probability density');
ylabel(bivarpdf_surf, 'Real Distribution');
ylabel(bivarpdf_sc, 'Real Distribution');
ylabel(bivargauss, 'Real Distribution');
zlabel(bivarpdf_surf, 'probability density');
zlabel(bivarpdf_sc, 'probability density');
zlabel(bivargauss, 'probability density');

Anda mungkin juga menyukai