clear all;
n = 500;

%first make a matrix of uncorrelated noise
a(:,1) = randn(n,1);
a(:,2) = randn(n,1);

%make a second matrix of correlated noise
b(:,1) = randn(n,1);
b(:,2) = 0.5*randn(n,1) + 0.5*b(:,1);

%compute the covariance matrix in 2 different ways
covarmat =cov(a);
c = a-repmat(mean(a),n,1);
blarg = c'*c/(n-1);

sigma = cov(b);


%compute the eigenvectors and eigenvalues
%[V, D] = eig(sigma);

%plot the correlated noise and the first two principal components
%plot(b(:,1),b(:,2),'b.');
%hold on
%plot(3*[-V(1,1) V(1,1)],3*[-V(1,2) V(1,2)],'k')
%plot(3*[-V(2,1) V(2,1)],3*[-V(2,2) V(2,2)],'k')

%re-order the matrix

%V2(:,1) = V(:,2);
%V2(:,2) = V(:,1);

%newB = b*V2;

%plot(newB(:,1),newB(:,2),'b.');


%[coeff,score,latent] = princomp(b);

%plot(score(:,1),score(:,2),'b.');

%coeff = eigenvectors
%score = transformed data
%latent = eigenvalues
