annotate matlab/drumplots.m @ 75:8a146c651475 tip

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