0% found this document useful (0 votes)
106 views17 pages

Matlab Seminar Report

This document summarizes a seminar report on applying mathematics in MATLAB. It discusses uniform, Gaussian, and experimental noise distributions. For uniform distributions, it derives the mean and variance analytically and plots the theoretical PDF. For Gaussian distributions, it similarly derives the mean and variance and plots the theoretical PDF. For experimental noise data, it plots the real and imaginary components, fits empirical PDFs to Gaussian distributions, and proposes a bivariate normal distribution fits the joint PDF of the components.

Uploaded by

HaoChihLIN
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)
106 views17 pages

Matlab Seminar Report

This document summarizes a seminar report on applying mathematics in MATLAB. It discusses uniform, Gaussian, and experimental noise distributions. For uniform distributions, it derives the mean and variance analytically and plots the theoretical PDF. For Gaussian distributions, it similarly derives the mean and variance and plots the theoretical PDF. For experimental noise data, it plots the real and imaginary components, fits empirical PDFs to Gaussian distributions, and proposes a bivariate normal distribution fits the joint PDF of the components.

Uploaded by

HaoChihLIN
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/ 17

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) = {
0

------ (1.a)

Mean of a continuous uniform distribution:


From the definition of the Expected Value:
+

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

{}

= [

1
2()

2]

2 2

2()

(+)()
2()

----- (1.b)

Variance of a continuous uniform distribution:


Start from the definition of the Variance:
V(X) = {( {})2 } = { 2 } ({})2
+

= 2 f () (

+ 2

= 2 (
=
=

3 3

3()

2 +2+2

( 2 ++2 )
3

+ 2
)
2

+ 2

) = [3() 3 ] (

()( 2 ++2 )

2 +2+2
4

----- Using the result from (1.b)

3()

2 2+2
12

2 +2+2
4
()2
12

----- (1.c)

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:
Theoretical variance:

2
()2
12

1+0
2

(10)2
12

= 0.5

(1.b)

= 0.0833

(1.c)

The numerical values of mean and variance are 0.5 and 0.0833 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]:

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:
f (x) =

1
22

()2
22

------ (2.a)

Mean of a Gaussian distribution:


Start from the definition of the Expected Value:
{} = + f () = + 1 2

2
+

= [( ) + ] 22
+

= ( ) 22

()2
22

+ +

2
= 2
2 ( ) (

()2
22

()2
22

+ 22

()2
22

()2
22

()2

+ 1

22

22

The right integral part is equal to


f (x) from (2.a). The complete
integral over the pdf is 1, so the right part now becomes: ( 1).
1

{} =

22

22

( 2 )

()2
22

( 2 )[0 0] + = ------ (2.b)

Variance of a Gaussian distribution:


Start from the definition of the Variance:
+

V(X) = {( {})2 } = ( )2 f ()
+

V(X) =

( )

1
2 2

()2
22

we let =

2 2 2

V(X) =

2 2 2
2 2

, = 2 2

2 2
1

2 2

2 2

2 =

2 2

By using integration by parts with = , =


V(X) =

22

([

1
2

+ 1 2

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

) = lim (

) = 0,

and the same for


V(X) =
=

22

+ 1 2

(0

) =

2
+

= 2 ( ) ----- (2.c)

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 XR 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 XR 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:
f(x) = 1

1 2
(
)
1

+ 2

2 2
)
2

For the real signal component, the parameters of the fitted PDF are:
a1 = 0.5268, b1 = 0.007966, c1 = 1.065, a2 = 0.01925, b2 = 0.287, c2 = 0.1534
For the imaginary part vector, the parameters of the fitted PDF are:
a1 = 0.003051, b1 = 0.3737, c1 = 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

where x,y is the covariance between random variables X and Y, and 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:
fXY (x, y) =

1
2 12

1
2(12 )

[(

) +(

) 2

( )( )

]} ----- (3.a)

It was found that (from question.5):


= 3.7570 17, and = 9.0001 16, = 0.7362, = 0.7517,
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

Bytes

Class

noise

1x1

80176

struct

Attributes

3.2 Part 3 MATLAB Code


%%
% 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');

You might also like