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