-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsecond_gen_logfb_feat.m
More file actions
77 lines (68 loc) · 2.21 KB
/
second_gen_logfb_feat.m
File metadata and controls
77 lines (68 loc) · 2.21 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
function second_gen_logfb_feat(nbands)
% the job of this script is generate log filterbank energies
% - it generates basic features as well as whitened versions.
% - it depends on there being text files called '~train.txt','~allfiles.txt'
% which have 1 file name per line.
NFFT=512;
fs = 16000;
H = get_mel_filterbank(26,NFFT/2,fs);
alldata = {};
totalsize = 0;
pass = 0;
for filelistname={'~train.txt','~allfiles.txt'}
filelist = fopen(char(filelistname));
fname = fgetl(filelist);
numfile = 0;
fprintf('%s:',char(filelistname));
while ischar(fname)
speech = audioread(fname);
frames = frame_sig(speech,0.025*fs,0.01*fs,@(x)hamming(x));
pspec = abs(fft(frames,NFFT,2)).^2;
pspec = pspec(:,1:NFFT/2);
lfbe = log(pspec*H');
%lfbe = log(pspec);
%lfbe = frames;
if pass == 0
fname = fgetl(filelist);
numfile = numfile + 1;
alldata{numfile} = lfbe;
[L,W] = size(lfbe);
totalsize = totalsize + L;
if mod(numfile,100) == 0
fprintf('.');
end
else
lfbew = lfbe - repmat(mu1,size(lfbe,1),1);
lfbew= (e*((e'*lfbew')./repmat(sqrt(diag(v)'),size(lfbew,1),1)'))';
[a b c] = fileparts(fname);
newname = [a,'/',b,'.mlogfb'];
write_HTK_file(lfbe,newname,10000,6);
newname = [a,'/',b,'.mlogfbw'];
write_HTK_file(lfbew,newname,10000,6);
fname = fgetl(filelist);
numfile = numfile + 1;
if mod(numfile,100) == 0
fprintf(',');
end
end
end
fclose(filelist);
fprintf('\n');
if pass == 0
% collect all frames together, do whitening
block = zeros(totalsize,W);
q = 1;
for i = 1:length(alldata)
lfbe = alldata{i};
[L,W] = size(lfbe);
block(q:q+L-1,:) = lfbe;
q = q + L;
end
mu1 = mean(block);
block = block - repmat(mu1,size(block,1),1);
[e v] = eig(cov(block));
else
fprintf('Number of files processed (logfbw) = %d\n',numfile);
end
pass = 1;
end