-
Notifications
You must be signed in to change notification settings - Fork 0
/
mfcc.m
86 lines (66 loc) · 1.78 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
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
%Llama a las demas funciones
function mfcc = mfcc(y,fv,fbanks)
overlap_percentage = 0.5;
frame = 0.02; %20 ms
total_samples = rows(y);
frame_size = fv*frame;
overlap = overlap_percentage*frame_size;
yp = preemphasis(y,rows(y));
%figure(1);
%plot(y);
%title("original");
%figure(2);
%plot(yp);
%title("preemphasis");
%funcion de hamming
ham = hamming(frame_size);
total_frames = floor(total_samples/overlap)-1;
%Se iteran por los frames
%sacarle magic numbers
coef_amount = 13;
filter_amount = 33;
for f = 1: total_frames
yw = windowing(yp,frame_size,f,overlap,ham);
yf = fft(yw);
yper = periodogram(yf,frame_size);
%if f == 4
% figure(3)
% plot(yper);
%end
for fb = 1 : rows(fbanks)
energy = 0;
filterbank = fbanks(fb,:);
for fftpoint = 1 : columns(filterbank)
energy += filterbank(fftpoint)*yper(fftpoint);
end
filterenergies(fb)=energy;
end
for n = 1 : (coef_amount - 1)
c=0;
for k = 1 : filter_amount
c+=log(filterenergies(k))*cos(n*(k-0.5)*pi/filter_amount);
end
coef(n)=c;
end
energycoef = loggedenergy(y,frame_size);
n+=1;
coef(n)=energycoef;
for k = 1 : n
mfcc(k,f) = coef(k);
end
end
%Se calculan los deltas
delta(1,:) = (2*(mfcc(:,3)) + (mfcc(:,2)))/10;
delta(2,:) = (2*(mfcc(:,4)) + (mfcc(:,3) - mfcc(:,1)))/10;
for f = 3 : (total_frames-2)
delta(f,:) = (2*(mfcc(:,f+2) - mfcc(:,f-2)) + (mfcc(:,f+1) - mfcc(:,f-1)))/10;
end
delta(total_frames-1,:) = (2*(-1*mfcc(:,total_frames-3)) + (mfcc(:,total_frames) - mfcc(:,total_frames-2)))/10;
delta(total_frames,:) = (2*(-1*mfcc(:,total_frames-2)) + (-1*mfcc(:,total_frames-1)))/10;
%guardo los deltas
for f = 1 : total_frames
for k = 1 : coef_amount
mfcc(coef_amount + k,f) = delta(f,k);
end
end
mfcc;