changeset 20:6464cf684717

Added drum analysis functions and archive of plots
author samer
date Mon, 12 Mar 2012 15:51:05 +0000
parents 14708527e1a2
children 739b2444a4ac
files drum_plots.tar.gz matlab/BData.mat matlab/aggplot.m matlab/drumfiles.m matlab/drumplot.m matlab/drumplots.m matlab/fileplay.m matlab/fileplot.m matlab/finite_shift.m matlab/indplots.m matlab/paperplot.m matlab/read_shift.m matlab/shift_beat.m
diffstat 13 files changed, 229 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
Binary file drum_plots.tar.gz has changed
Binary file matlab/BData.mat has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/matlab/aggplot.m	Mon Mar 12 15:51:05 2012 +0000
@@ -0,0 +1,9 @@
+% aggplot - Do plots for all data lumped together
+function aggplot(files,varargin)
+	plots=drumplots(cellcat(1,map(@read_shift,cellfilt(@finite_shift,files))),varargin{:});
+	zipwith(@(f,p)paperplot(f,p,'epsfile',sprintf('agg%d.eps',f),varargin{:}), ...
+		num2cell(40+(1:length(plots))), ...
+		plots);
+end
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/matlab/drumfiles.m	Mon Mar 12 15:51:05 2012 +0000
@@ -0,0 +1,25 @@
+function f=files
+f= {...
+	{'data/AdamBetts_Human.txt',2}, ...
+	{'data/AdamW_DownLine4_0.7like.txt',1}, ...
+	{'data/AdamW_DownLine5_0.7like.txt',0}, ...
+	{'data/AdamW_LewesTake12_0.7like.txt',1}, ...
+	{'data/AdamW_LewesTake13_lastCoupleOut_0.7like.txt',1}, ...
+	{'data/AdamW_LewesTake14_barOutEnd_0.7like.txt',1}, ...
+	{'data/AlFunk_0.7likelihood.txt',1}, ...
+	{'data/BadEvilEvenTest.txt',-1}, ...
+	{'data/Blitzkrieg_0.7like.txt',0}, ...
+	{'data/FutureHides_0.7like.txt',-2}, ...
+	{'data/HugoFollowLeaders_meatPotatoes_0.7like.txt',-1}, ...
+	{'data/HugoTest_MeatTwoVeg_0.7like.txt',0}, ...
+	{'data/JamesAlLast_0.7like.txt',NaN}, ...
+	{'data/JemDoultonFunky7_0.7like.txt',-1}, ...
+	{'data/MyTravelEvenKS_0.7likelihood.txt',0}, ...
+	{'data/RodWebbReggaeBeat_0.7like.txt',1}, ...
+	{'data/baydrumTest2.txt',0}, ...
+	{'data/cannibal&_goodTilLastCoupleBars.txt',0}, ...
+	{'data/david11_fixed120BPMTest.txt',0}, ...
+	{'data/david11_fixed120BPMTest0.txt',0}, ...
+	{'data/idiotsDanceTake2_0.7likelihoodTest.txt',1}, ...
+	{'data/myTravelEvenKickSnareTest2.txt',0}, ...
+};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/matlab/drumplot.m	Mon Mar 12 15:51:05 2012 +0000
@@ -0,0 +1,11 @@
+% drumplot - Do plots for given array of tracking data
+function drumplot(BDT,varargin)
+	opts=prefs('basename',[],varargin{:});
+	plots=drumplots(BDT,opts);
+	if isempty(opts.basename)
+		plotfn=@(f,p)paperplot(f,p,opts);
+	else
+		plotfn=@(f,p)paperplot(f,p,'epsfile',sprintf('%s-%d.eps',opts.basename,f),opts);
+	end
+	zipwith(plotfn,num2cell(40+(1:length(plots))),plots);
+end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/matlab/drumplots.m	Mon Mar 12 15:51:05 2012 +0000
@@ -0,0 +1,121 @@
+% drumplots - return functions to do plots for one array of drum tracking data
+% Execute each function in its own figure to see the results.
+function PX=drumplots(BDT,varargin)
+
+	% columns: time, type:{1,2}, error, beat pos, prob, KL, post entro, prior entro, beat period
+	opts=prefs('bar',4,'with_metre',0,'marker_size',2,varargin{:});
+	K=find(BDT(:,2)==1); % kick
+	S=find(BDT(:,2)==2); % snare
+	TM=mod(BDT(:,4)+0.5,opts.bar)-0.5;
+	Surp=max(0,-log(BDT(:,5)));
+	Info=BDT(:,6);
+	HPrior=BDT(:,8);
+	HPost=BDT(:,7);
+	plotargs={'MarkerSize',opts.marker_size};
+
+	PX={	@()scat_with_metre([HPrior,Surp], 'surprise/nats', 'prior entropy/nats'), ...
+			@()scat_with_metre([HPost,Surp],'posterior entropy/nats','surprise/nats'), ...
+			@()scat_with_metre([Surp,Info], 'surprise/nats','information gain/nats'), ...
+			@()scat_with_metre([Info,HPost],'information gain/nats','posterior entropy/nats'), ...
+			@()scat_with_metre([HPrior,Info],'prior entropy/nats','information gain/nats'), ...
+			@()scat_with_metre([HPrior,HPost],'posterior entropy/nats', 'prior entropy/nats'), ...
+			@()scat_by_type([TM,Info], {'metrical position','information gain/nats'}), ...
+			@()scat_by_type([TM,Surp], {'metrical position','surprise/nats'}), ...
+			@()scat_by_type([TM,noisy(BDT(:,2),0.02)], {'metrical position','drum type'}), ...
+			@metre_entropies, ...
+			@()metre_hist, ...
+			@()total_info_dist, ...
+			@()mean_info_dist, ...
+			@()scat3d_by_type([HPrior,HPost,Info],{'prior entro','posterior entro','info gain'}), ...
+	%	@()scat_by_type([HPrior,HPost,Info], { 'prior entropy/nats', 'posterior entropy/nats', 'information gain/nats'});
+		};
+
+
+	function y=noisy(x,k), y=x+k*randn(size(x)); end
+
+	function h=metre_hist
+		DTime=round(8*TM);
+		T1=min(DTime);
+		T2=max(DTime);
+		ID=accumhist(DTime-T1+1,1,T2-T1+1);
+		colormap jet;
+		bar((T1:T2)/8,ID);
+		xlabel('metrical position');
+		title('total event count');
+		h=gca;
+	end
+
+	function h=total_info_dist
+		DTime=round(8*TM);
+		T1=min(DTime);
+		T2=max(DTime);
+		ID=accumhist(DTime-T1+1,Info,T2-T1+1);
+		colormap jet;
+		bar((T1:T2)/8,ID);
+		xlabel('metrical position');
+		title('total information gain');
+		h=gca;
+	end
+
+	function h=mean_info_dist
+		DTime=round(8*TM);
+		T1=min(DTime);
+		T2=max(DTime);
+		ID=accumhist(DTime-T1+1,Info,T2-T1+1);
+		CC=accumhist(DTime-T1+1,1,T2-T1+1);
+		colormap jet;
+		bar((T1:T2)/8,ID./CC);
+		xlabel('metrical position');
+		title('mean information per event');
+		h=gca;
+	end
+	function h=metre_entropies
+		newplot; hold on;
+		scat1([TM,BDT(:,8)],'b+');
+		scat1([TM,BDT(:,7)],'ro');
+		hold off;
+		legend({'prior entropy','posterior entropy'});
+		xlabel('metrical position');
+		ylabel('entropy/nats');
+		rotate3d off;
+		h=gca;
+	end
+
+	function h=scat_with_metre(X,lab1,lab2)
+		if opts.with_metre
+			h=scat_by_type([X,TM],{lab1,lab2,'metrical position'});
+			camproj('orthographic');
+		else
+			h=scat_by_type(X,{lab1,lab2});
+		end
+	end
+
+	function h=scat3d_by_type(X,labels)
+		h=scat_by_type(X,labels);
+		camproj('perspective');
+		axis vis3d;
+	end
+
+	function h=scat_by_type(X,labels)
+		newplot; hold on;
+		scat1(X(K,:),'ro');
+		scat1(X(S,:),'b+');
+		hold off;
+		legend({'kick','snare'});
+		axislabels(labels);
+		if length(labels)>2, rotate3d on; 
+		else rotate3d off; 
+		end
+		h=gca;
+	end
+
+	function scat1(X,marker)
+		if size(X,2)<=2
+			plot(X(:,1),X(:,2),marker,plotargs{:});
+		else 
+			plot3(X(:,1),X(:,2),X(:,3),marker,plotargs{:});
+		end
+		box on;
+	end
+end
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/matlab/fileplay.m	Mon Mar 12 15:51:05 2012 +0000
@@ -0,0 +1,36 @@
+% fileplay - Do plots for given file and play over MIDI channel 9
+% Data is played on kick and snare (note numbers 36 and 38).
+% Metrical grid can be played on hi-hat, cowbell etc.
+function player=fileplay(MO,file,varargin)
+	opts=prefs('vel',80,'dur',0.1,'shift',file{2},'metre',[],varargin{:});
+
+	disp(file{1});
+	BDT=shift_beat(opts.shift,read(file{1}));
+	drumplot(BDT,'bar',4,'pause',0,varargin{:});
+	player=playdrums(MO,[36,38,42,44,51,56,49,53],addmetre(opts.metre,BDT(:,[2,1,4])),opts);
+end
+
+function player=playdrums(MO,PercMap,Evs,opts)
+	NN=map(PercMap,Evs(:,1));
+	Times=(Evs(:,2)-Evs(1,2))/1000;
+	player=rendermidi(MO,window(zipmidi_abs(Times,opts.dur,9,NN,opts.vel)'),nows(MO)+1);
+end
+
+function Evs=addmetre(metre,Evs)
+	for i=1:size(metre,1)
+		Evs=add_periodic(metre(i,1),metre(i,2),Evs);
+	end
+end
+
+function X=add_periodic(m,type,Y)
+	[UMetPos,K]=unique(Y(:,3));
+	Bars=(0:m:max(UMetPos))';
+	BarTimes=interp1(UMetPos,Y(K,2),Bars);
+	Types=repmat(type,size(BarTimes));
+	X=sort_by(2,vertcat(Y,[Types,BarTimes,Bars]));
+end
+
+function X=sort_by(col,Y)
+	[dummy,K]=sort(Y(:,col));
+	X=Y(K,:);
+end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/matlab/fileplot.m	Mon Mar 12 15:51:05 2012 +0000
@@ -0,0 +1,5 @@
+function fileplot(file,varargin)
+	disp(file{1});
+	drumplot(read_shift(file),varargin{:});
+	optpause(prefs('pause',1,'drawnow',1,varargin{:}));
+end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/matlab/finite_shift.m	Mon Mar 12 15:51:05 2012 +0000
@@ -0,0 +1,3 @@
+function b=finite_shift(file)
+	b=isfinite(file{2});
+end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/matlab/indplots.m	Mon Mar 12 15:51:05 2012 +0000
@@ -0,0 +1,7 @@
+function indplots(files_shifts,varargin)
+	opts=prefs('print',0,varargin{:});
+	for i=1:length(files_shifts)
+		if finite_shift(files_shifts{i})
+			fileplot(files_shifts{i},'basename',sprintf('plots/file%d',i),opts);
+		end
+	end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/matlab/paperplot.m	Mon Mar 12 15:51:05 2012 +0000
@@ -0,0 +1,5 @@
+function h=paperplot(fig,fn,varargin)
+
+opts=prefs('epsfile',[],varargin{:});
+h=printfig(fig,fn,opts.epsfile,'font_name','Helvetica','print',~isempty(opts.epsfile),varargin{:});
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/matlab/read_shift.m	Mon Mar 12 15:51:05 2012 +0000
@@ -0,0 +1,3 @@
+function X=read_shift(file)
+	X=shift_beat(file{2},read(file{1}));
+end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/matlab/shift_beat.m	Mon Mar 12 15:51:05 2012 +0000
@@ -0,0 +1,4 @@
+function X=shift_beat(delta,X)		
+	X(:,4)=X(:,4)+delta;
+end
+