-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathFeatureSpectralMfccs.m
37 lines (29 loc) · 1.13 KB
/
FeatureSpectralMfccs.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
% ======================================================================
%> @brief computes the MFCCs from the magnitude spectrum (see Slaney)
%> called by ::ComputeFeature
%>
%> @param X: spectrogram (dimension FFTLength X Observations)
%> @param f_s: sample rate of audio data (unused)
%>
%> @retval vmfcc mel frequency cepstral coefficients
% ======================================================================
function [vmfcc] = FeatureSpectralMfccs(X, f_s)
iNumCoeffs = 13;
% allocate memory
vmfcc = zeros(iNumCoeffs, size(X,2));
H = ToolMfccFb(size(X,1), f_s);
T = GenerateDctMatrix (size(H,1), iNumCoeffs);
for (n = 1:size(X,2))
% compute the mel spectrum
X_Mel = log10(H * X(:,n)+1e-20);
% calculate the mfccs
vmfcc(:,n) = T * X_Mel;
end
end
%> see function mfcc.m from Slaneys Auditory Toolbox
function [T] = GenerateDctMatrix (iNumBands, iNumCepstralCoeffs)
T = cos((0:(iNumCepstralCoeffs-1))' * ...
(2*(0:(iNumBands-1))+1) * pi/2/iNumBands);
T = T/sqrt(iNumBands/2);
T(1,:) = T(1,:) * sqrt(2)/2;
end