Daniel@0: function varargout = mirrolloff(x,varargin) Daniel@0: % r = mirrolloff(s) calculates the spectral roll-off in Hz. Daniel@0: % Optional arguments: Daniel@0: % r = mirrolloff(s,'Threshold',p) specifies the energy threshold in Daniel@0: % percentage. (Default: .85) Daniel@0: % p can be either a value between 0 and 1. But if p exceeds 1, it Daniel@0: % is understood as a percentage, i.e. between 1 and 100. Daniel@0: % In other words, r is the frequency under which p percents Daniel@0: % of the spectral energy is distributed. Daniel@0: % Daniel@0: % Typical values for the energy threshold: Daniel@0: % 85% in G. Tzanetakis, P. Cook. Musical genre classification of audio Daniel@0: % signals. IEEE Tr. Speech and Audio Processing, 10(5),293-302, 2002. Daniel@0: % 95% in T. Pohle, E. Pampalk, G. Widmer. Evaluation of Frequently Daniel@0: % Used Audio Features for Classification of Music Into Perceptual Daniel@0: % Categories, ? Daniel@0: Daniel@0: p.key = 'Threshold'; Daniel@0: p.type = 'Integer'; Daniel@0: p.default = 85; Daniel@0: p.position = 2; Daniel@0: option.p = p; Daniel@0: Daniel@0: specif.option = option; Daniel@0: Daniel@0: varargout = mirfunction(@mirrolloff,x,varargin,nargout,specif,@init,@main); Daniel@0: Daniel@0: Daniel@0: function [s type] = init(x,option) Daniel@0: s = mirspectrum(x); Daniel@0: type = 'mirscalar'; Daniel@0: Daniel@0: Daniel@0: function r = main(s,option,postoption) Daniel@0: if iscell(s) Daniel@0: s = s{1}; Daniel@0: end Daniel@0: m = get(s,'Magnitude'); Daniel@0: f = get(s,'Frequency'); Daniel@0: if option.p>1 Daniel@0: option.p = option.p/100; Daniel@0: end Daniel@0: v = mircompute(@algo,m,f,option.p); Daniel@0: r = mirscalar(s,'Data',v,'Title','Rolloff','Unit','Hz.'); Daniel@0: Daniel@0: Daniel@0: function v = algo(m,f,p) Daniel@0: cs = cumsum(m); % accumulation of spectrum energy Daniel@0: thr = cs(end,:,:)*p; % threshold corresponding to the rolloff point Daniel@0: v = zeros(1,size(cs,2),size(cs,3)); Daniel@0: for l = 1:size(cs,3) Daniel@0: for k = 1:size(cs,2) Daniel@0: fthr = find(cs(:,k,l) >= thr(1,k,l)); % find the location of the threshold Daniel@0: if isempty(fthr) Daniel@0: v(1,k,l) = NaN; Daniel@0: else Daniel@0: v(1,k,l) = f(fthr(1)); Daniel@0: end Daniel@0: end Daniel@0: end