annotate toolboxes/MIRtoolbox1.3.2/MIRToolbox/mirattackslope.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 = mirattackslope(orig,varargin)
wolffd@0 2 % a = mirattackslope(x) estimates the average slope of each note attack.
wolffd@0 3 % Optional arguments:
wolffd@0 4 % a = mirattackslope(x,m) specifies a method for slope computation.
wolffd@0 5 % Possible values:
wolffd@0 6 % m = 'Diff': ratio between the magnitude difference at the
wolffd@0 7 % beginning and the ending of the attack period, and the
wolffd@0 8 % corresponding time difference.
wolffd@0 9 % m = 'Gauss': average of the slope, weighted by a gaussian
wolffd@0 10 % curve that emphasizes values at the middle of the attack
wolffd@0 11 % period. (similar to Peeters 2004).
wolffd@0 12 % mirattackslope(...,'Contrast',c) specifies the 'Contrast' parameter
wolffd@0 13 % used in mironsets for event detection through peak picking.
wolffd@0 14 % Same default value as in mironsets.
wolffd@0 15 %
wolffd@0 16 % Peeters. G. (2004). A large set of audio features for sound description
wolffd@0 17 % (similarity and classification) in the CUIDADO project. version 1.0
wolffd@0 18
wolffd@0 19 meth.type = 'String';
wolffd@0 20 meth.choice = {'Diff','Gauss'};
wolffd@0 21 meth.default = 'Diff';
wolffd@0 22 option.meth = meth;
wolffd@0 23
wolffd@0 24 cthr.key = 'Contrast';
wolffd@0 25 cthr.type = 'Integer';
wolffd@0 26 cthr.default = NaN;
wolffd@0 27 option.cthr = cthr;
wolffd@0 28
wolffd@0 29 specif.option = option;
wolffd@0 30
wolffd@0 31 varargout = mirfunction(@mirattackslope,orig,varargin,nargout,specif,@init,@main);
wolffd@0 32
wolffd@0 33
wolffd@0 34 function [o type] = init(x,option)
wolffd@0 35 o = mironsets(x,'Attack','Contrast',option.cthr);
wolffd@0 36 type = mirtype(x);
wolffd@0 37
wolffd@0 38
wolffd@0 39 function sl = main(o,option,postoption)
wolffd@0 40 if iscell(o)
wolffd@0 41 o = o{1};
wolffd@0 42 end
wolffd@0 43 po = get(o,'PeakPos');
wolffd@0 44 pa = get(o,'AttackPos');
wolffd@0 45 pou = get(o,'PeakPosUnit');
wolffd@0 46 pau = get(o,'AttackPosUnit');
wolffd@0 47 sr = get(o,'Sampling');
wolffd@0 48 d = get(o,'Data');
wolffd@0 49 sl = mircompute(@algo,po,pa,pou,pau,d,option.meth,sr);
wolffd@0 50 fp = mircompute(@frampose,pau,pou);
wolffd@0 51 sl = mirscalar(o,'Data',sl,'FramePos',fp,'Title','Attack Slope');
wolffd@0 52 sl = {sl,o};
wolffd@0 53
wolffd@0 54
wolffd@0 55 function fp = frampose(pa,po)
wolffd@0 56 pa = sort(pa{1});
wolffd@0 57 po = sort(po{1});
wolffd@0 58 fp = [pa';po'];
wolffd@0 59
wolffd@0 60
wolffd@0 61 function sl = algo(po,pa,pou,pau,d,meth,sr)
wolffd@0 62 pa = sort(pa{1});
wolffd@0 63 po = sort(po{1});
wolffd@0 64 pau = sort(pau{1});
wolffd@0 65 pou = sort(pou{1});
wolffd@0 66 sl = zeros(1,length(pa));
wolffd@0 67 for i = 1:length(pa)
wolffd@0 68 switch meth
wolffd@0 69 case 'Diff'
wolffd@0 70 sl(i) = (d(po(i))-d(pa(i)))/(pou(i)-pau(i));
wolffd@0 71 case 'Gauss'
wolffd@0 72 l = po(i)-pa(i);
wolffd@0 73 h = ceil(l/2);
wolffd@0 74 gauss = exp(-(1-h:l-h).^2/(l/4)^2);
wolffd@0 75 dat = diff(d(pa(i):po(i))).*gauss';
wolffd@0 76 sl(i) = mean(dat)*sr;
wolffd@0 77 end
wolffd@0 78 end