-
Notifications
You must be signed in to change notification settings - Fork 102
/
extract_features.m
44 lines (38 loc) · 1.15 KB
/
extract_features.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
function [features, num_of_success] = extract_features(db, func)
% db - a database to extract the features from
% func - a function that extracts the features for a single database entry
TRIM_SILENCE = true;
GYRO = true;
NUM_OF_ENTRIES = length(db);
GYRO_DIM = 1;
FS = 8000;
features = {};
num_of_success = 0;
for k = 1:NUM_OF_ENTRIES
try
[wavdata, samp_rate] = read(db, k);
wavdata = (wavdata{1});
if GYRO
wavdata = wavdata(:, GYRO_DIM);
end
wavdata = resample(wavdata, FS, samp_rate);
fs = FS;
if TRIM_SILENCE
if GYRO
% cut 0.5 second at the beginning and a second from the end
wavdata = wavdata(4000:end-8000);
end
[wavdata, nseg] = get_voiced_segments(wavdata, fs);
else
nseg = 1;
end
if nseg > 0
num_of_success = num_of_success + 1;
features{num_of_success} = func(wavdata, fs);
end
catch ME
% print error source
ME.stack(1)
end
end
end