comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:25bf17994ef1
1 function [ceps] = mfcc(audioFile, FFTsize, hop, mfccFilterWeights, mfccDCTMatrix)
2
3 %Beat synched data
4 cepstralCoefficients = 13;
5 %BeatLength = 60/BPM*Fs;
6 %FrameSize = round(BeatLength*NoteDiv);
7 hop = hop;
8 %Nfft = 2^nextpow2(FrameSize);
9 Nfft = FFTsize;
10 FrameSize = FFTsize;
11 %number_of_frame = length([1:FrameSize:length(audioFile)])-1;
12
13 seg_start = [1:FrameSize:length(audioFile)]';
14 seg_stop = min(seg_start+FrameSize,length(audioFile));
15
16 if(seg_stop(end)-seg_start(end)~=FrameSize)
17 seg_stop(end) =[];
18 seg_start(end)=[];
19 end
20
21 number_of_frame = length(seg_start);
22
23 hamWindow = 0.54 - 0.46*cos(2*pi*(0:FrameSize-1)/FrameSize);
24
25 % Filter the input with the preemphasis filter
26 preEmphasized = audioFile; %filter([1 -.97], 1, audioFile);
27
28 % Allocate all the space we need for the output arrays.
29 ceps = zeros(cepstralCoefficients, number_of_frame);
30
31 %Tuning related variables :
32 averagedPowerSpectrogram = zeros(Nfft/2,1);
33
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 %%% Mel - Frequencies Cepstrum Coefficients
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 h=waitbar(0,'MFCC Calculus - Please wait..');
38 for start=1:number_of_frame
39
40 %Frame position
41 waitbar(start/number_of_frame);
42
43 first = seg_start(start);
44 last = seg_stop(start);
45
46
47 %Hanning window mult
48 fftData = zeros(1,Nfft);
49 preEmphasizedSlice = preEmphasized(first:last-1);
50 fftData(1:FrameSize) = preEmphasizedSlice.*hamWindow';
51
52 %magnitude of the fft
53 fftMag = abs(fft(fftData));
54 fftMag = fftMag(1:Nfft/2);
55
56 %Sum the spectrogram magnitude
57 averagedPowerSpectrogram = averagedPowerSpectrogram + fftMag'.^2;
58
59 %fft data into filter bank outputs + Log Compression
60 FilteredFFT = mfccFilterWeights * fftMag';
61
62 factorLogCompr = 10;
63 addTermLogCompr = 1;
64 earMag = log10(addTermLogCompr+FilteredFFT*factorLogCompr);
65
66 %Cosine transform to reduce dimensionality
67 ceps(:,start) = mfccDCTMatrix * earMag;
68
69 end %Loop on frames
70
71 close(h);
72
73 end