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