%% Computational Statistics, ICA example
clear;
load icaexample
w = randn(1,2); % Random initialization of weights
w = w/norm(w);
step = 0.03;
for iter = 1:100
y = z*w';
K = mean(y.^4)-3;
Ycube = repmat(y.^3,1,2);
grad = mean(Ycube.*z);
w = w + step*grad;
w = w/norm(w);
end
soundsc(G(:,1),N); % one component of the original signal
soundsc(x(:,1),N); %one component of the mixed signal
soundsc(z(:,1),N); % primary component of whitened signal PCA
soundsc(y,N); %% First signal
xx(:,1) = x(:,1)-y'*x(:,1)*y/(y'*y); %% Orthogonalization
xx(:,2) = x(:,2) - y'*x(:,2)*y/(y'*y);
xx = mean(xx,2);
soundsc(xx,N);%% Second Signal