annotate toolboxes/MIRtoolbox1.3.2/MIRToolbox/mirregularity.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 = mirregularity(orig,varargin)
Daniel@0 2 % i = mirregularity(x) calculates the irregularity of a spectrum, i.e.,
Daniel@0 3 % the degree of variation of the successive peaks of the spectrum.
Daniel@0 4 % Specification of the definition of irregularity:
Daniel@0 5 % mirregularity(...,'Jensen') is based on (Jensen, 1999),
Daniel@0 6 % where the irregularity is the sum of the square of the
Daniel@0 7 % difference in amplitude between adjoining partials.
Daniel@0 8 % (Default approach)
Daniel@0 9 % mirregularity(...,'Krimphoff') is based on (Krimphoff et al., 1994),
Daniel@0 10 % where the irregularity is the sum of the amplitude minus the
Daniel@0 11 % mean of the preceding, same and next amplitude.
Daniel@0 12 % If the input x is not already a spectrum with peak extracted, the peak
Daniel@0 13 % picking is performed prior to the calculation of the irregularity.
Daniel@0 14 % In this case the 'Contrast' parameter used in mirpeaks can be
Daniel@0 15 % modified, and is set by default to .1.
Daniel@0 16 %
Daniel@0 17 % [Krimphoff et al. 1994] J. Krimphoff, S. McAdams, S. Winsberg,
Daniel@0 18 % Caracterisation du timbre des sons complexes. II Analyses
Daniel@0 19 % acoustiques et quantification psychophysique. Journal de Physique
Daniel@0 20 % IV, Colloque C5, Vol. 4. 1994.
Daniel@0 21 % [Jensen, 1999] K. Jensen, Timbre Models of Musical Sounds, Ph.D.
Daniel@0 22 % dissertation, University of Copenhagen, Rapport Nr. 99/7.
Daniel@0 23
Daniel@0 24
Daniel@0 25 meth.type = 'String';
Daniel@0 26 meth.default = 'Jensen';
Daniel@0 27 meth.choice = {'Jensen','Krimphoff'};
Daniel@0 28 option.meth = meth;
Daniel@0 29
Daniel@0 30 cthr.key = 'Contrast';
Daniel@0 31 cthr.type = 'Integer';
Daniel@0 32 cthr.default = .01;
Daniel@0 33 option.cthr = cthr;
Daniel@0 34
Daniel@0 35 specif.option = option;
Daniel@0 36
Daniel@0 37 varargout = mirfunction(@mirregularity,orig,varargin,nargout,specif,@init,@main);
Daniel@0 38
Daniel@0 39
Daniel@0 40 function [x type] = init(x,option)
Daniel@0 41 if not(isamir(x,'mirdata')) || isamir(x,'miraudio')
Daniel@0 42 x = mirspectrum(x);
Daniel@0 43 end
Daniel@0 44 if not(haspeaks(x))
Daniel@0 45 x = mirpeaks(x,'Reso','SemiTone','Contrast',option.cthr); %% FIND BETTER
Daniel@0 46 end
Daniel@0 47 type = 'mirscalar';
Daniel@0 48
Daniel@0 49
Daniel@0 50 function o = main(x,option,postoption)
Daniel@0 51 if iscell(x)
Daniel@0 52 x = x{1};
Daniel@0 53 end
Daniel@0 54 m = get(x,'PeakVal');
Daniel@0 55 p = get(x,'PeakPos');
Daniel@0 56 y = cell(1,length(m));
Daniel@0 57 for h = 1:length(m)
Daniel@0 58 y{h} = cell(1,length(m{h}));
Daniel@0 59 for k = 1:length(m{h})
Daniel@0 60 y{h}{k} = zeros(size(m{h}{k}));
Daniel@0 61 for j = 1:size(m{h}{k},3)
Daniel@0 62 for l = 1:size(m{h}{k},2)
Daniel@0 63 state = warning('query','MATLAB:divideByZero');
Daniel@0 64 warning('off','MATLAB:divideByZero');
Daniel@0 65 mm = m{h}{k}{1,l,j};
Daniel@0 66 pp = p{h}{k}{1,l,j};
Daniel@0 67 [pp oo] = sort(pp); % Sort peaks in ascending order of x abscissae.
Daniel@0 68 mm = mm(oo);
Daniel@0 69 if strcmpi(option.meth,'Jensen')
Daniel@0 70 y{h}{k}(1,l,j) = sum((mm(2:end,:)-mm(1:end-1,:)).^2)...
Daniel@0 71 ./sum(mm.^2);
Daniel@0 72 elseif strcmpi(option.meth,'Krimphoff')
Daniel@0 73 avrg = filter(ones(3,1),1,mm)/3;
Daniel@0 74 y{h}{k}(1,l,j) = log10(sum(abs(mm(2:end-1,:)-avrg(3:end))));
Daniel@0 75 end
Daniel@0 76 warning(state.state,'MATLAB:divideByZero');
Daniel@0 77 if isnan(y{h}{k}(1,l,j))
Daniel@0 78 y{h}{k}(1,l,j) = 0;
Daniel@0 79 end
Daniel@0 80 end
Daniel@0 81 end
Daniel@0 82 end
Daniel@0 83 end
Daniel@0 84 if isa(x,'mirspectrum')
Daniel@0 85 t = 'Spectral irregularity';
Daniel@0 86 else
Daniel@0 87 t = ['Irregularity of ',get(x,'Title')];;
Daniel@0 88 end
Daniel@0 89 i = mirscalar(x,'Data',y,'Title',t);
Daniel@0 90 o = {i,x};