
%% Fig 6 CNQX ASDR

clear;
[events.time events.comment] = get_events('buster359');
load('buster359\buster359_nowaveform.mat');
%time(time>events.time(3)) = time(time>events.time(3))-events.time(3)+52*3600+events.time(1);

b359.time = (time-events.time(1))/3600;
b359.time = b359.time(clean==1);
b359.channel = channel(clean==1);

b359.bins = min(b359.time):1/3600:max(b359.time);
b359.asdr = hist(b359.time,b359.bins);
subplot(2,1,1)
plot(b359.bins,b359.asdr,'-k');

xlim([-12 48]);

b359.ISI = [NaN; diff(b359.time)];
tmp1 = b359.time(b359.ISI<=19.5/3600/1000 & b359.time<0);
%tmp2 = [];
tmp2 = b359.time(b359.ISI<=11.5/3600/1000 & b359.time>=0 & b359.time<50);
%tmp3 = b359.time(b359.ISI<=39.5/3600/1000 & b359.time>=50);
tmp3 = [];
b359.burst = [tmp1; tmp2; tmp3];
clear tmp;
tmp1 = b359.time(b359.ISI>19.5/3600/1000 & b359.time<0);
%tmp2 = [];
tmp2 = b359.time(b359.ISI>11.5/3600/1000 & b359.time>=0 & b359.time<50);
%tmp3 = b359.time(b359.ISI>39.5/3600/1000 & b359.time>=50);
tmp3 = [];
b359.IBI = [tmp1; tmp2; tmp3];

b359.bin1hr = floor(min(b359.time)):1:ceil(max(b359.time));
b359.asdr1hr.all = histc(b359.time,b359.bin1hr)/3600;
b359.asdr1hr.burst = histc(b359.burst,b359.bin1hr)/3600;
b359.asdr1hr.IBI = histc(b359.IBI,b359.bin1hr)/3600;

subplot(2,1,2);
hold off;
plot(b359.bin1hr+0.5,b359.asdr1hr.burst,'-r','LineWidth',2);
hold on;
plot(b359.bin1hr+0.5,b359.asdr1hr.IBI,'-b','LineWidth',2);
plot(b359.bin1hr+0.5,b359.asdr1hr.all,'-k','LineWidth',2);

xlim([-12 48]);
%ylim([0 24]);
%set(gca,'YTick',0:4:24)
grid on;
set(gca,'XTick',-12:2:64);