annotate toolboxes/MIRtoolbox1.3.2/MIRToolbox/mirbeatspectrum.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function varargout = mirbeatspectrum(orig,varargin)
wolffd@0 2 % n = mirbeatspectrum(m) evaluates the beat spectrum.
wolffd@0 3 % [n,m] = mirbeatspectrum(m) also return the similarity matrix on which
wolffd@0 4 % the estimation is made.
wolffd@0 5 % Optional argument:
wolffd@0 6 % mirbeatspectrum(...,s) specifies the estimation method.
wolffd@0 7 % Possible values:
wolffd@0 8 % s = 'Diag', summing simply along the diagonals of the matrix.
wolffd@0 9 % s = 'Autocor', based on the autocorrelation of the matrix.
wolffd@0 10 % mirbeatspectrum(...,'Distance',f) specifies the name of a dissimilarity
wolffd@0 11 % distance function, from those proposed in the Statistics Toolbox
wolffd@0 12 % (help pdist).
wolffd@0 13 % default value: f = 'cosine'
wolffd@0 14 % J. Foote, M. Cooper, U. Nam, "Audio Retrieval by Rhythmic Similarity",
wolffd@0 15 % ISMIR 2002.
wolffd@0 16
wolffd@0 17
wolffd@0 18 dist.key = 'Distance';
wolffd@0 19 dist.type = 'String';
wolffd@0 20 dist.default = 'cosine';
wolffd@0 21 option.dist = dist;
wolffd@0 22
wolffd@0 23 meth.type = 'String';
wolffd@0 24 meth.choice = {'Diag','Autocor'};
wolffd@0 25 meth.default = 'Autocor';
wolffd@0 26 option.meth = meth;
wolffd@0 27
wolffd@0 28 specif.option = option;
wolffd@0 29 varargout = mirfunction(@mirbeatspectrum,orig,varargin,nargout,specif,@init,@main);
wolffd@0 30
wolffd@0 31
wolffd@0 32 function [x type] = init(x,option)
wolffd@0 33 if not(isamir(x,'mirscalar'))
wolffd@0 34 if isamir(x,'miraudio')
wolffd@0 35 x = mirmfcc(x,'frame',.025,'s',.01,'s','Rank',8:30);
wolffd@0 36 end
wolffd@0 37 x = mirsimatrix(x,'Distance',option.dist,'Similarity');
wolffd@0 38 end
wolffd@0 39 type = 'mirscalar';
wolffd@0 40
wolffd@0 41
wolffd@0 42 function y = main(orig,option,postoption)
wolffd@0 43 if iscell(orig)
wolffd@0 44 orig = orig{1};
wolffd@0 45 end
wolffd@0 46 fp = get(orig,'FramePos');
wolffd@0 47 if not(isa(orig,'mirscalar'))
wolffd@0 48 s = get(orig,'Data');
wolffd@0 49 total = cell(1,length(s));
wolffd@0 50 for k = 1:length(s)
wolffd@0 51 for h = 1:length(s{k})
wolffd@0 52 maxfp = find(fp{k}{h}(2,:)>4,1);
wolffd@0 53 if isempty(maxfp)
wolffd@0 54 maxfp = Inf;
wolffd@0 55 else
wolffd@0 56 fp{k}{h}(:,maxfp+1:end) = [];
wolffd@0 57 end
wolffd@0 58 l = min(length(s{k}{h}),maxfp);
wolffd@0 59 total{k}{h} = zeros(1,l);
wolffd@0 60 if strcmpi(option.meth,'Diag')
wolffd@0 61 for i = 1:l
wolffd@0 62 total{k}{h}(i) = mean(diag(s{k}{h},i-1));
wolffd@0 63 end
wolffd@0 64 else
wolffd@0 65 for i = 1:l
wolffd@0 66 total{k}{h}(i) = mean(mean(s{k}{h}(:,1:l-i+1).*s{k}{h}(:,i:l)));
wolffd@0 67 end
wolffd@0 68 end
wolffd@0 69 end
wolffd@0 70 end
wolffd@0 71 else
wolffd@0 72 total = get(orig,'Data');
wolffd@0 73 end
wolffd@0 74 n = mirscalar(orig,'Data',total,'FramePos',fp,'Title','Beat Spectrum');
wolffd@0 75 y = {n orig};