clear;
close all;

% 1
N=100;
S=[2 1; 1 1];
Sq=sqrtm(S);
e=Sq*randn(2,N);
% 2
x=2*rand(1,N)-1;
U=[1 3]';
y=U*x+e;
% 3
Rx=1/3;
Rxy=Rx*U';
Ry=U*Rx*U'+S;
Astar=Rxy*inv(Ry);
LMSEerr=Rx-Astar*Rxy'; % theoretical MSE
% 4
mx=mean(x);
my=mean(y');
M=cov([x' y']);
sRx=M(1,1);
sRxy=M(1,2:3);
sRy=M(2:3,2:3);
sAstar=sRxy*inv(sRy);
% Given a new measurement ynew, LMSE estimator is: xhat = mx+sAstar*(ynew-my)
sLMSEerr=sRx-sAstar*sRxy'; % estimated MSE