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