annotate toolboxes/MIRtoolbox1.3.2/MIRToolbox/@mirkeystrength/mirkeystrength.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 = mirkeystrength(orig,varargin)
Daniel@0 2 % ks = mirkeystrength(x) computes the key strength, i.e., the probability
Daniel@0 3 % associated with each possible key candidate.
Daniel@0 4 % Optional parameters:
Daniel@0 5 % mirkeystrength(...,'Frame',l,h) orders a frame decomposition of window
Daniel@0 6 % length l (in seconds) and hop factor h, expressed relatively to
Daniel@0 7 % the window length. For instance h = 1 indicates no overlap.
Daniel@0 8 % Default values: l = 1 seconds and h = .5
Daniel@0 9 % The mirchromagram options 'Weight' and 'Triangle' can be specified.
Daniel@0 10 % [ks,c] = mirkeystrength(...) also displays the chromagram used for the key
Daniel@0 11 % strength estimation.
Daniel@0 12 %
Daniel@0 13 % Krumhansl, Cognitive foundations of musical pitch. Oxford UP, 1990.
Daniel@0 14 % Gomez, Tonal description of polyphonic audio for music content processing,
Daniel@0 15 % INFORMS Journal on Computing, 18-3, pp. 294-304, 2006.
Daniel@0 16
Daniel@0 17 wth.key = 'Weight';
Daniel@0 18 wth.type = 'Integer';
Daniel@0 19 wth.default = .5;
Daniel@0 20 option.wth = wth;
Daniel@0 21
Daniel@0 22 tri.key = 'Triangle';
Daniel@0 23 tri.type = 'Boolean';
Daniel@0 24 tri.default = 0;
Daniel@0 25 option.tri = tri;
Daniel@0 26
Daniel@0 27 specif.option = option;
Daniel@0 28 specif.defaultframelength = .1;
Daniel@0 29 specif.defaultframehop = .125;
Daniel@0 30
Daniel@0 31 varargout = mirfunction(@mirkeystrength,orig,varargin,nargout,specif,@init,@main);
Daniel@0 32
Daniel@0 33
Daniel@0 34 function [x type] = init(x,option)
Daniel@0 35 if not(isamir(x,'mirchromagram'))
Daniel@0 36 x = mirchromagram(x,'Weight',option.wth,'Triangle',option.tri,'Normal');
Daniel@0 37 else
Daniel@0 38 x = mirchromagram(x,'Wrap','Normal');
Daniel@0 39 end
Daniel@0 40 type = 'mirkeystrength';
Daniel@0 41
Daniel@0 42
Daniel@0 43 function k = main(orig,option,postoption)
Daniel@0 44 if iscell(orig)
Daniel@0 45 orig = orig{1};
Daniel@0 46 end
Daniel@0 47 if isa(orig,'mirkeystrength')
Daniel@0 48 c = [];
Daniel@0 49 k = orig;
Daniel@0 50 else
Daniel@0 51 c = orig;
Daniel@0 52 load gomezprofs;
Daniel@0 53 m = get(c,'Magnitude');
Daniel@0 54 st = cell(1,length(m));
Daniel@0 55 kk = cell(1,length(m));
Daniel@0 56 %disp('Computing key strengths...')
Daniel@0 57 for i = 1:length(m)
Daniel@0 58 mi = m{i};
Daniel@0 59 if not(iscell(mi))
Daniel@0 60 mi = {mi};
Daniel@0 61 end
Daniel@0 62 si = cell(1,length(mi));
Daniel@0 63 ki = cell(1,length(mi));
Daniel@0 64 for j = 1:length(mi)
Daniel@0 65 mj = mi{j};
Daniel@0 66 sj = zeros(12,size(mj,2),size(mj,3),2);
Daniel@0 67 for k = 1:size(mj,2)
Daniel@0 68 for l = 1:size(mj,3)
Daniel@0 69 tmp = corrcoef([mj(:,k,l) gomezprofs']);
Daniel@0 70 sj(:,k,l,1) = tmp(1,2:13);
Daniel@0 71 sj(:,k,l,2) = tmp(1,14:25);
Daniel@0 72 kj(:,k,l) = {'C','C#','D','D#','E','F','F#','G','G#','A','A#','B'};
Daniel@0 73 end
Daniel@0 74 end
Daniel@0 75 si{j} = sj;
Daniel@0 76 ki{j} = kj;
Daniel@0 77 end
Daniel@0 78 st{i} = si;
Daniel@0 79 kk{i} = ki;
Daniel@0 80 end
Daniel@0 81 k = class(struct,'mirkeystrength',mirdata(c));
Daniel@0 82 k = purgedata(k);
Daniel@0 83 k = set(k,'Title','Key strength','Abs','tonal center','Ord','strength',...
Daniel@0 84 'Tonic',kk,'Strength',st,'MultiData',{'maj','min'},'Interpolable',0);
Daniel@0 85 end
Daniel@0 86 k = {k c};