% 
% 
% %% Fig 2A
% 
% subplot(2,1,1);
% hold off;
% plot(CNQX.time,...
%     CNQX.channel+0.15*randn(size(CNQX.time)),...
%     '.','Markersize',2,'Color',[0.4 0.4 0.4]);
% ylim([1 64]);
% set(gca,'XTick',min(CNQX.time):60*5:max(CNQX.time),'YTick',0:10:70);
% xlim([xstart xstart+1800]);
% 
% subplot(2,1,2);
% hold off;
% asdr.bins = min(CNQX.time):1:max(CNQX.time);
% asdr.all = histc(CNQX.time,asdr.bins);
% plot(asdr.bins,asdr.all,'-','Color',[0.4 0.4 0.4]);
% set(gca,'XTick',min(CNQX.time):60*5:max(CNQX.time));
% ylim([0 4500]);
% xlim([xstart xstart+1800]);

%% lim stuff
xstart = 1.5036e5;
%xstart = 1.953e5;

%% Close
close all;

%% Fig 2A - raster only
hold off;
plot(CNQX.time(CNQX.isburst),CNQX.channel(CNQX.isburst)+0.15*randn(size(CNQX.time(CNQX.isburst))),...
    '.','Markersize',2,'Color',[0 0 0]/255);
hold on;
plot(CNQX.time(~CNQX.isburst),CNQX.channel(~CNQX.isburst)+0.15*randn(size(CNQX.time(~CNQX.isburst))),...
    '.','Markersize',2,'Color',[0 0 0]/255);
ylim([1 64]);

xlim([xstart xstart+3600*10]);
set(gca,'XTick',min(CNQX.time):3600:max(CNQX.time),'XTickLabel',round([min(CNQX.time):3600:max(CNQX.time)]/3600-41.5),'YTick',0:20:60);
%legend('all spikes','orientation','horizontal','location','northwest');
xlim([tmp(1) tmp(1)+20])
axis square;

%% Fig 2B - raster w/ bursts colored in red, interbursts in blue
hold off;
plot(CNQX.time(~CNQX.isburst),CNQX.channel(~CNQX.isburst)+0.15*randn(size(CNQX.time(~CNQX.isburst))),...
    '.','Markersize',2,'Color',[0 75 255]/255);
hold on;
plot(CNQX.time(CNQX.isburst),CNQX.channel(CNQX.isburst)+0.15*randn(size(CNQX.time(CNQX.isburst))),...
    '.','Markersize',2,'Color',[255 0 0]/255);
ylim([1 64]);

xlim([xstart xstart+3600*10]);
%xlim([xstart xstart+15]);
set(gca,'XTick',min(CNQX.time):3600:max(CNQX.time),'XTickLabel',round([min(CNQX.time):3600:max(CNQX.time)]/3600-41.5),'YTick',0:20:60);
%legend('spikes in bursts','spike in interburst interval','orientation','horizontal','location','northwest');
xlim([tmp(1) tmp(1)+20])
axis square;
%% Fig 2C - asdr for 1 second bins
bins = min(CNQX.time):1:max(CNQX.time);
asdr.burst = histc(CNQX.time(CNQX.isburst),bins);
asdr.IBI = histc(CNQX.time(~CNQX.isburst),bins);
asdr.all = histc(CNQX.time,bins);

hold off;
plot(bins+0.5,asdr.all,'-','Color',[0 0 0],'LineWidth',2.5);
hold on;
plot(bins+0.5,asdr.burst,'-','Color',[255 0 0]/255,'LineWidth',1);
plot(bins+0.5,asdr.IBI,'-','Color',[0 75 255]/255,'LineWidth',3);

hold on;
xlim([xstart xstart+3600*10]);
set(gca,'XTick',min(CNQX.time):3600:max(CNQX.time),'XTickLabel',round([min(CNQX.time):3600:max(CNQX.time)]/3600-41.5));
%legend('all spikes','spikes in bursts','spike in interburst interval','orientation','horizontal','location','northwest');

xlim([tmp(1) tmp(1)+20])
axis square;
%% Fig 2D - asdr for 1-hour bins
bins = min(CNQX.time):3600:max(CNQX.time);
asdr.burst = histc(CNQX.time(CNQX.isburst),bins)/3600;
asdr.IBI = histc(CNQX.time(~CNQX.isburst),bins)/3600;
asdr.all = histc(CNQX.time,bins)/3600;

hold off;
plot(bins+1800,asdr.all,'-o','Color',[0 0 0],'LineWidth',2);
hold on;
plot(bins+1800,asdr.burst,'-o','Color',[255 0 0]/255,'LineWidth',2);
plot(bins+1800,asdr.IBI,'-o','Color',[0 75 255]/255,'LineWidth',2);

hold on;
xlim([xstart xstart+3600*10]);
set(gca,'XTick',min(CNQX.time):3600:max(CNQX.time),'XTickLabel',round([min(CNQX.time):3600:max(CNQX.time)]/3600-41.5));
legend('all spikes','spikes in bursts','spike in interburst interval','orientation','horizontal','location','northwest');