forked from KyleZhang1118/Voice-Separation-and-Enhancement
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Process_IVA.m
95 lines (95 loc) · 2.58 KB
/
Process_IVA.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
function [Y,W,SetupStruc] = Process_IVA(s,Transfer,SetupStruc)
K = SetupStruc.IVA.K;
hop = SetupStruc.IVA.hop;
win = hanning(K,'periodic');
win = win/sqrt(sum(win(1:hop:K).^2));
SetupStruc.IVA.win = win; % Preserve 'win' in 'SetupStruc'
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
N = size(s,2);
for i = 1:N
X(:,:,i) = fft(enframe(s(:,i),win,hop)');
end
frame_N = size(X,2);
K_m = K/2+1;
Num = size(Transfer,3);
Y = zeros((frame_N-1)*hop+K,Num);
Y_f = zeros(Num,frame_N,K);
%%%%%%%%%%%%%%%%%%%%%%%%%% Obtain processing matrix 'W'
X_sp = zeros(Num,frame_N,K_m);
W_IVA = zeros(Num,Num,K_m);
V_sp = zeros(Num,N,K_m);
theta = 10^-6;
for i = 1:K_m
X_f = permute(X(i,:,:),[3 2 1]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Initialize W by PCA
[E,D] = PCA(X_f,1,Num);
V = sqrt(D)\E';
V_sp(:,:,i) = V;
X_sp(:,:,i) = V*X_f;
%%%%%%%%%%%% Adjust amplitude of 'w'
W_o = eye(Num);
y_f = W_o*V*X_f;
W_IVA(:,:,i) = W_o;
Y_f(:,:,i) = y_f;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%% IVA iterations
epsi = 1e-6;
step_size = 0.1;
max_iteration = 200;
Y_k = zeros(Num,frame_N);
% K_sp = sqrt(K_m);
pObj = inf;
A = zeros(1001,2)-1; %%%% Show the decrease of non-linear correlation, IVA max iterations 1000
for iteration = 1:max_iteration
for i = 1:Num
y_temp = permute(Y_f(i,:,:),[3 2 1]);
Y_k(i,:) = sqrt(sum(abs(y_temp(1:K_m,:)).^2))+epsi;
end
dlw = 0;
for i = 1:K_m
W = W_IVA(:,:,i);
X_f = X_sp(:,:,i);
y_f = Y_f(:,:,i);
y_fun = y_f./Y_k;
% y_fun = K_sp*tanh(K_sp*Y_k).*y_f./Y_k;
core = eye(size(W))-y_fun*y_f'/frame_N;
dlw = dlw +log(abs(det(W))+epsi);
W = W+step_size*core*W;
W_IVA(:,:,i) = W;
Y_f(:,:,i) = W*X_f;
end
Obj = (sum(sum(Y_k))/frame_N-2*dlw)/(Num*K_m);
dObj = pObj-Obj;
pObj = Obj;
A(iteration,:) = [Obj,abs(dObj)/abs(Obj)];
if(abs(dObj)/abs(Obj)<theta)
break;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%% Post processing
W = zeros(Num,N,K_m);
Y_f(:,:,1) = zeros(Num,frame_N);
for i = 2:K_m
W_inv = pinv(W_IVA(:,:,i)*V_sp(:,:,i));
for ii = 1:Num
Y_f(ii,:,i) = Y_f(ii,:,i)*W_inv(1,ii);
W_IVA(ii,:,i) = W_IVA(ii,:,i)*W_inv(1,ii);
end
W(:,:,i) = W_IVA(:,:,i)*V_sp(:,:,i);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if(i~=K_m)
Y_f(:,:,K+2-i) = conj(Y_f(:,:,i));
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Recover signals
if(K/hop==2)
win = ones(K,1);
end
for i = 1:Num
y_temp = permute(Y_f(i,:,:),[3 2 1]);
Y(:,i) = overlapadd(real(ifft(y_temp))',win,hop);
end
return;