annotate toolboxes/MIRtoolbox1.3.2/MIRToolbox/mirrolloff.m @ 0:cc4b1211e677 tip

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