-
Notifications
You must be signed in to change notification settings - Fork 0
/
wcmvn.m
61 lines (53 loc) · 1.75 KB
/
wcmvn.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
function Fea = wcmvn(fea, win, varnorm)
% performs cepstral mean and variance normalization over a sliding window
%
% Inputs:
% - fea : input ndim x nobs feature matrix, where nobs is the
% number of frames and ndim is the feature dimension
% - win : length of the sliding window (should be an odd number)
% - varnorm : binary switch (false|true), if true variance is normalized
% as well
% Outputs:
% - Fea : output ndim x nobs normalized feature matrix.
%
% Omid Sadjadi <[email protected]>
% Microsoft Research, Conversational Systems Research Center
if ( nargin < 3 ),
varnorm = false;
end
if ( nargin == 1),
win = 301;
end
if ( mod(win, 2) == 0 ),
fprintf(1, 'Error: Window length should be an odd number!\n');
return;
end
[ndim, nobs] = size(fea);
if ( nobs < win ),
if ~mod(nobs, 2)
nobs = nobs+1;
fea = [fea, fea(:, end)];
end
win = nobs;
end
epss = 1e-20;
Fea = zeros(ndim, nobs);
idx = 1 : ( win - 1 )/2;
Fea(:, idx) = bsxfun(@minus, fea(:, idx), mean(fea(:, 1 : win), 2));
if varnorm,
Fea(:, idx) = bsxfun(@rdivide, Fea(:, idx), std(fea(:, 1 : win), [], 2) + epss);
for m = ( win - 1 )/2 + 1 : nobs - ( win - 1 )/2
idx = m - ( win - 1 )/2 : m + ( win - 1 )/2;
Fea(:, m) = ( fea(:, m) - mean(fea(:, idx), 2) )./(std(fea(:, idx), [], 2) + epss);
end
else
for m = ( win - 1 )/2 + 1 : nobs - ( win - 1 )/2
idx = m - ( win - 1 )/2 : m + ( win - 1 )/2;
Fea(:, m) = ( fea(:, m) - mean(fea(:, idx), 2) );
end
end
idx = (nobs - ( win - 1 )/2 + 1) : nobs;
Fea(:, idx) = bsxfun(@minus, fea(:, idx), mean(fea(:, nobs-win+1:nobs), 2));
if varnorm,
Fea(:, idx) = bsxfun(@rdivide, Fea(:, idx), std(fea(:, nobs-win+1:nobs), [], 2) + epss);
end