% PROGRAM NAME: binorm.m
% This code performs m simulations of n
% measurements of a bivariate normal r.v.
m=1000;
n=2000;
% Specifications:
my=0;
sigx=1.0;
sigy=1.0;
rxy=0.1;
% ====================
a=rxy*(sigy/sigx);
sigu=(sigy^2 - a^2*sigx^2)^0.5;
x=sigx*randn(n,m);
u=sigu*randn(n,m);
y=a*x + u;
sigxvec=std(x);
sigyvec=std(y);
%covxyvec=cov(x,y);
rxy=zeros(1,m);
for k=1:m
    cv=cov(x(:,k),y(:,k));
    cvxy=cv(1,2);
    sx=cv(1,1)^.5;
    sy=cv(2,2)^.5;
    rxy(k)=cvxy/(sx*sy);
end
hist(rxy)