comparison toolboxes/MIRtoolbox1.3.2/MIRToolbox/mirrolloff.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 function varargout = mirrolloff(x,varargin)
2 % r = mirrolloff(s) calculates the spectral roll-off in Hz.
3 % Optional arguments:
4 % r = mirrolloff(s,'Threshold',p) specifies the energy threshold in
5 % percentage. (Default: .85)
6 % p can be either a value between 0 and 1. But if p exceeds 1, it
7 % is understood as a percentage, i.e. between 1 and 100.
8 % In other words, r is the frequency under which p percents
9 % of the spectral energy is distributed.
10 %
11 % Typical values for the energy threshold:
12 % 85% in G. Tzanetakis, P. Cook. Musical genre classification of audio
13 % signals. IEEE Tr. Speech and Audio Processing, 10(5),293-302, 2002.
14 % 95% in T. Pohle, E. Pampalk, G. Widmer. Evaluation of Frequently
15 % Used Audio Features for Classification of Music Into Perceptual
16 % Categories, ?
17
18 p.key = 'Threshold';
19 p.type = 'Integer';
20 p.default = 85;
21 p.position = 2;
22 option.p = p;
23
24 specif.option = option;
25
26 varargout = mirfunction(@mirrolloff,x,varargin,nargout,specif,@init,@main);
27
28
29 function [s type] = init(x,option)
30 s = mirspectrum(x);
31 type = 'mirscalar';
32
33
34 function r = main(s,option,postoption)
35 if iscell(s)
36 s = s{1};
37 end
38 m = get(s,'Magnitude');
39 f = get(s,'Frequency');
40 if option.p>1
41 option.p = option.p/100;
42 end
43 v = mircompute(@algo,m,f,option.p);
44 r = mirscalar(s,'Data',v,'Title','Rolloff','Unit','Hz.');
45
46
47 function v = algo(m,f,p)
48 cs = cumsum(m); % accumulation of spectrum energy
49 thr = cs(end,:,:)*p; % threshold corresponding to the rolloff point
50 v = zeros(1,size(cs,2),size(cs,3));
51 for l = 1:size(cs,3)
52 for k = 1:size(cs,2)
53 fthr = find(cs(:,k,l) >= thr(1,k,l)); % find the location of the threshold
54 if isempty(fthr)
55 v(1,k,l) = NaN;
56 else
57 v(1,k,l) = f(fthr(1));
58 end
59 end
60 end