%% load files
x1 = loadspk('zeno19309_14DIV_pre-drug_01.spk');
x2 = loadspk('zeno19309_15DIV_40uM-CNQX_01.spk');


%% combine
time = [x1.time - max(x1.time); ...
    x2.time];
channel = [x1.channel; x2.channel];

%% raster, asdr

x_low = min(time);
x_high = max(time);

subplot(4,1,1)
plot(time/3600,channel+.15*randn(size(channel)),'.k','MarkerSize',3);
%axis([min(time)/3600 max(time)/3600 0 max(channel)]);
%axis([x_low x_high 0.5 max(channel)+0.5]);
set(gca,'XTick',[x_low:1:x_high]);
ylabel('channel','FontSize',14);

dt = 1;
bin = min(time):dt:max(time);
asdr = histc(time,bin);
subplot(4,1,2)
plot((bin+dt)/3600,asdr/dt,'-k');
%axis([x_low x_high 0 ceil(10*max(asdr)/dt)/10]);
set(gca,'XTick',[x_low:1:x_high]);
ylabel(['Array-Wide Firing',10,'Rate (Hz/channel)',10,'[' num2str(dt) '-sec bins]'],'FontSize',14);


dt = 60;
bin = min(time):dt:max(time);
asdr = histc(time,bin);
subplot(4,1,3)
plot((bin+dt)/3600,asdr/dt,'-k');
%axis([min(time)/3600 max(time)/3600 0 ceil(10*max(asdr/dt))/10/10]);
%axis([x_low x_high 0 ceil(10*max(asdr)/dt)/10]);
set(gca,'XTick',[x_low:1:x_high]);
ylabel(['Array-Wide Firing',10,'Rate (Hz/channel)',10,'[' num2str(dt) '-sec bins]'],'FontSize',14);

dt = 3600;
bin = min(time):dt:max(time);
asdr = histc(time,bin);
subplot(4,1,4)
plot((bin+dt)/3600,asdr/dt,'-k');
%axis([min(time)/3600 max(time)/3600 0 ceil(10*max(asdr/dt))/10/10]);
%axis([x_low x_high 0 ceil(10*max(asdr)/dt)/10]);
set(gca,'XTick',[x_low:1:x_high]);
ylabel(['Array-Wide Firing',10,'Rate (Hz/channel)',10,'[' num2str(dt) '-sec bins]'],'FontSize',14);
xlabel('Time (hours)','FontSize',14);

for i = 1:4
    subplot(4,1,i)
    set(gca,'TickDir','out','TickLength',[0.002 0.025]);
end
