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