-
Notifications
You must be signed in to change notification settings - Fork 0
/
mfcc.m
54 lines (48 loc) · 1.53 KB
/
mfcc.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
%number songs from 1 to n=# of songs as in ground_truth.csv
%save ground_truth.csv as ground_truth.xlsx
addpath ./Data/software/ma
n=4;%Makes the repository run as is
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%{
n=4 allows you to run mfcc.m in the repository as is.
To make the rest of the code run (Graph Laplacian, etc.), you need
729 .wav files in ./Data/tracks/ and to change to n=729.
%}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
p=struct('fs',11025,'visu',0); %visu=1 include plots, visu=0 don't include
i=1;
song=loadwav(['./Data/tracks/',num2str(i),'.wav']);
mfccvals=ma_mfcc(song,p);
j=size(mfccvals,2); %number of time frames (min of all songs)
%for uniformity, take the first j= 1653 frames from the middle 2 minutes of
%each song
for i=2:n
song=loadwav(['./Data/tracks/',num2str(i),'.wav']);
mfccvals=ma_mfcc(song,p);
j2=size(mfccvals,2);
if j2<j
j=j2;
end
end
j
%mfccs(w,x,y) = wth mfcc of xth frame of yth song
mfccs=zeros(20,j,n);
for i=1:n
song=loadwav(['./Data/tracks/',num2str(i),'.wav']);
mfccvals=ma_mfcc(song,p);
mfccs(:,:,i)=mfccvals(:,1:j);
end
[num,txt]=xlsread('./ground_truth.xlsx');
Name=txt(:,1);
TrackName=cell(20*n,1);
TrackNumber=cell(20*n,1);
MFCCNumber=zeros(20*n,1);
Frame=zeros(20*n,j);
for k=1:n
TrackName(20*(k-1)+1,1)=Name(k,1);
TrackNumber(20*(k-1)+1,1)={num2str(k)};
MFCCNumber(20*(k-1)+1:20*(k-1)+20)=[1:20]';
Frame(20*(k-1)+1:20*(k-1)+20,:)=mfccs(:,:,k);
end
T=table(TrackName,TrackNumber,MFCCNumber,Frame);
writetable(T,'mfccs.xlsx')