-
Notifications
You must be signed in to change notification settings - Fork 3
/
experiment_raw_sumstats.m
56 lines (40 loc) · 1.37 KB
/
experiment_raw_sumstats.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
addpath('Voicebox');
files = getAllFiles('data/training');
window = windows('hanning');
%% Build training and test matrices
fprintf('Building trainingset...\n');
trainingSet = zeros(numel(files), 258);
trainingLabels = zeros(numel(files), 1);
for i = 1:numel(files)
filename = char(files(i));
label = getLabelByFilename(filename);
trainingLabels(i) = label;
[y, fs] = readwav(filename);
frames = enframe(y, window, length(window) / 2)';
F = rfft(frames);
F = log10(abs(F));
f = [mean(F') std(F')];
trainingSet(i,:) = f;
end
fprintf('Building testset...\n');
files = getAllFiles('data/test');
testSet = zeros(numel(files), 258);
testLabels = zeros(numel(files), 1);
for i = 1:numel(files)
filename = char(files(i));
label = getLabelByFilename(filename);
testLabels(i) = label;
[y, fs] = readwav(filename);
frames = enframe(y, window, length(window) / 2)';
F = rfft(frames);
F = log10(abs(F));
f = [mean(F') std(F')];
testSet(i,:) = f;
end
%% Classifying with SVM
fprintf('Training...\n');
svm = svmtrain(trainingLabels, trainingSet);
fprintf('Testing...\n');
[predictedLabels, accuracy] = svmpredict(testLabels, testSet, svm);
performance = sum(predictedLabels==testLabels)/length(testLabels);
fprintf('Performance: %2.4f (%i/%i)\n', performance, sum(predictedLabels==testLabels), length(testLabels));