Daniel@0: function varargout = mirregularity(orig,varargin) Daniel@0: % i = mirregularity(x) calculates the irregularity of a spectrum, i.e., Daniel@0: % the degree of variation of the successive peaks of the spectrum. Daniel@0: % Specification of the definition of irregularity: Daniel@0: % mirregularity(...,'Jensen') is based on (Jensen, 1999), Daniel@0: % where the irregularity is the sum of the square of the Daniel@0: % difference in amplitude between adjoining partials. Daniel@0: % (Default approach) Daniel@0: % mirregularity(...,'Krimphoff') is based on (Krimphoff et al., 1994), Daniel@0: % where the irregularity is the sum of the amplitude minus the Daniel@0: % mean of the preceding, same and next amplitude. Daniel@0: % If the input x is not already a spectrum with peak extracted, the peak Daniel@0: % picking is performed prior to the calculation of the irregularity. Daniel@0: % In this case the 'Contrast' parameter used in mirpeaks can be Daniel@0: % modified, and is set by default to .1. Daniel@0: % Daniel@0: % [Krimphoff et al. 1994] J. Krimphoff, S. McAdams, S. Winsberg, Daniel@0: % Caracterisation du timbre des sons complexes. II Analyses Daniel@0: % acoustiques et quantification psychophysique. Journal de Physique Daniel@0: % IV, Colloque C5, Vol. 4. 1994. Daniel@0: % [Jensen, 1999] K. Jensen, Timbre Models of Musical Sounds, Ph.D. Daniel@0: % dissertation, University of Copenhagen, Rapport Nr. 99/7. Daniel@0: Daniel@0: Daniel@0: meth.type = 'String'; Daniel@0: meth.default = 'Jensen'; Daniel@0: meth.choice = {'Jensen','Krimphoff'}; Daniel@0: option.meth = meth; Daniel@0: Daniel@0: cthr.key = 'Contrast'; Daniel@0: cthr.type = 'Integer'; Daniel@0: cthr.default = .01; Daniel@0: option.cthr = cthr; Daniel@0: Daniel@0: specif.option = option; Daniel@0: Daniel@0: varargout = mirfunction(@mirregularity,orig,varargin,nargout,specif,@init,@main); Daniel@0: Daniel@0: Daniel@0: function [x type] = init(x,option) Daniel@0: if not(isamir(x,'mirdata')) || isamir(x,'miraudio') Daniel@0: x = mirspectrum(x); Daniel@0: end Daniel@0: if not(haspeaks(x)) Daniel@0: x = mirpeaks(x,'Reso','SemiTone','Contrast',option.cthr); %% FIND BETTER Daniel@0: end Daniel@0: type = 'mirscalar'; Daniel@0: Daniel@0: Daniel@0: function o = main(x,option,postoption) Daniel@0: if iscell(x) Daniel@0: x = x{1}; Daniel@0: end Daniel@0: m = get(x,'PeakVal'); Daniel@0: p = get(x,'PeakPos'); Daniel@0: y = cell(1,length(m)); Daniel@0: for h = 1:length(m) Daniel@0: y{h} = cell(1,length(m{h})); Daniel@0: for k = 1:length(m{h}) Daniel@0: y{h}{k} = zeros(size(m{h}{k})); Daniel@0: for j = 1:size(m{h}{k},3) Daniel@0: for l = 1:size(m{h}{k},2) Daniel@0: state = warning('query','MATLAB:divideByZero'); Daniel@0: warning('off','MATLAB:divideByZero'); Daniel@0: mm = m{h}{k}{1,l,j}; Daniel@0: pp = p{h}{k}{1,l,j}; Daniel@0: [pp oo] = sort(pp); % Sort peaks in ascending order of x abscissae. Daniel@0: mm = mm(oo); Daniel@0: if strcmpi(option.meth,'Jensen') Daniel@0: y{h}{k}(1,l,j) = sum((mm(2:end,:)-mm(1:end-1,:)).^2)... Daniel@0: ./sum(mm.^2); Daniel@0: elseif strcmpi(option.meth,'Krimphoff') Daniel@0: avrg = filter(ones(3,1),1,mm)/3; Daniel@0: y{h}{k}(1,l,j) = log10(sum(abs(mm(2:end-1,:)-avrg(3:end)))); Daniel@0: end Daniel@0: warning(state.state,'MATLAB:divideByZero'); Daniel@0: if isnan(y{h}{k}(1,l,j)) Daniel@0: y{h}{k}(1,l,j) = 0; Daniel@0: end Daniel@0: end Daniel@0: end Daniel@0: end Daniel@0: end Daniel@0: if isa(x,'mirspectrum') Daniel@0: t = 'Spectral irregularity'; Daniel@0: else Daniel@0: t = ['Irregularity of ',get(x,'Title')];; Daniel@0: end Daniel@0: i = mirscalar(x,'Data',y,'Title',t); Daniel@0: o = {i,x};