x1 = loadspk('milkdud19309_13DIV_nodrug-2012-01-19-00-19-06.spk');
x2 = loadspk('milkdud19309_14DIV_vehicle-2012-01-19-10-01-05.spk');
x3 = loadspk('milkdud19309_15DIV_vehicle-2012-01-20-09-59-27.spk');

badchannels = [1 8 33 57 64];
x1.time = x1.time(~ismember(x1.channel,badchannels));
x1.unit = x1.unit(~ismember(x1.channel,badchannels));
x1.channel = x1.channel(~ismember(x1.channel,badchannels));

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

timestamps = [0 max(x2.time)];

save milkdud19309_13-15DIV time channel unit timestamps;


%%

load milkdud19309_13-15DIV.mat

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

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),'added vehicle','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,[39.4160 39.4160],'-g');

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

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