
%% Fig 5 TTX ASDR

clear;
[events.time events.comment] = get_events('donkeylips363');
load('donkeylips363\donkeylips363_nowaveform.mat');
time(time>events.time(3)) = time(time>events.time(3))-events.time(3)+52*3600+events.time(1);
%%
d363.time = (time-events.time(1))/3600;
d363.time = d363.time(clean==1);
d363.channel = channel(clean==1);

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

xlim([-12 48]);

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

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

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

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