disp('autocorrelation matrix')
R=[1.1 0.5; 0.5 1.1]
disp('crosscorrelation matrix')
p=[0.5271; -0.4458]
% initial filter value & stepsize
hinit=[-1;-1];
mu=1.249;
% record the evolution of the h
T=100;
H=[hinit];
h=hinit;
% SD algorithm
for k=1:T
h=h-mu*(R*h-p);
H=[H,h];
end
hopt=inv(R)*p;

%drawing the contour
figure
%Uncomment tp plot contours
  [X,Y] = meshgrid(hopt(1)-0.5:.001:hopt(1)+0.5,hopt(2)-0.5:.001:hopt(2)+0.5);
  Z = X.^2*R(1,1)+Y.^2*R(2,2)+ 2*R(1,2).*X.*Y  - 2*p(1)*X - 2*p(2)*Y ;
  contour(X,Y,Z)

hold on
plot(H(1,:),H(2,:),'r');
plot(hopt(1),hopt(2),'*');
grid on
plot(hinit(1),hinit(2),'s');
title(['mu = ' num2str(mu)])

% plot the variable nu from the lecture notes
[Q Lam]=eig(R);
nu=Q'*(H-hopt*ones(1,T+1));
figure
plot(nu')
title('\nu=Q^{T}*(h-h_{opt})')
legend('\nu_1(n)','\nu_2(n)')
xlabel('n')
grid on
