Clear Filters
Clear Filters

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?

3 views (last 30 days)
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 Comments
Solomon Gofere
Solomon Gofere on 2 Nov 2014
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

Sign in to comment.

Accepted Answer

Harry
Harry on 2 Nov 2014
Edited: Harry on 2 Nov 2014
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:

More Answers (0)

Community Treasure Hunt

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

Start Hunting!