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