-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbss.m
More file actions
88 lines (74 loc) · 2.43 KB
/
bss.m
File metadata and controls
88 lines (74 loc) · 2.43 KB
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
function[SS, AA] = bss(blockSize, X, fs, epsilon, outDir, maxIter, minStep)
%------------------------------------------------------------------------
%
% bss.m:
% Performs blind source separation on the provided mixtures using the
% provided sampling block size, frequency, and initial step size.
%
% Inputs:
% blockSize: The block size to use when sampling from the mixtures
% while performing blind source separation
% X: Matrix of mixtures from which to extract sources
% fs: The frequency of the mixtures (and inferred sources)
% epsilon: The initial step size to use during gradient ascent
% outDir: The directory to write output to
% maxIter: The maximum number of iterations during gradient ascent
% minStep: The minimum step size during dynamic epsilon adjustment
%
% Outputs:
% SS: The sources inferred from the provided mixtures
% AA: The inferred mixing matrix
%
%------------------------------------------------------------------------
% Get the number of mixtures and their size
n = size(X, 1);
% Write original mixtures to file
for i=1:n
wavwrite(soundnorm(X(i,:)), fs,...
[outDir 'mixture_' int2str(i) '_orig.wav']);
end
% Choose Identity matrix for initial value of A
AA = eye(n);
% Gradient ascent
% Initialize likelihood to 0
lastLoglike = 0;
% Also serves as an escape hatch
converged = false;
i = 0;
% Constant for step size adjustment
a = 1;
while ~converged
if i > maxIter || epsilon < minStep
converged = true;
end
% Get samples
samples = sample(blockSize, X);
% Calculate S fragments
SS = AA\samples;
% Infer mixing matrix A
AA = inferA(blockSize, X, AA, epsilon);
% Calculate log likelihood and delta
currentLoglike = loglike(AA, SS);
loglikeDelta = currentLoglike - lastLoglike;
if converged
% Calculate full S and normalize
SS = AA\X;
for j=1:n
% Normalize sources
SS(j,:) = soundnorm(SS(j,:));
% Write inferred sources to file
wavwrite(SS(j,:), fs, [outDir 'source_' int2str(j)...
'_inferred.wav']);
end
end
if abs(loglikeDelta) < epsilon*a
disp('step down');
% Reduce step size if the difference from last iteration is
% less than epsilon*a
epsilon = epsilon/2;
end
% Update likelihood and iteration counter
lastLoglike = currentLoglike;
i = i + 1;
end
end