annotate toolboxes/MIRtoolbox1.3.2/MIRToolbox/mirkey.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 = mirkey(orig,varargin)
wolffd@0 2 % k = mirkey(x) estimates the key.
wolffd@0 3 % Optional argument:
wolffd@0 4 % mirkey(...,'Total',m) selects not only the most probable key, but
wolffd@0 5 % the m most probable keys.
wolffd@0 6 % The other parameter 'Contrast' related to mirpeaks can be specified
wolffd@0 7 % here (see help mirchromagram).
wolffd@0 8 % The optional parameters 'Weight' and 'Triangle' related to
wolffd@0 9 % mirchromagram can be specified here (see help mirchromagram).
wolffd@0 10 % [k,ks] = mirkey(...) also returns the key clarity, corresponding here
wolffd@0 11 % to the key strength associated to the best candidate.
wolffd@0 12 % [k,ks,ksc] = mirkey(...) also displays the key strength curve used for
wolffd@0 13 % the key estimation and shows in particular the peaks corresponding
wolffd@0 14 % to the selected key(s).
wolffd@0 15
wolffd@0 16 tot.key = 'Total';
wolffd@0 17 tot.type = 'Integer';
wolffd@0 18 tot.default = 1;
wolffd@0 19 option.tot = tot;
wolffd@0 20
wolffd@0 21 thr.key = 'Contrast';
wolffd@0 22 thr.type = 'Integer';
wolffd@0 23 thr.default = .1;
wolffd@0 24 option.thr = thr;
wolffd@0 25
wolffd@0 26 wth.key = 'Weight';
wolffd@0 27 wth.type = 'Integer';
wolffd@0 28 wth.default = .5;
wolffd@0 29 option.wth = wth;
wolffd@0 30
wolffd@0 31 tri.key = 'Triangle';
wolffd@0 32 tri.type = 'Boolean';
wolffd@0 33 tri.default = 0;
wolffd@0 34 option.tri = tri;
wolffd@0 35
wolffd@0 36 specif.option = option;
wolffd@0 37 specif.defaultframelength = 1;
wolffd@0 38 specif.defaultframehop = .5;
wolffd@0 39
wolffd@0 40 varargout = mirfunction(@mirkey,orig,varargin,nargout,specif,@init,@main);
wolffd@0 41
wolffd@0 42
wolffd@0 43 function [p type] = init(x,option)
wolffd@0 44 if not(isamir(x,'mirkeystrength'))
wolffd@0 45 x = mirkeystrength(x,'Weight',option.wth,'Triangle',option.tri);
wolffd@0 46 end
wolffd@0 47 p = mirpeaks(x,'Total',option.tot,'Contrast',option.thr);
wolffd@0 48 type = {'mirscalar','mirscalar','mirkeystrength'};
wolffd@0 49
wolffd@0 50
wolffd@0 51 function k = main(p,option,postoption)
wolffd@0 52 if iscell(p)
wolffd@0 53 p = p{1};
wolffd@0 54 end
wolffd@0 55 pc = get(p,'PeakPos');
wolffd@0 56 pv = get(p,'PeakMaxVal');
wolffd@0 57 pm = get(p,'PeakMode');
wolffd@0 58 k = mirscalar(p,'Data',pc,'Mode',pm,'Title','Key',...
wolffd@0 59 'Legend',{'C','C#','D','D#','E','F','F#','G','G#','A','A#','B'});
wolffd@0 60 m = mirscalar(p,'Data',pv,'Title','Key clarity','MultiData',{});
wolffd@0 61 k = {k m p};