forked from alexanderlerch/ACA-Code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FeatureSpectralMfccs.m
39 lines (30 loc) · 1.09 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
38
39
%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));
% create filters
H = ToolMfccFb(size(X, 1), f_s);
% create transformation matrix
T = GenerateDctMatrix_I (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_I (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