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