comparison toolboxes/MIRtoolbox1.3.2/MIRToolbox/mirregularity.m @ 0:e9a9cd732c1e tip

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