% This script is to plot the data set in the tranformed space0 
%

% load the data sets
%
load s1.dat;
load s2.dat;
[m,n] = size(s1);

% Setup files for storing the results
%
FID = fopen('set1_original','w');

% adjust the data so that the required mean is obtained
%
for k=1:m
b(k,1) = s1(k,1) - 1.2299 ;
b(k,2) = s1(k,2) + 0.2579 ;
fprintf(FID,'%7.6f   %7.6f\n', b(k,1),b(k,2));
end;
mean_1 = mean(b);
[m,n] = size(s2);

% Setup files for storing the results
%
FID = fopen('set2_original','w');

% adjust the data so that the required mean is obtained
%
for k=1:m
c(k,1) = s2(k,1) - 0.6351 ;
c(k,2) = s2(k,2) + 0.8489 ;
fprintf(FID,'%7.6f   %7.6f\n', b(k,1),b(k,2));
end;
mean_2 = mean(c);

% compute the eigen values and eigen vectors
%
[ev1,eg1] = eig(cov(s1));
transform_1 = sqrtm(inv(eg1)) * transpose(ev1);
[v,d] = eig(cov(s2));
transform_2 = sqrtm(inv(d)) * transpose(v);

% shift the data set in the tranformed space
%
for i=1:length(s1)
	shift_set1(i,:)=(s1(i,:) - mean_1(1,:));
end;
shift_set1_transf = transpose(transform_1*transpose(shift_set1));

% plot the transformed data 
%
grid on;
hold on;
box on;
plot(shift_set1_transf(:,1),shift_set1_transf(:,2),'ko');

% shift the data set in the tranformed space
%
for i=1:length(s2)
	shift_set2(i,:)=s1(i,:)-mean_2(1,:);
end;
shift_set2_transf = transpose(transform_2*transpose(shift_set2));

% plot the transformed data 
%
grid on;
zoom on;
hold on;
box on;
plot(shift_set2_transf(:,1),shift_set2_transf(:,2),'k*');
legend('set1','set2');

% end of file
%
