d@0
|
1 function [mfccFilterWeights mfccDCTMatrix] = initMFCCVariables(sampleRate, FFTsize)
|
d@0
|
2
|
d@0
|
3 Fs = sampleRate;
|
d@0
|
4 Nfft = FFTsize;
|
d@0
|
5
|
d@0
|
6 %Filter bank parameters
|
d@0
|
7 lowestFrequency = 133.3333;
|
d@0
|
8 linearFilters = 13;
|
d@0
|
9 linearSpacing = 66.66666666;
|
d@0
|
10 logFilters = 27;
|
d@0
|
11 logSpacing = 1.0711703;
|
d@0
|
12 cepstralCoefficients = 13;
|
d@0
|
13
|
d@0
|
14 % Keep this around for later....
|
d@0
|
15 totalFilters = linearFilters + logFilters;
|
d@0
|
16
|
d@0
|
17 % Now figure the band edges. Interesting frequencies are spaced
|
d@0
|
18 % by linearSpacing for a while, then go logarithmic. First figure0
|
d@0
|
19 % all the interesting frequencies. Lower, center, and upper band
|
d@0
|
20 % edges are all consecutive interesting frequencies.
|
d@0
|
21 freqs = lowestFrequency + (0:linearFilters-1)*linearSpacing;
|
d@0
|
22 freqs(linearFilters+1:totalFilters+2) = freqs(linearFilters) * logSpacing.^(1:logFilters+2);
|
d@0
|
23 lower = freqs(1:totalFilters);
|
d@0
|
24 center = freqs(2:totalFilters+1);
|
d@0
|
25 upper = freqs(3:totalFilters+2);
|
d@0
|
26
|
d@0
|
27 % each filter has unit weight, assuming a triangular weighting function
|
d@0
|
28 mfccFilterWeights = zeros(totalFilters,Nfft/2);
|
d@0
|
29 triangleHeight = 2./(upper-lower);
|
d@0
|
30 fftFreqs = (0:Nfft/2-1)/(Nfft)*Fs;
|
d@0
|
31 for chan=1:totalFilters
|
d@0
|
32 mfccFilterWeights(chan,:) = (fftFreqs > lower(chan) & fftFreqs <= center(chan)).* triangleHeight(chan).*(fftFreqs-lower(chan))/(center(chan)-lower(chan)) + ...
|
d@0
|
33 (fftFreqs > center(chan) & fftFreqs < upper(chan)) .* triangleHeight(chan).*(upper(chan)-fftFreqs)/(upper(chan)-center(chan));
|
d@0
|
34 end
|
d@0
|
35
|
d@0
|
36 % Figure out Discrete Cosine Transform. We want a matrix
|
d@0
|
37 % dct(i,j) which is totalFilters x cepstralCoefficients in size.
|
d@0
|
38 % The i,j component is given by cos( i * (j+0.5)/totalFilters pi )
|
d@0
|
39 % where we have assumed that i and j start at 0.
|
d@0
|
40 mfccDCTMatrix = 1/sqrt(totalFilters/2)*cos((0:(cepstralCoefficients-1))' * (2*(0:(totalFilters-1))+1) * pi/2/totalFilters);
|
d@0
|
41 mfccDCTMatrix(1,:) = mfccDCTMatrix(1,:) * sqrt(2)/2;
|
d@0
|
42
|