-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateMatrix.m
More file actions
64 lines (50 loc) · 1.52 KB
/
createMatrix.m
File metadata and controls
64 lines (50 loc) · 1.52 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
function [A, notes] = createMatrix(binsPerSemitone)
% A: a matrix. Each row corresponds to frequency bin. Each column
% corresponds to instrument/note.
% notes: a vector containing the note names (e.g. ViolinAs5), 1 for
% each column
% setup
LOGSEMI = 0.057763;
INC = LOGSEMI / binsPerSemitone;
NUMBINS = ceil(log(22050) / INC);
% acquire relevant files (first 3 junk)
fileList = dir('../Data');
fileNames = {};
for i = 4:size(fileList, 1)
fileNames = [fileNames; fileList(i).name];
end
% names of instruments
INST_NAMES = {'Saxophone'; 'Clarinet'; 'Cello'; 'Flute'; 'Horn';
'Trumpet'; 'Tuba'; 'Violin'};
% get names of instruments
INST_NAMES = upper(INST_NAMES);
notes = cell(size(fileNames));
for i = 1:size(fileNames)
fileName = upper(fileNames(i));
% find instrument
inst = '';
for j = 1:size(INST_NAMES, 1)
foundCell = strfind(fileName, INST_NAMES{j});
if foundCell{1}
inst = INST_NAMES{j};
break;
end
end
% find note
noteStartCell = regexp(fileName, '[ABCDEFG]S?[0123456789]');
noteStart = noteStartCell{1};
noteEnd = noteStart + 1;
if fileName{1}(noteStart + 1) == 'S'
noteEnd = noteStart + 2;
end
note = fileName{1}(noteStart:noteEnd);
notes{i} = [inst note];
end
% for each file, add binned vector to matrix A
numFiles = size(fileNames, 1);
A = zeros(NUMBINS, numFiles);
for i = 1:numFiles
[y, fs] = aiffread(strcat('../Data/', fileNames{i}));
A(:, i) = getFFTBin(y, fs, binsPerSemitone);
end
end