bounds = [-16:1:49]*3600;

for i = 1:length(bounds)-1
    tmp.time = alldata.time(alldata.time>bounds(i) & alldata.time<=bounds(i+1));
    tmp.isburst = alldata.isburst(alldata.time>bounds(i) & alldata.time<=bounds(i+1));
    if i==1 || i==length(bounds)-1
        dem = (max(tmp.time)-min(tmp.time));
    else
        dem/3600;
    end
    FR.total(i) = length(tmp.isburst)/dem;
    FR.burst(i) = sum(tmp.isburst)/dem;
    FR.IBI(i) = sum(abs(tmp.isburst-1))/dem;
end

%% plot stuff

close all; figure;
%subplot(3,1,1);
plot(bounds(1:end-1)/3600+0.5,FR.total,'b-','MarkerSize',20,'LineWidth',4); hold on;
%subplot(3,1,2);
plot(bounds(1:end-1)/3600+0.5,FR.burst,'k-','MarkerSize',20,'LineWidth',4);
%subplot(3,1,3);
plot(bounds(1:end-1)/3600+0.5,FR.IBI,'r-','MarkerSize',20,'LineWidth',4);

axis([bounds(1)/3600 bounds(end)/3600 0 65]);
grid on;
set(gca,'XTick',-16:1:49,'YTick',0:5:65);
xlabel('Time (hours)','FontSize',16); ylabel('Array-Wide Firing Rate (Hz)','FontSize',16);

legend('all spikes','spikes in bursts','spikes in interburst interval');