annotate toolboxes/MIRtoolbox1.3.2/MIRToolbox/mireventdensity.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 = mireventdensity(x,varargin)
wolffd@0 2 % e = mireventdensity(x) estimate the mean frequency of events (i.e., how
wolffd@0 3 % many note onsets per second) in the temporal data x.
wolffd@0 4
wolffd@0 5 % Optional arguments: Option1, Option2
wolffd@0 6 % Tuomas Eerola, 14.08.2008
wolffd@0 7 %
wolffd@0 8 normal.type = 'String';
wolffd@0 9 normal.choice = {'Option1','Option2'};
wolffd@0 10 normal.default = 'Option1';
wolffd@0 11 option.normal = normal;
wolffd@0 12
wolffd@0 13 frame.key = 'Frame';
wolffd@0 14 frame.type = 'Integer';
wolffd@0 15 frame.number = 2;
wolffd@0 16 frame.default = [0 0];
wolffd@0 17 frame.keydefault = [10 1];
wolffd@0 18 option.frame = frame;
wolffd@0 19
wolffd@0 20 specif.option = option;
wolffd@0 21
wolffd@0 22 specif.defaultframelength = 1.00;
wolffd@0 23 specif.defaultframehop = 0.5;
wolffd@0 24
wolffd@0 25 %specif.eachchunk = 'Normal';
wolffd@0 26 specif.combinechunk = {'Average','Concat'};
wolffd@0 27
wolffd@0 28 varargout = mirfunction(@mireventdensity,x,varargin,nargout,specif,@init,@main);
wolffd@0 29
wolffd@0 30
wolffd@0 31 function [x type] = init(x,option)
wolffd@0 32 if not(isamir(x,'mirenvelope'))
wolffd@0 33 if option.frame.length.val
wolffd@0 34 x = mironsets(x,'Klapuri99', 'Frame',option.frame.length.val,...
wolffd@0 35 option.frame.length.unit,...
wolffd@0 36 option.frame.hop.val,...
wolffd@0 37 option.frame.hop.unit);
wolffd@0 38 else
wolffd@0 39 x = mironsets(x,'Klapuri99');
wolffd@0 40 end
wolffd@0 41 end
wolffd@0 42 type = 'mirscalar';
wolffd@0 43
wolffd@0 44
wolffd@0 45 function e = main(o,option,postoption)
wolffd@0 46 if iscell(o)
wolffd@0 47 o = o{1};
wolffd@0 48 end
wolffd@0 49 sr = get(o,'Sampling');
wolffd@0 50 p = mirpeaks(o); %%%%<<<<<<< MORE OPTIONS HERE
wolffd@0 51 pv = get(p,'PeakVal');
wolffd@0 52 v = mircompute(@algo,pv,o,option,sr);
wolffd@0 53 e = mirscalar(o,'Data',v,'Title','Event density','Unit','per second');
wolffd@0 54 e = {e o};
wolffd@0 55
wolffd@0 56
wolffd@0 57 function e = algo(pv,o,option,sr)
wolffd@0 58 nc = size(o,2);
wolffd@0 59 nch = size(o,3);
wolffd@0 60 e = zeros(1,nc,nch);
wolffd@0 61 % for i = 1:nch
wolffd@0 62 % for j = 1:nc
wolffd@0 63 % if option.root
wolffd@0 64 % e(1,j,i) = norm(d(:,j,i));
wolffd@0 65 % else
wolffd@0 66 % disp('do the calc...')
wolffd@0 67 % % e(1,j,i) = d(:,j,i)'*d(:,j,i);
wolffd@0 68 % %tmp = mironsets(d,'Filterbank',10,'Contrast',0.1); % Change by TE, was only FB=20, no other params
wolffd@0 69 % e2 = mirpeaks(e)
wolffd@0 70 % [o1,o2] = mirgetdata(e);
wolffd@0 71 % e(1,j,i) = length(o2)/mirgetdata(mirlength(d));
wolffd@0 72 % end
wolffd@0 73 % end
wolffd@0 74 % end
wolffd@0 75 for i = 1:nch
wolffd@0 76 for j = 1:nc
wolffd@0 77 e(1,j,i) = length(pv{1,j,i});
wolffd@0 78 if strcmpi(option.normal,'Option1')
wolffd@0 79 e(1,j,i) = e(1,j,i) *sr/size(o,1);
wolffd@0 80 elseif strcmpi(option.normal,'Option2')
wolffd@0 81 pvs = pv{1};
wolffd@0 82 high_pvs = length(find(mean(pvs)>pvs));
wolffd@0 83 e(1,j,i) = high_pvs(1,j,i) *sr/size(o,1); % only those which are larger than mean
wolffd@0 84 end
wolffd@0 85 end
wolffd@0 86 end
wolffd@0 87
wolffd@0 88
wolffd@0 89
wolffd@0 90 %function [y orig] = eachchunk(orig,option,missing,postchunk)
wolffd@0 91 %y = mireventdensity(orig,option);
wolffd@0 92
wolffd@0 93
wolffd@0 94 %function y = combinechunk(old,new)
wolffd@0 95 %do = mirgetdata(old);
wolffd@0 96 %dn = mirgetdata(new);
wolffd@0 97 %y = set(old,'ChunkData',do+dn);