annotate toolboxes/MIRtoolbox1.3.2/MIRToolbox/mirattackslope.m @ 0:cc4b1211e677 tip

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