x1 = loadspk('dojo22493_11DIV_nodrug_01.spk');
x2 = loadspk('dojo22493_11DIV_nodrug_02.spk');
x3 = loadspk('dojo22493_12DIV_40uM-CNQX_01.spk');
x4 = loadspk('dojo22493_12DIV_40uM-CNQX_02.spk');
% x5 = loadspk('dojo22493_13DIV_post-patch_wash4.spk');

time = [x1.time-max(x1.time)-max(x2.time); x2.time-max(x2.time); x3.time; x4.time+max(x3.time)];
channel = [x1.channel; x2.channel; x3.channel; x4.channel];
unit = [x1.unit; x2.unit; x3.unit; x4.unit];

timestamps = [0 max(x4.time)+max(x3.time)];

save dojo22493_11-13DIV time channel unit timestamps;

%%

load dojo22493_11-13DIV.mat

dt = 3600;
bin = [ceil(min(time)/dt)*dt:dt:floor(max(time)/dt)*dt];
asdr = histc(time,bin);

figure(1);
set(gcf,'Position',[455 361 2105 384]);
hold off;
stairs(bin/3600,asdr/dt,'-k','LineWidth',0.5);
hold on;
y_lim = ylim;
timestamp_label = (timestamps+120)/3600;
plot([timestamps(1) timestamps(1)]/3600,[0 y_lim(2)],'--r');
%text(timestamp_label(1),y_lim(2),'CNQX (stimulation begins 5min later)','HorizontalAlignment','left','VerticalAlignment','top','Color',[1 0 0]);
text(timestamp_label(1),y_lim(2),'CNQX','HorizontalAlignment','left','VerticalAlignment','top','Color',[1 0 0]);
plot([timestamps(2) timestamps(2)]/3600,[0 y_lim(2)],'--r');
text(timestamp_label(2),y_lim(2),'wash','HorizontalAlignment','left','VerticalAlignment','top','Color',[1 0 0]);

text(bin(1)/3600,y_lim(2),['bin size = ' num2str(dt) 'sec'],'HorizontalAlignment','left','VerticalAlignment','bottom','Color',[0 0 0]);

%plot([timestamps(1)+300 timestamps(2)]/3600,[7.16 7.16],'-g');

%xlim([bin(1) bin(end)]/3600);
xlim([-12 bin(end)/3600]);
set(gca,'XTick',[-20:2:28],'TickDir','out','TickLength',[0.0025 0.025]);
box off;

ylabel('Array-wide firing rate (Hz)','FontSize',14);
xlabel('Time (hours)','FontSize',14);