%ICAdemo.m
x1=randn(1,1000);
y1=randn(1,1000); 
x2=rand(1,1000);
y2=rand(1,1000); 
z1=[0.6 0.3;0.3 0.6]*[x2;y2];
x2=z1(1,:);
y2=z1(2,:);
[E,D]=eig(cov(z1'))
z2=E'*z1;
x3=z2(1,:);
y3=z2(2,:);
x1=(x1-mean(x1))/sqrt(var(x1));
y1=(y1-mean(y1))/sqrt(var(y1));
x2=(x2-mean(x2))/sqrt(var(x2));
y2=(y2-mean(y2))/sqrt(var(y2));
x3=(x3-mean(x3))/sqrt(var(x3));
y3=(y3-mean(y3))/sqrt(var(y3));
figure
subplot(2,2,1) 
plot(x1,y1,'*');
subplot(2,2,2) 
plot(x2,y2,'*');
subplot(2,2,3) 
plot(x3,y3,'*'); 
%computation of kurtosis of the data x1,x2,x3,x4,y2 and y3.
%temp=4e[(WiTZ)3]-12E[WiTZ)2]E[WiTZ].
E=[kurt(x1) kurt(y1) kurt(x2) kurt(y2) kurt(x3) kurt(y3)]; 
%Absolute value of the kurtosis is minimized as follows. %Differentiation of kurtosis of the data with mean=0 %and var=1 
W=rand(2,2); 
W(:,1)=W(:,1)/sqrt(sum(W(:,1).^2)); 
W(:,2)=W(:,2)-(W(:,2)'*W(:,1))*W(:,1); 
W(:,2)=W(:,2)/sqrt(sum(W(:,2).^2)); 
x4=x3; y4=y3; 
COL1=[]; COL2=[]; WTRACT=[]; 
for iter=1:100 
    X=W'*[x3;y3]; 
    x4=X(1,:); 
    y4=X(2,:); 
    W(:,1)=W(:,1)+gradient(x4); 
    W(:,2)=W(:,2)+gradient(y4); 
    W(:,1)=W(:,1)/sqrt(sum(W(:,1).^2)); 
    W(:,2)=W(:,2)-(W(:,2)'*W(:,1))*W(:,1);
    W(:,2)=W(:,2)/sqrt(sum(W(:,2).^2)); 
    COL1=[COL1 kurt(x4)];
    COL2=[COL2 kurt(y4)];
end
subplot(2,2,4) 
plot(x4,y4,'*') 
figure 
subplot(2,1,1) 
plot(COL1) 
subplot(2,1,2) 
plot(COL2) 
title('Convergence graph for ICA')

