function [X,Y, u, v]=gen(corr, N, d1, d2)
csize=length(corr);
sigma=zeros(csize*2);
for i=1:csize
    sigma(2*i-1, 2*i-1)=1;
    sigma(2*i, 2*i)=1;    
    sigma(2*i-1, 2*i) = corr(1,i);
    sigma(2*i, 2*i-1) = corr(1,i);    
end

[V,D] = eig(sigma);
A = V*sqrt(D);
G = A*random('Normal',0,1,csize*2,N);
G = G';
u=[];
v=[];
for i=1:csize
    u=[u, G(:,2*i-1)];
    v=[v, G(:,2*i)];
end
fx=[];
fy=[];
for i=1:d1
    fx=[fx,random('unif', 0, 1, 1,csize)'];
end
for i=1:d2
    fy=[fy,random('unif',0,1, 1,csize)'];
end
X=u*fx;
Y=v*fy;

%X=u*fx+random('Normal', 0, 0.0001, N, d);
%Y=v*fy+random('Normal', 0, 0.0001, N, d);
