t = 0.01*(0:379)';
X = [sin(20*t.^2) sin(5*t.^3) sin(2*t.^4)];
figure;
a1 = subplot(2,1,1);
plot(X);
legend({'X1' 'X2' 'X3'});
title('X');
blk = 25;
C = zeros(size(X,1)-blk+1,2);
a2 = subplot(2,1,2);
h = plot(C);
set(h(1),'color',[0 0.5 0]);
set(h(2),'color','r');
title('Running Covariance');
for n = 0:size(X,1)-blk
c = cov(X(n + (1:blk),:));
C(n+1,:) = c(2:3,1);
set(h(1),'Ydata',C(:,1));
set(h(2),'Ydata',C(:,2));
drawnow;
end
legend({'cov(X1 , X2)' 'cov(X1 , X3)'});
linkaxes([a1 a2],'x');