load('C:\Users\USER\Documents\mingfaifong\buster359\buster359_FullRecNoWaveformNoClean.mat');
%[e1 e2] = get_events('buster359');

dt = 25/25000;

close all;
figure('units','normalized','outerposition',[0 0 2 1])

subplot(2,4,1);
%pre.time = sortrows(time(time<e1(1))-e1(1));
pre.time = sortrows(time(time<e1(1)));
pre.ISI = diff(pre.time);
pre.bins = 0.5*dt:dt:max(pre.ISI(pre.ISI<60));
pre.hist = hist(pre.ISI,pre.bins);
bar(pre.bins,pre.hist/length(pre.time));
set(gca,'yscale','log');
set(gca,'TickDir','out');
grid on; xlim([-0.1 10]);
xlabel('Interspike Interval (seconds)'); ylabel('Counts');
title(['buster359 before CNQX',10,'ISI Distribution',10,'(normalized to total number of spikes)']);

subplot(2,4,2);
bar(pre.bins,pre.hist/((max(CNQX.time)-min(CNQX.time))*3600));
set(gca,'yscale','log');
set(gca,'TickDir','out');
grid on; xlim([-0.1 10]);
xlabel('Interspike Interval (seconds)'); ylabel('Counts');
title(['buster359 before CNQX',10,'ISI Distribution',10,'(normalized to total number of hours)']);

subplot(2,4,3);
bar(pre.bins,pre.hist.*pre.bins/length(pre.time));
grid on; xlim([-0.1 10]);
ylim([0 1]);
set(gca,'TickDir','out');
xlabel('Interspike Interval (seconds)'); ylabel('Counts * ISI');
title(['buster359 before CNQX',10,'ISI Distribution',10,'(normalized to ISI length and total number of spikes)']);

subplot(2,4,4);
bar(pre.bins,pre.hist.*pre.bins/((max(CNQX.time)-min(CNQX.time))*3600));
grid on; xlim([-0.1 10]);
ylim([0 1]);
set(gca,'TickDir','out');
xlabel('Interspike Interval (seconds)'); ylabel('Counts * ISI');
title(['buster359 before CNQX',10,'ISI Distribution',10,'(normalized to ISI length and total number of spikes)']);

%%
subplot(2,4,2);
%CNQX.time = sortrows(time(time>=e1(1))-e1(1));
CNQX.time = sortrows(time(time>=e1(1)));
CNQX.ISI = diff(CNQX.time);
CNQX.bins = 0.5*dt:dt:max(CNQX.ISI(CNQX.ISI<60));
CNQX.hist = hist(CNQX.ISI,CNQX.bins);
bar(CNQX.bins,CNQX.hist/length(CNQX.time)*1e7);
set(gca,'yscale','log');
set(gca,'TickDir','out');
grid on; xlim([-0.1 10]);
xlabel('Interspike Interval (seconds)'); ylabel('Counts');
title(['buster359 after CNQX',10,'ISI Distribution',10,'(normalized to total number of spikes)']);

subplot(2,4,4);
bar(CNQX.bins,CNQX.bins.*CNQX.hist/length(CNQX.time)*1e4);
grid on; xlim([-0.1 10]);
ylim([0 1]);
set(gca,'TickDir','out');
xlabel('Interspike Interval (seconds)'); ylabel('Counts * ISI');
title(['buster359 after CNQX',10,'ISI Distribution',10,'(normalized to ISI length and total number of spikes)']);
%hold on; plot([0 max(CNQX.bins)],[0 max(CNQX.bins)],':','Color',[0.5 0.5 0.5]);
%plot([0 max(CNQX.bins)],2*[0 max(CNQX.bins)],':','Color',[0.5 0.5 0.5]);