MATLAB: Use the code below to generate 1000 samples of the random variables X, Y
ID: 2249307 • Letter: M
Question
MATLAB:
Use the code below to generate 1000 samples of the random variables X, Y, and Z.
x=randn(1,1000);
y=randn(1,1000);
z=x+y;
a. Applying equation 3-25 on page 133 of the text, compute the correlation coefficient for the following cases;
p(x,y), p(x,x), and p(x,z). Do not use the matlab function corrcoef.m.
Explain the results for each output in matlab.
b. Using a criteria of p>.75 for significant correlation, determine if any of the cases above in part a. result in significant correlation. If we assume that the case where p<.75 is uncorrelated, assess the three cases as statistically independent or statistically dependent?
book to use: http://web.kyunghee.ac.kr/~tskim/Cooper%20-%20Probabilistic%20Methods%20of%20Signal%20and%20System%20Analysis,%203rd%20Ed.pdf
Explanation / Answer
a. Please find the solution in the below MATLAB Program
clear all; close all;
%%%------generate 1000 samples of the random variables X-----%%%
x=randn(1,1000);
%%%------generate 1000 samples of the random variables Y-----%%%
y=randn(1,1000);
%%%----Compute Z from the relation given in the question-----%%%
z=x+y;
%%%%---Correlation coefficient is an approximate measure to express the degree to which two rndom variables are correlated without regard to the magnitude of either one---%
%---Correlation coefficient formula from Equation 3-25 in page 133 is given as pxy=[E(XY)-E(X)E(Y)]/[std(x)std(y)], where E(X) is the expectation of X(which is the 'Mean' of X) and std(x) is the standard deviation of X
%---Mean=sum of all samples/Number of sample---%
Ex=sum(x)/length(x); Ey=sum(y)/length(y); Ez=sum(z)/length(z);
Exx=sum(x.*x)/length(x.*x); Exy=sum(x.*y)/length(x.*y); Exz=sum(x.*z)/length(x.*z);
%----Standart deviaion std(X)=sqrt(Mean(X-Ex)^2)-----%
std_x=sqrt(mean((x-Ex).^2)); std_y=sqrt(mean((y-Ey).^2)); std_z=sqrt(mean((z-Ez).^2));
%----Correlation Coefficient between the random variables X and X => p(x,x) can be calculated as below----%
pxx=(Exx-Ex*Ex)/(std_x*std_x)
%----Correlation Coefficient between the random variables X and Y => p(x,y) can be calculated as below----%
pxy=(Exy-Ex*Ey)/(std_x*std_y)
%----Correlation Coefficient between the random variables X and Z => p(x,z) can be calculated as below----%
pxz=(Exz-Ex*Ez)/(std_x*std_z)
display(['Correlation Coefficient between the random variables X and X => p(x,x)=',num2str(pxx)]);
display(['Correlation Coefficient between the random variables X and Y => p(x,y)=',num2str(pxy)]);
display(['Correlation Coefficient between the random variables X and Z => p(x,z)=',num2str(pxz)]);
%----If you observe the values of correlation coefficients p(x,x),p(x,y) and p(x,z) ->
%----We can conclude that X and Y are Random and statistically independent as the correlation value is very small;
%----The correlation coefficient of X and X is '1' as there will be 100% correlation of the signal with itself;
%----The correlation coefficient of X,Z is nearly 0.7
%---PROGAM ENDS---%
Output:
pxx =
1.0000
pxy =
0.0157
pxz =
0.7033
Correlation Coefficient between the random variables X and X => p(x,x)=1
Correlation Coefficient between the random variables X and Y => p(x,y)=0.015741
Correlation Coefficient between the random variables X and Z => p(x,z)=0.70333
b.Using the criteria of p>0.75 for significant correlation, only the case p(x,x) resulted in significant correlation and X,X are statistically dependent..
The remaining cases p(x,y) and p(x,z) are uncorrelated with p<0.75 and (X,Y0 and (X,Z) are statistically independent.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.