Mercurial > hg > emotion-detection-top-level
annotate Code/Descriptors/Matlab/Common/SpectralCentroid.m @ 4:92ca03a8fa99 tip
Update to ICASSP 2013 benchmark
author | Dawn Black |
---|---|
date | Wed, 13 Feb 2013 11:02:39 +0000 |
parents | |
children |
rev | line source |
---|---|
Dawn@4 | 1 function C = SpectralCentroid( signal, windowLength, step, fs) |
Dawn@4 | 2 |
Dawn@4 | 3 % function C = SpectralCentroid(signal,windowLength, step, fs) |
Dawn@4 | 4 % |
Dawn@4 | 5 % This function computes the spectral centroid feature of an audio signal |
Dawn@4 | 6 % ARGUMENTS: |
Dawn@4 | 7 % - signal: the audio samples |
Dawn@4 | 8 % - windowLength: the length of the window analysis (in number of samples) |
Dawn@4 | 9 % - step: the step of the window analysis (in number of samples) |
Dawn@4 | 10 % - fs: the sampling frequency |
Dawn@4 | 11 % |
Dawn@4 | 12 % RETURNS: |
Dawn@4 | 13 % - C: the sequence of the spectral centroid feature |
Dawn@4 | 14 % |
Dawn@4 | 15 |
Dawn@4 | 16 signal = signal / max(abs(signal)); |
Dawn@4 | 17 curPos = 1; |
Dawn@4 | 18 L = length(signal); |
Dawn@4 | 19 numOfFrames = floor((L-windowLength)/step) + 1; |
Dawn@4 | 20 H = hamming(windowLength); |
Dawn@4 | 21 m = ((fs/(2*windowLength))*[1:windowLength])'; |
Dawn@4 | 22 C = zeros(numOfFrames,1); |
Dawn@4 | 23 for (i=1:numOfFrames) |
Dawn@4 | 24 window = H.*(signal(curPos:curPos+windowLength-1))'; |
Dawn@4 | 25 FFT = (abs(fft(window,2*windowLength))); |
Dawn@4 | 26 FFT = FFT(1:windowLength); |
Dawn@4 | 27 FFT = FFT / max(FFT); |
Dawn@4 | 28 C(i) = sum(m.*FFT)/sum(FFT); |
Dawn@4 | 29 if (sum(window.^2)<0.010) |
Dawn@4 | 30 C(i) = 0.0; |
Dawn@4 | 31 end |
Dawn@4 | 32 curPos = curPos + step; |
Dawn@4 | 33 end |
Dawn@4 | 34 C = C / (fs/2); |