Mercurial > hg > cip2012
comparison matlab/drumplots.m @ 20:6464cf684717
Added drum analysis functions and archive of plots
author | samer |
---|---|
date | Mon, 12 Mar 2012 15:51:05 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
19:14708527e1a2 | 20:6464cf684717 |
---|---|
1 % drumplots - return functions to do plots for one array of drum tracking data | |
2 % Execute each function in its own figure to see the results. | |
3 function PX=drumplots(BDT,varargin) | |
4 | |
5 % columns: time, type:{1,2}, error, beat pos, prob, KL, post entro, prior entro, beat period | |
6 opts=prefs('bar',4,'with_metre',0,'marker_size',2,varargin{:}); | |
7 K=find(BDT(:,2)==1); % kick | |
8 S=find(BDT(:,2)==2); % snare | |
9 TM=mod(BDT(:,4)+0.5,opts.bar)-0.5; | |
10 Surp=max(0,-log(BDT(:,5))); | |
11 Info=BDT(:,6); | |
12 HPrior=BDT(:,8); | |
13 HPost=BDT(:,7); | |
14 plotargs={'MarkerSize',opts.marker_size}; | |
15 | |
16 PX={ @()scat_with_metre([HPrior,Surp], 'surprise/nats', 'prior entropy/nats'), ... | |
17 @()scat_with_metre([HPost,Surp],'posterior entropy/nats','surprise/nats'), ... | |
18 @()scat_with_metre([Surp,Info], 'surprise/nats','information gain/nats'), ... | |
19 @()scat_with_metre([Info,HPost],'information gain/nats','posterior entropy/nats'), ... | |
20 @()scat_with_metre([HPrior,Info],'prior entropy/nats','information gain/nats'), ... | |
21 @()scat_with_metre([HPrior,HPost],'posterior entropy/nats', 'prior entropy/nats'), ... | |
22 @()scat_by_type([TM,Info], {'metrical position','information gain/nats'}), ... | |
23 @()scat_by_type([TM,Surp], {'metrical position','surprise/nats'}), ... | |
24 @()scat_by_type([TM,noisy(BDT(:,2),0.02)], {'metrical position','drum type'}), ... | |
25 @metre_entropies, ... | |
26 @()metre_hist, ... | |
27 @()total_info_dist, ... | |
28 @()mean_info_dist, ... | |
29 @()scat3d_by_type([HPrior,HPost,Info],{'prior entro','posterior entro','info gain'}), ... | |
30 % @()scat_by_type([HPrior,HPost,Info], { 'prior entropy/nats', 'posterior entropy/nats', 'information gain/nats'}); | |
31 }; | |
32 | |
33 | |
34 function y=noisy(x,k), y=x+k*randn(size(x)); end | |
35 | |
36 function h=metre_hist | |
37 DTime=round(8*TM); | |
38 T1=min(DTime); | |
39 T2=max(DTime); | |
40 ID=accumhist(DTime-T1+1,1,T2-T1+1); | |
41 colormap jet; | |
42 bar((T1:T2)/8,ID); | |
43 xlabel('metrical position'); | |
44 title('total event count'); | |
45 h=gca; | |
46 end | |
47 | |
48 function h=total_info_dist | |
49 DTime=round(8*TM); | |
50 T1=min(DTime); | |
51 T2=max(DTime); | |
52 ID=accumhist(DTime-T1+1,Info,T2-T1+1); | |
53 colormap jet; | |
54 bar((T1:T2)/8,ID); | |
55 xlabel('metrical position'); | |
56 title('total information gain'); | |
57 h=gca; | |
58 end | |
59 | |
60 function h=mean_info_dist | |
61 DTime=round(8*TM); | |
62 T1=min(DTime); | |
63 T2=max(DTime); | |
64 ID=accumhist(DTime-T1+1,Info,T2-T1+1); | |
65 CC=accumhist(DTime-T1+1,1,T2-T1+1); | |
66 colormap jet; | |
67 bar((T1:T2)/8,ID./CC); | |
68 xlabel('metrical position'); | |
69 title('mean information per event'); | |
70 h=gca; | |
71 end | |
72 function h=metre_entropies | |
73 newplot; hold on; | |
74 scat1([TM,BDT(:,8)],'b+'); | |
75 scat1([TM,BDT(:,7)],'ro'); | |
76 hold off; | |
77 legend({'prior entropy','posterior entropy'}); | |
78 xlabel('metrical position'); | |
79 ylabel('entropy/nats'); | |
80 rotate3d off; | |
81 h=gca; | |
82 end | |
83 | |
84 function h=scat_with_metre(X,lab1,lab2) | |
85 if opts.with_metre | |
86 h=scat_by_type([X,TM],{lab1,lab2,'metrical position'}); | |
87 camproj('orthographic'); | |
88 else | |
89 h=scat_by_type(X,{lab1,lab2}); | |
90 end | |
91 end | |
92 | |
93 function h=scat3d_by_type(X,labels) | |
94 h=scat_by_type(X,labels); | |
95 camproj('perspective'); | |
96 axis vis3d; | |
97 end | |
98 | |
99 function h=scat_by_type(X,labels) | |
100 newplot; hold on; | |
101 scat1(X(K,:),'ro'); | |
102 scat1(X(S,:),'b+'); | |
103 hold off; | |
104 legend({'kick','snare'}); | |
105 axislabels(labels); | |
106 if length(labels)>2, rotate3d on; | |
107 else rotate3d off; | |
108 end | |
109 h=gca; | |
110 end | |
111 | |
112 function scat1(X,marker) | |
113 if size(X,2)<=2 | |
114 plot(X(:,1),X(:,2),marker,plotargs{:}); | |
115 else | |
116 plot3(X(:,1),X(:,2),X(:,3),marker,plotargs{:}); | |
117 end | |
118 box on; | |
119 end | |
120 end | |
121 |