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?

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 commentaires

Does your notation "E(a,b)" basically mean the correlation/covariance between a and b? (It doesn't matter which).
When you say "E(y,e) equal to zero", do you mean "E(Y,e) equal to zero"?
Do we assume that e and x are uncorrelated? This would make things easier in my opinion.
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
That's good - the answer I wrote should work for you. Please accept it if you are happy with it.

Connectez-vous pour commenter.

 Réponse acceptée

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:

Plus de réponses (0)

Catégories

En savoir plus sur Random Number Generation dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by