Daniel@0: function varargout = mireventdensity(x,varargin) Daniel@0: % e = mireventdensity(x) estimate the mean frequency of events (i.e., how Daniel@0: % many note onsets per second) in the temporal data x. Daniel@0: Daniel@0: % Optional arguments: Option1, Option2 Daniel@0: % Tuomas Eerola, 14.08.2008 Daniel@0: % Daniel@0: normal.type = 'String'; Daniel@0: normal.choice = {'Option1','Option2'}; Daniel@0: normal.default = 'Option1'; Daniel@0: option.normal = normal; Daniel@0: Daniel@0: frame.key = 'Frame'; Daniel@0: frame.type = 'Integer'; Daniel@0: frame.number = 2; Daniel@0: frame.default = [0 0]; Daniel@0: frame.keydefault = [10 1]; Daniel@0: option.frame = frame; Daniel@0: Daniel@0: specif.option = option; Daniel@0: Daniel@0: specif.defaultframelength = 1.00; Daniel@0: specif.defaultframehop = 0.5; Daniel@0: Daniel@0: %specif.eachchunk = 'Normal'; Daniel@0: specif.combinechunk = {'Average','Concat'}; Daniel@0: Daniel@0: varargout = mirfunction(@mireventdensity,x,varargin,nargout,specif,@init,@main); Daniel@0: Daniel@0: Daniel@0: function [x type] = init(x,option) Daniel@0: if not(isamir(x,'mirenvelope')) Daniel@0: if option.frame.length.val Daniel@0: x = mironsets(x,'Klapuri99', 'Frame',option.frame.length.val,... Daniel@0: option.frame.length.unit,... Daniel@0: option.frame.hop.val,... Daniel@0: option.frame.hop.unit); Daniel@0: else Daniel@0: x = mironsets(x,'Klapuri99'); Daniel@0: end Daniel@0: end Daniel@0: type = 'mirscalar'; Daniel@0: Daniel@0: Daniel@0: function e = main(o,option,postoption) Daniel@0: if iscell(o) Daniel@0: o = o{1}; Daniel@0: end Daniel@0: sr = get(o,'Sampling'); Daniel@0: p = mirpeaks(o); %%%%<<<<<<< MORE OPTIONS HERE Daniel@0: pv = get(p,'PeakVal'); Daniel@0: v = mircompute(@algo,pv,o,option,sr); Daniel@0: e = mirscalar(o,'Data',v,'Title','Event density','Unit','per second'); Daniel@0: e = {e o}; Daniel@0: Daniel@0: Daniel@0: function e = algo(pv,o,option,sr) Daniel@0: nc = size(o,2); Daniel@0: nch = size(o,3); Daniel@0: e = zeros(1,nc,nch); Daniel@0: % for i = 1:nch Daniel@0: % for j = 1:nc Daniel@0: % if option.root Daniel@0: % e(1,j,i) = norm(d(:,j,i)); Daniel@0: % else Daniel@0: % disp('do the calc...') Daniel@0: % % e(1,j,i) = d(:,j,i)'*d(:,j,i); Daniel@0: % %tmp = mironsets(d,'Filterbank',10,'Contrast',0.1); % Change by TE, was only FB=20, no other params Daniel@0: % e2 = mirpeaks(e) Daniel@0: % [o1,o2] = mirgetdata(e); Daniel@0: % e(1,j,i) = length(o2)/mirgetdata(mirlength(d)); Daniel@0: % end Daniel@0: % end Daniel@0: % end Daniel@0: for i = 1:nch Daniel@0: for j = 1:nc Daniel@0: e(1,j,i) = length(pv{1,j,i}); Daniel@0: if strcmpi(option.normal,'Option1') Daniel@0: e(1,j,i) = e(1,j,i) *sr/size(o,1); Daniel@0: elseif strcmpi(option.normal,'Option2') Daniel@0: pvs = pv{1}; Daniel@0: high_pvs = length(find(mean(pvs)>pvs)); Daniel@0: e(1,j,i) = high_pvs(1,j,i) *sr/size(o,1); % only those which are larger than mean Daniel@0: end Daniel@0: end Daniel@0: end Daniel@0: Daniel@0: Daniel@0: Daniel@0: %function [y orig] = eachchunk(orig,option,missing,postchunk) Daniel@0: %y = mireventdensity(orig,option); Daniel@0: Daniel@0: Daniel@0: %function y = combinechunk(old,new) Daniel@0: %do = mirgetdata(old); Daniel@0: %dn = mirgetdata(new); Daniel@0: %y = set(old,'ChunkData',do+dn);