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