-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBird_Classifier.m
More file actions
142 lines (93 loc) · 4.1 KB
/
Bird_Classifier.m
File metadata and controls
142 lines (93 loc) · 4.1 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
function Bird_Classifier
% Bird voice classifier is the software that classifies bird voices into the different classes.
% Classifier is based on the idea of unsupervised classification. Cheak README file for comprehensive
% information of the system.
%% Prepare path and file
% From where to read
pathFrom = 'C:\Users\Tero\Desktop\Mathlab\Machinelearning\Fidecula\';
ident = '*.wav';
% Construct wav_path to provide it to audioreader later
result = horzcat(pathFrom,ident);
wav_path = dir(result);
% Where to create output files
pathTo = 'C:\Users\Tero\Desktop\Mathlab\Machinelearning\ClassifiedStuff\';
% If file exists delete it and all its content
if length(dir(pathTo)) > 50
rmdir ClassifiedStuff s
pause(60);
end
% Create target folder to pathTo
mkdir('ClassifiedStuff');
f = fullfile('C:\Users\Tero\Desktop\Mathlab\Machinelearning\','ClassifiedStuff');
save(f)
%% Loop through files and test them against references
% Initially this is true to allow adding the first reference to the reference list
r = true;
% These could be in the same list but I didn't spend extra time to figuring out syntax for that
referenssit = {};
s_refeaanet = struct('name',{},'date',{},'bytes',{},'isdir',{},'datenum',{});
curve_lista = {};
% Loop through the original list of the voices
for t = 2:length(wav_path)
testattava = wav_path(t).name;
y1 = audioread([pathFrom wav_path(t).name]); % Read audiofile
% harmonic_frequency_seek-function was provided for me from Tampere University of Technology.
curve1 = harmonic_frequency_seek(y1); % Calculate harmonic frequencies
% If decision maker established a new class this will be true
if r == true
referenssit{end+1} = wav_path(t-1).name;
referenssit = referenssit';
y = audioread([pathFrom wav_path(t-1).name]);
curve = harmonic_frequency_seek(y);
curve_lista{end+1} = curve;
s_refeaanet(end+1) = wav_path(t-1);
end
% Loop through reference list to test against everyone of them
for refe = 1:length(referenssit)
% Get reference curve
curve = curve_lista{1,refe}(1,:);
% Execute Dynamic Time Warping to calculate difference between reference curve and the curve to be tested
diag = dtw(curve,curve1);
list(refe,:) = [referenssit(refe),diag];
r = false; % reset boolean
end
%% Decision maker
% If reference curve is not found new class will be established and
% file will be added there
[what_class, amount_of_classes] = FileReader_Output(referenssit(refe),pathTo);
if strcmp(what_class,'ei asettunut') == 1
FileWriter(pathTo,what_class,amount_of_classes,referenssit);
end
% The system is allowed to add a file to the certain class if
% difference between reference of class and voice to be tested is small enough
listan_diagit = list(:,2);
d = cell2mat(listan_diagit);
[M,I] = min(d);
% Index of the class to be added
listan_referenssit = list(:,1);
refer = cell2mat(listan_referenssit(I));
% M is warping limit. Smaller value will eventually lead to greater number of classes,
% because it raises standards to be "similar" voice
if M < 7000
class = FileReader_Output(refer,pathTo);
FileWriter(pathTo,class,amount_of_classes,testattava);
else
what_class = 'ei asettunut'; % allows establishing the new class
FileWriter(pathTo,what_class,amount_of_classes,testattava); % creates new class and adds file there
r = true;
end
end
%% Plot histogram
content_Classfied_Folder = poista_turhat_pisteet(dir(pathTo));
for m = 1:length(content_Classfied_Folder)
class_name = content_Classfied_Folder(m).name;
class_index = m;
temp = poista_turhat_pisteet(dir(horzcat(pathTo,class_name)));
number_of_files = length(temp);
x(m) = class_index;
z(m) = number_of_files;
end
figure(2)
bar(x,z);
title('Voices in class');
end