wolffd@0: function d = mirdist(x,y,dist) wolffd@0: % d = mirdist(x,y) evaluates the distance between x and y. wolffd@0: % x is the feature values corresponding to one audio file, and y is the wolffd@0: % values (for the same feature) corrdponding to one (or several) wolffd@0: % audio files. wolffd@0: % If x and y are not decomposed into frames, wolffd@0: % d = mirdist(x,y,f) specifies distance function. wolffd@0: % Default value: f = 'Cosine' wolffd@0: % If x and y are composed of clustered frames (using mircluster), the wolffd@0: % cluster signatures are compared using Earth Mover Distance. wolffd@0: % (Logan, Salomon, 2001) wolffd@0: % If x and y contains peaks, the vectors representing the peak wolffd@0: % distributions are compared using Euclidean distance. wolffd@0: % (used with mirnovelty in Jacobson, 2006) wolffd@0: % wolffd@0: % The Earth Mover Distance is based on the implementation by Yossi Rubner, wolffd@0: % wrapped for Matlab by Elias Pampalk. wolffd@0: wolffd@0: if not(isa(x,'mirdata')) wolffd@0: x = miraudio(x); wolffd@0: end wolffd@0: if not(isa(y,'mirdata')) wolffd@0: y = miraudio(y); wolffd@0: end wolffd@0: wolffd@0: clx = get(x,'Clusters'); wolffd@0: if isempty(clx{1}) wolffd@0: px = get(x,'PeakPos'); wolffd@0: if not(iscell(px)) || isempty(px{1}) || ... wolffd@0: not(iscell(px{1})) || isempty(px{1}{1}) || not(iscell(px{1}{1})) wolffd@0: if nargin < 3 wolffd@0: dist = 'Cosine'; wolffd@0: end wolffd@0: wolffd@0: d = get(x,'Data'); wolffd@0: dd = d{1}{1}; wolffd@0: if iscell(dd) wolffd@0: dd = dd{1}; wolffd@0: end wolffd@0: if size(dd,2)>1 wolffd@0: if size(dd,1)>1 wolffd@0: error('ERROR IN MIRDIST: If the input is decomposed into frames, they should first be clustered.'); wolffd@0: else wolffd@0: dd = dd'; wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: e = get(y,'Data'); wolffd@0: dt = cell(1,length(e)); wolffd@0: for h = 1:length(e) wolffd@0: ee = e{h}{1}; wolffd@0: if iscell(ee) wolffd@0: ee = ee{1}; wolffd@0: end wolffd@0: if size(ee,2)>1 wolffd@0: if size(ee,1)>1 wolffd@0: error('ERROR IN MIRDIST: If the input is decomposed into frames, they should first be clustered.'); wolffd@0: else wolffd@0: ee = ee'; wolffd@0: end wolffd@0: end wolffd@0: if isempty(ee) wolffd@0: if isempty(dd) wolffd@0: dt{h}{1} = 0; wolffd@0: else wolffd@0: dt{h}{1} = Inf; wolffd@0: end wolffd@0: else wolffd@0: if length(dd)