wolffd@0: function varargout = mirattackslope(orig,varargin) wolffd@0: % a = mirattackslope(x) estimates the average slope of each note attack. wolffd@0: % Optional arguments: wolffd@0: % a = mirattackslope(x,m) specifies a method for slope computation. wolffd@0: % Possible values: wolffd@0: % m = 'Diff': ratio between the magnitude difference at the wolffd@0: % beginning and the ending of the attack period, and the wolffd@0: % corresponding time difference. wolffd@0: % m = 'Gauss': average of the slope, weighted by a gaussian wolffd@0: % curve that emphasizes values at the middle of the attack wolffd@0: % period. (similar to Peeters 2004). wolffd@0: % mirattackslope(...,'Contrast',c) specifies the 'Contrast' parameter wolffd@0: % used in mironsets for event detection through peak picking. wolffd@0: % Same default value as in mironsets. wolffd@0: % wolffd@0: % Peeters. G. (2004). A large set of audio features for sound description wolffd@0: % (similarity and classification) in the CUIDADO project. version 1.0 wolffd@0: wolffd@0: meth.type = 'String'; wolffd@0: meth.choice = {'Diff','Gauss'}; wolffd@0: meth.default = 'Diff'; wolffd@0: option.meth = meth; wolffd@0: wolffd@0: cthr.key = 'Contrast'; wolffd@0: cthr.type = 'Integer'; wolffd@0: cthr.default = NaN; wolffd@0: option.cthr = cthr; wolffd@0: wolffd@0: specif.option = option; wolffd@0: wolffd@0: varargout = mirfunction(@mirattackslope,orig,varargin,nargout,specif,@init,@main); wolffd@0: wolffd@0: wolffd@0: function [o type] = init(x,option) wolffd@0: o = mironsets(x,'Attack','Contrast',option.cthr); wolffd@0: type = mirtype(x); wolffd@0: wolffd@0: wolffd@0: function sl = main(o,option,postoption) wolffd@0: if iscell(o) wolffd@0: o = o{1}; wolffd@0: end wolffd@0: po = get(o,'PeakPos'); wolffd@0: pa = get(o,'AttackPos'); wolffd@0: pou = get(o,'PeakPosUnit'); wolffd@0: pau = get(o,'AttackPosUnit'); wolffd@0: sr = get(o,'Sampling'); wolffd@0: d = get(o,'Data'); wolffd@0: sl = mircompute(@algo,po,pa,pou,pau,d,option.meth,sr); wolffd@0: fp = mircompute(@frampose,pau,pou); wolffd@0: sl = mirscalar(o,'Data',sl,'FramePos',fp,'Title','Attack Slope'); wolffd@0: sl = {sl,o}; wolffd@0: wolffd@0: wolffd@0: function fp = frampose(pa,po) wolffd@0: pa = sort(pa{1}); wolffd@0: po = sort(po{1}); wolffd@0: fp = [pa';po']; wolffd@0: wolffd@0: wolffd@0: function sl = algo(po,pa,pou,pau,d,meth,sr) wolffd@0: pa = sort(pa{1}); wolffd@0: po = sort(po{1}); wolffd@0: pau = sort(pau{1}); wolffd@0: pou = sort(pou{1}); wolffd@0: sl = zeros(1,length(pa)); wolffd@0: for i = 1:length(pa) wolffd@0: switch meth wolffd@0: case 'Diff' wolffd@0: sl(i) = (d(po(i))-d(pa(i)))/(pou(i)-pau(i)); wolffd@0: case 'Gauss' wolffd@0: l = po(i)-pa(i); wolffd@0: h = ceil(l/2); wolffd@0: gauss = exp(-(1-h:l-h).^2/(l/4)^2); wolffd@0: dat = diff(d(pa(i):po(i))).*gauss'; wolffd@0: sl(i) = mean(dat)*sr; wolffd@0: end wolffd@0: end