annotate toolboxes/MIRtoolbox1.3.2/MIRToolbox/@mirtonalcentroid/mirtonalcentroid.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 = mirtonalcentroid(orig,varargin)
Daniel@0 2 % c = mirtonalcentroid(x) calculates the 6-dimensional tonal centroid
Daniel@0 3 % vector from the chromagram.
Daniel@0 4 % It corresponds to a projection of the chords along circles of fifths,
Daniel@0 5 % of minor thirds, and of major thirds.
Daniel@0 6 % [c ch] = mirtonalcentroid(x) also returns the intermediate chromagram.
Daniel@0 7 %
Daniel@0 8 % C. A. Harte and M. B. Sandler, Detecting harmonic change in musical
Daniel@0 9 % audio, in Proceedings of Audio and Music Computing for Multimedia
Daniel@0 10 % Workshop, Santa Barbara, CA, 2006.
Daniel@0 11
Daniel@0 12 frame.key = 'Frame';
Daniel@0 13 frame.type = 'Integer';
Daniel@0 14 frame.number = 2;
Daniel@0 15 frame.default = [0 0];
Daniel@0 16 frame.keydefault = [.743 .1];
Daniel@0 17 option.frame = frame;
Daniel@0 18
Daniel@0 19 specif.option = option;
Daniel@0 20
Daniel@0 21 varargout = mirfunction(@mirtonalcentroid,orig,varargin,nargout,specif,@init,@main);
Daniel@0 22
Daniel@0 23
Daniel@0 24 function [c type] = init(orig,option)
Daniel@0 25 if option.frame.length.val
Daniel@0 26 c = mirchromagram(orig,'Frame',option.frame.length.val,...
Daniel@0 27 option.frame.length.unit,...
Daniel@0 28 option.frame.hop.val,...
Daniel@0 29 option.frame.hop.unit);
Daniel@0 30 else
Daniel@0 31 c = mirchromagram(orig);
Daniel@0 32 end
Daniel@0 33 type = 'mirtonalcentroid';
Daniel@0 34
Daniel@0 35
Daniel@0 36 function tc = main(ch,option,postoption)
Daniel@0 37 if iscell(ch)
Daniel@0 38 ch = ch{1};
Daniel@0 39 end
Daniel@0 40 if isa(ch,'mirtonalcentroid')
Daniel@0 41 tc = orig;
Daniel@0 42 ch = [];
Daniel@0 43 else
Daniel@0 44 x1 = sin(pi*7*(0:11)/6)';
Daniel@0 45 y1 = cos(pi*7*(0:11)/6)';
Daniel@0 46 % minor thirds circle
Daniel@0 47 x2 = sin(pi*3*(0:11)/2)';
Daniel@0 48 y2 = cos(pi*3*(0:11)/2)';
Daniel@0 49 % major thirds circle
Daniel@0 50 x3 = 0.5 * sin(pi*2*(0:11)/3)';
Daniel@0 51 y3 = 0.5 * cos(pi*2*(0:11)/3)';
Daniel@0 52 c = [x1 y1 x2 y2 x3 y3];
Daniel@0 53 c = c';
Daniel@0 54 tc = class(struct,'mirtonalcentroid',mirdata(ch));
Daniel@0 55 tc = purgedata(tc);
Daniel@0 56 tc = set(tc,'Title','Tonal centroid','Abs','dimensions','Ord','position');
Daniel@0 57 m = get(ch,'Magnitude');
Daniel@0 58 %disp('Computing tonal centroid...')
Daniel@0 59 n = cell(1,length(m)); % The final structured list of magnitudes.
Daniel@0 60 d = cell(1,length(m)); % The final structured list of centroid dimensions.
Daniel@0 61 for i = 1:length(m)
Daniel@0 62 mi = m{i};
Daniel@0 63 if not(iscell(mi))
Daniel@0 64 mi = {mi};
Daniel@0 65 end
Daniel@0 66 ni = cell(1,length(mi)); % The list of magnitudes.
Daniel@0 67 di = cell(1,length(mi)); % The list of centroid dimensions.
Daniel@0 68 for j = 1:length(mi)
Daniel@0 69 mj = mi{j};
Daniel@0 70 ni{j} = zeros(6,size(mj,2),size(mi,3));
Daniel@0 71 for k = 1:size(mj,3)
Daniel@0 72 ni{j}(:,:,k) = c * mj(:,:,k);
Daniel@0 73 end
Daniel@0 74 di{j} = repmat((1:6)',[1,size(mj,2),size(mi,3)]);
Daniel@0 75 end
Daniel@0 76 n{i} = ni;
Daniel@0 77 d{i} = di;
Daniel@0 78 end
Daniel@0 79 tc = set(tc,'Positions',n,'Dimensions',d);
Daniel@0 80 end
Daniel@0 81 tc = {tc,ch};