Mercurial > hg > batch-feature-extraction-tool
diff Source/mfcc.m @ 0:25bf17994ef1
First commit. VS2013, Codeblocks and Mac OSX configuration
author | Geogaddi\David <d.m.ronan@qmul.ac.uk> |
---|---|
date | Thu, 09 Jul 2015 01:12:16 +0100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Source/mfcc.m Thu Jul 09 01:12:16 2015 +0100 @@ -0,0 +1,73 @@ +function [ceps] = mfcc(audioFile, FFTsize, hop, mfccFilterWeights, mfccDCTMatrix) + +%Beat synched data +cepstralCoefficients = 13; +%BeatLength = 60/BPM*Fs; +%FrameSize = round(BeatLength*NoteDiv); +hop = hop; +%Nfft = 2^nextpow2(FrameSize); +Nfft = FFTsize; +FrameSize = FFTsize; +%number_of_frame = length([1:FrameSize:length(audioFile)])-1; + +seg_start = [1:FrameSize:length(audioFile)]'; +seg_stop = min(seg_start+FrameSize,length(audioFile)); + +if(seg_stop(end)-seg_start(end)~=FrameSize) + seg_stop(end) =[]; + seg_start(end)=[]; +end + +number_of_frame = length(seg_start); + +hamWindow = 0.54 - 0.46*cos(2*pi*(0:FrameSize-1)/FrameSize); + +% Filter the input with the preemphasis filter +preEmphasized = audioFile; %filter([1 -.97], 1, audioFile); + +% Allocate all the space we need for the output arrays. +ceps = zeros(cepstralCoefficients, number_of_frame); + +%Tuning related variables : +averagedPowerSpectrogram = zeros(Nfft/2,1); + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% Mel - Frequencies Cepstrum Coefficients +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +h=waitbar(0,'MFCC Calculus - Please wait..'); +for start=1:number_of_frame + + %Frame position + waitbar(start/number_of_frame); + + first = seg_start(start); + last = seg_stop(start); + + + %Hanning window mult + fftData = zeros(1,Nfft); + preEmphasizedSlice = preEmphasized(first:last-1); + fftData(1:FrameSize) = preEmphasizedSlice.*hamWindow'; + + %magnitude of the fft + fftMag = abs(fft(fftData)); + fftMag = fftMag(1:Nfft/2); + + %Sum the spectrogram magnitude + averagedPowerSpectrogram = averagedPowerSpectrogram + fftMag'.^2; + + %fft data into filter bank outputs + Log Compression + FilteredFFT = mfccFilterWeights * fftMag'; + + factorLogCompr = 10; + addTermLogCompr = 1; + earMag = log10(addTermLogCompr+FilteredFFT*factorLogCompr); + + %Cosine transform to reduce dimensionality + ceps(:,start) = mfccDCTMatrix * earMag; + +end %Loop on frames + +close(h); + +end