%% ASDR plot

figure(3); hold off;
binsize = 3600; %seconds
bins = min(time(unit~=0)):binsize:max(time(unit~=0));
asdr = histc(time(unit~=0),bins);

subplot(2,1,2);
plot(bins,asdr/max(unit)/binsize,'-ok');
%ymax = ceil(max(asdr/max(unit)/binsize));
set(gca,'XTick',[-24*3600:3600:80*3600],'XTickLabel',[-24:1:80],'TickLength',[0.0025 0.025]);
xlim([min(bins) max(bins)]);
ylim([0 ymax]);
xlabel('Time (hours)','FontSize',18);
ylabel('Normalized ASDR (Hz/unit)','FontSize',18);

%%

timepoints = [-1*3600,... %an hour before drug
    0,...               %right after drug is added but before stim turns on
    5.5*60,...            %after stim turns on
    12*3600+5.5*60,...    %12 hours after stim begins
    24*3600,...         %5min before stim turns off
    24*3600+5.5*60,...    %after stim turns off but before wash
    starttimes(4)+10*60,...   %10min after 2nd set of washes
    starttimes(4)+3*3600];   %12hr after 2nd set of washes

snip_length = 5*60; %length of time snippet in seconds

figure(2);

for i = 1:length(timepoints)
    subplot(length(timepoints),1,i); hold off;
    snip_ind = find(time>=timepoints(i) & time<timepoints(i)+snip_length & unit~=0);
    plot(time(snip_ind),unit(snip_ind)+0.1*randn(size(unit(snip_ind))),'.','MarkerSize',1);
    ylim([0 max(unit)+1]);
    xlim([time(min(snip_ind)) time(max(snip_ind))]);
    set(gca,'YTick',[0 max(unit)+1],'XTick',[]);
    %text(max(unit(snip_in
    ylabel('Unit','FontSize',14);
end;
xlabel('Time (5-minute snippet)','FontSize',14);