d@0: function [mfccFilterWeights mfccDCTMatrix] = initMFCCVariables(sampleRate, FFTsize) d@0: d@0: Fs = sampleRate; d@0: Nfft = FFTsize; d@0: d@0: %Filter bank parameters d@0: lowestFrequency = 133.3333; d@0: linearFilters = 13; d@0: linearSpacing = 66.66666666; d@0: logFilters = 27; d@0: logSpacing = 1.0711703; d@0: cepstralCoefficients = 13; d@0: d@0: % Keep this around for later.... d@0: totalFilters = linearFilters + logFilters; d@0: d@0: % Now figure the band edges. Interesting frequencies are spaced d@0: % by linearSpacing for a while, then go logarithmic. First figure0 d@0: % all the interesting frequencies. Lower, center, and upper band d@0: % edges are all consecutive interesting frequencies. d@0: freqs = lowestFrequency + (0:linearFilters-1)*linearSpacing; d@0: freqs(linearFilters+1:totalFilters+2) = freqs(linearFilters) * logSpacing.^(1:logFilters+2); d@0: lower = freqs(1:totalFilters); d@0: center = freqs(2:totalFilters+1); d@0: upper = freqs(3:totalFilters+2); d@0: d@0: % each filter has unit weight, assuming a triangular weighting function d@0: mfccFilterWeights = zeros(totalFilters,Nfft/2); d@0: triangleHeight = 2./(upper-lower); d@0: fftFreqs = (0:Nfft/2-1)/(Nfft)*Fs; d@0: for chan=1:totalFilters d@0: mfccFilterWeights(chan,:) = (fftFreqs > lower(chan) & fftFreqs <= center(chan)).* triangleHeight(chan).*(fftFreqs-lower(chan))/(center(chan)-lower(chan)) + ... d@0: (fftFreqs > center(chan) & fftFreqs < upper(chan)) .* triangleHeight(chan).*(upper(chan)-fftFreqs)/(upper(chan)-center(chan)); d@0: end d@0: d@0: % Figure out Discrete Cosine Transform. We want a matrix d@0: % dct(i,j) which is totalFilters x cepstralCoefficients in size. d@0: % The i,j component is given by cos( i * (j+0.5)/totalFilters pi ) d@0: % where we have assumed that i and j start at 0. d@0: mfccDCTMatrix = 1/sqrt(totalFilters/2)*cos((0:(cepstralCoefficients-1))' * (2*(0:(totalFilters-1))+1) * pi/2/totalFilters); d@0: mfccDCTMatrix(1,:) = mfccDCTMatrix(1,:) * sqrt(2)/2; d@0: