%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Generate simulate data %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% data length
N = 44000;
% read data from wave file
s1 = wavread('s0002.wav'); s1 = s1(1:N)';
s2 = wavread('S0033.wav'); s2 = s2(1:N)';
s3 = wavread('S0024.wav'); s3 = s3(1:N)';
s = [s1; s2; s3];
% mix the data
A = [ 1 4 5
3.4 2.4 2
6 2 3.5];
x = A * s;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Now we'll recover s1, s2 & s3 from x %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
len = size(x, 2); % number of data samples
IC_num = size(x, 1); % number of ICs
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Center the data with 0 mean %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for (cnt = 1: IC_num)
x(cnt, :) = x(cnt, :) - mean(x(cnt, :)')';
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Whiten the data %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Rx = x*x'/len;
[Ux Sx] = eig(Rx); % assert that Ux*Sx*Ux'-Rx = 0
Vx = inv(Sx).^0.5*Ux'; % Vx is the whiten matrix
z = Vx * x; % z is whiten data
% assert that z*z'/len = I
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Recover ICs %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% What kind of G we will be used ?
% G(y) = (1/alpha) * ln(cosh(alpha*y))
% g(y) = tanh(alpha*y)
% or
% G(y) = -exp(-y^2/2)
% g(y) = y * exp(-y^2/2)
% g'(y) = (1-y^2)*exp(-y^2/2)
w = eye(IC_num);
w_old = w;
eps = 1.0e-5;
flag = 1;
while (flag == 1)
for (cnt = 1: IC_num)
y = w(:, cnt)'*z;
Gy = -exp(-y.^2/2);
gy = y.*(-Gy);
gy1 = (1-y.^2).*(-Gy);
E1 = z*gy'/len;
E2 = mean(gy1')';
w(:, cnt) = E1-E2*w(:, cnt);
end
wt = w';
[Uw Sw] = svd(wt*wt');
wt = inv(Uw * sqrt(Sw)) * wt;
w = wt';
change = ((sum(sum((abs(w'*w_old) - eye(IC_num)).^2)))/IC_num)
if ( change < eps)
flag = 0;
end
w_old = w;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Recover s %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
s_n = w'*z;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Play all the music %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Play mix sound 1
Fs=16000;
x(1,:)=x(1,:)/(max(s_n(1,:))-min(x(1,:)))*2;
wavwrite(x(1, :),Fs,'mixsound1')
%wavplay(x(1, :), Fs);
% Play mix sound 2
x(2,:)=x(2,:)/(max(x(2,:))-min(x(2,:)))*2;
wavwrite(x(2, :),Fs,'mixsound2')
%wavplay(x(2, :), Fs);
% Play mix sound 3
x(3,:)=x(3,:)/(max(x(3,:))-min(x(3,:)))*2;
wavwrite(x(3, :),Fs,'mixsound3')
%wavplay(x(3, :), Fs);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Play sound 1
s_n(1,:)=s_n(1,:)-mean(s_n(1,:));
s_n(1,:)=s_n(1,:)/(max(s_n(1,:))-min(s_n(1,:)))*2;
wavwrite(s_n(1, :),Fs,'sound1')
wavplay(s_n(1, :), Fs);
% Play sound 2
s_n(2,:)=s_n(2,:)-mean(s_n(2,:));
s_n(2,:)=s_n(2,:)/(max(s_n(2,:))-min(s_n(2,:)))*2;
wavwrite(s_n(2, :),Fs,'sound2')
wavplay(s_n(2, :),Fs);
% Play sound 3
s_n(3,:)=s_n(3,:)-mean(s_n(3,:));
s_n(3,:)=s_n(3,:)/(max(s_n(3,:))-min(s_n(3,:)))*2;
wavwrite(s_n(3, :),Fs,'sound3')
wavplay(s_n(3, :), Fs);
figure;
subplot(3,3,1);
plot(s1);
title(strcat('source1'));
subplot(3,3,4);
plot(s2);
title(strcat('source2'));
subplot(3,3,7);
plot(s3);
title(strcat('source3'));
subplot(3,3,2);
plot(x(1,:));
title(strcat('Mixsound1'));
subplot(3,3,5);
plot(x(2,:));
title(strcat('Mixsound2'));
subplot(3,3,8);
plot(x(3,:));
title(strcat('Mixsound3'));
subplot(3,3,3);
plot(-0.2.*s_n(3,:));
title(strcat('seperation1'));
subplot(3,3,6);
plot(-0.1.*s_n(1,:));
title(strcat('seperation2'));
subplot(3,3,9);
plot(-0.2.*s_n(2,:));
title(strcat('seperation3'));
评论16