load('yoda363/yoda363_nowaveform.mat');
[evt_times evt_text] = get_events('yoda363');

data.time = spktimes(logical(cleanspk));
data.channel = channels(logical(cleanspk));
data.channel = data.channel(data.time<evt_times(3));
data.time = data.time(data.time<evt_times(3))-evt_times(1);

group1 = find(data.channel==1 | data.channel==4 | data.channel==7 | data.channel==10 | data.channel==13 | data.channel==16 | data.channel==19 | data.channel==22 | data.channel==25 | data.channel==28 | data.channel==31 | data.channel==34 | data.channel==37 | data.channel==40 | data.channel==43 | data.channel==46 | data.channel==49 | data.channel==52 | data.channel==55 | data.channel==58 | data.channel==61);
group2 = find(data.channel==2 | data.channel==5 | data.channel==8 | data.channel==11 | data.channel==14 | data.channel==17 | data.channel==20 | data.channel==23 | data.channel==26 | data.channel==29 | data.channel==32 | data.channel==35 | data.channel==38 | data.channel==41 | data.channel==44 | data.channel==47 | data.channel==50 | data.channel==53 | data.channel==56 | data.channel==59 | data.channel==62);
group3 = find(data.channel==3 | data.channel==6 | data.channel==9 | data.channel==12 | data.channel==15 | data.channel==18 | data.channel==21 | data.channel==24 | data.channel==27 | data.channel==30 | data.channel==33 | data.channel==36 | data.channel==39 | data.channel==42 | data.channel==45 | data.channel==48 | data.channel==51 | data.channel==54 | data.channel==57 | data.channel==60 | data.channel==63);
spktimes1 = data.time(group1); spktimes2 = data.time(group2); spktimes3 = data.time(group3);
channels1 = data.channel(group1); channels2 = data.channel(group2); channels3 = data.channel(group3);

close all; h_tight = tight_subplot(6,1,[.04 .04],[.075 .02],[.1 .01]);

for i = 1:6
axes(h_tight(i))
%plot(SS.time-evt_times(1),SS.channel+randn*.3,'.','MarkerSize',1);
	plot(spktimes1,channels1+0.25*randn(size(channels1)),'.','Color',[0 51 153]/255,'MarkerSize',1.5);
    hold on;
	plot(spktimes2,channels2+0.25*randn(size(channels2)),'.','Color',[51 153 0]/255,'MarkerSize',1.5);
	plot(spktimes3,channels3+0.25*randn(size(channels3)),'.','Color',[204 0 0]/255,'MarkerSize',1.5);
ylim([0 65])
lowerlim = -20+12*(i-1); upperlim = -8+12*(i-1);
xlim(3600*[lowerlim upperlim]);
set(gca,'XTick',3600*[lowerlim:1:upperlim]);
set(gca,'XTickLabel',[lowerlim:1:upperlim]);
end



%% asdr

load('yoda363/yoda363_nowaveform.SS','-mat');
%SS.time = SS.time;
SS.clean = SS.clean(SS.time<evt_times(3));
SS.time = SS.time(SS.time<evt_times(3));


for i = 1:6
axes(h_tight(i))
hold off;
SS.ASDR(1,1,0);
lowerlim = -20+12*(i-1); upperlim = -8+12*(i-1);
xlim(3600*[lowerlim+evt_times(1)/3600 upperlim+evt_times(1)/3600]);
set(gca,'XTick',3600*[lowerlim+evt_times(1)/3600:1:upperlim+evt_times(1)/3600]);
set(gca,'XTickLabel',[lowerlim:1:upperlim]);
xlabel(''); ylabel('')
ylim([0 1000])
end


%% BI filt

h_tight = tight_subplot(6,1,[.04 .04],[.075 .02],[.1 .01]);

load('yoda363/yoda363_BIfilt.mat','-mat');
[evt_times evt_text] = get_events('yoda363');
asdr_times = asdr_times;
BI = BI(asdr_times<evt_times(3));
asdr_times = asdr_times(asdr_times<evt_times(3))-evt_times(1);

for i = 1:6
axes(h_tight(i))
hold off;
plot(asdr_times,BI,'-b');
lowerlim = -20+12*(i-1); upperlim = -8+12*(i-1);
xlim(3600*[lowerlim upperlim]);
set(gca,'XTick',3600*[lowerlim:1:upperlim]);
set(gca,'XTickLabel',[lowerlim:1:upperlim]);
ylim([0 1])
end
