Hi guys, I have two randomly generated variables and want to generate the third which is correlated with one of them and uncorrelated with the other. How can I generate such random variable?

조회 수: 1 (최근 30일)
To be specific I have these series
e~N(0,1)and x~N(0,v), where v is variance of x
and I want to generate another variable say Y that satisfy the following conditions
E(y,e) equal to zero E(Y,x) not equal to zero
Please help me out with this.
  댓글 수: 3
Solomon Gofere
Solomon Gofere 2014년 11월 2일
Sorry I was not clear with my question. My notations are like this: E(x,y) refers to correlation between the two. Y and y are exactly the same, i just missed to hit shift. And e and x are correlated.
Thanks
Harry
Harry 2014년 11월 2일
That's good - the answer I wrote should work for you. Please accept it if you are happy with it.

댓글을 달려면 로그인하십시오.

채택된 답변

Harry
Harry 2014년 11월 2일
편집: Harry 2014년 11월 2일
With problems like this, I always think it is easiest to start with zero-mean, unit-power uncorrelated random variables. It's difficult to write equations in this forum, so I wrote some which I have uploaded as an image at the end of this post. I assume you want real numbers, but this is straightforward to extend to the complex case.
First, here's the Matlab code:
close all; clear all; clc;
% Draw N random values for e
N = 10000;
e = randn(N,1);
% Set required variances and cross-correlation for x and y
Px = 1;
Py = 3;
rho_xy = 0.4;
% Generate s1 and s2 of length N
s1 = randn(N,1);
s2 = randn(N,1);
% Make x
x = sqrt(Px)*s1;
% Make y
B = rho_xy*sqrt(Py);
C = sqrt(Py*(1 - rho_xy^2));
y = B*x + C*s2;
% Check results
sample_Pe = mean(e.^2)
sample_Px = mean(x.^2)
sample_Py = mean(y.^2)
sample_rho_ey = e.'*y/(norm(e)*norm(y))
sample_rho_xy = x.'*y/(norm(x)*norm(y))
And here are the equations:

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by