-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcentroid.m
57 lines (54 loc) · 1.66 KB
/
centroid.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
function [C, CMean, CSD, CMax] = SpecCentroid(snd,fs,nfft,window,noverlap)
%CENTROID Calculates spectral centroid of a sound.
% C = CENRTROID(SOUND, FS) calculates the spectral centroid of a given
% sound. Fs is the sample frequency; the window length is the minimum of 2048 and
% the sample length; overlap is 80%.
%
% [C, CMean, CSD, CMax] = CENRTROID(SOUND, FS) also calculates the mean,
% standard deviation and maximum of spectral centroid.
%
% C = CENRTROID(SOUND,FS,NFFT);
% C = CENRTROID(SOUND,FS,NFFT,WINDOW);
% C = CENRTROID(SOUND,FS,NFFT,WINDOW,NOVERLAP)
% Read the manual of the SPECGRAM command for the parameters.
%
% Example:
% [s, fs] = wavread('testsound.wav');
% c = centroid(s, fs);
% Uses:
% Matlab Signal Processing Toolbox
%
% References:
% Tzanetakis, G., Essl, G. and Cook, P.
% In: Proc. Int. Symposium on Music Information
% Retrieval (ISMIR), Bloomington, Indiana, 2001
%
% Frederik Nagel and Michael Großbach
% Institute of Music Physiology and Musicians' Medicine
% Hanover University of Music and Drama
% Hannover
% Germany
%
% e-mail: [email protected]
% homepage: http://www.immm.hmt-hannover.de
%
% May 29, 2006.
%
% See also SPECGRAM, FFT
error(nargchk(2, 5, nargin))
if(nargin==2)
nfft = min([length(snd) 2048]);
window = nfft;
noverlap = round(window*.8);
s = specgram(snd, nfft, fs, window, noverlap);
elseif (nargin==3)
s = specgram(snd, nfft, fs);
elseif (nargin==4)
s = specgram(snd, nfft, fs, window);
elseif (nargin==5)
s = specgram(snd, nfft, fs, window, noverlap);
end
C = sum((repmat((1:size(s,1))',1,size(s,2)) .* abs(s))) ./ sum(abs(s));
CMean = mean(C);
CSD = std(C);
CMax = max(C);