fid = 'atlas22471_11DIV_40uM-CNQX-ChR2-stim-CL-2x_01';
% t_end = loadspk([fid '.spk'],'last');
% spk = loadspk([fid '.spk'],[0 t_end],0);
spk = loadspk([fid '.spk']);
ss = SqueakySpk(fid,spk.meta.fs_Hz,1,spk);
% ss.RemoveChannel([1 8 33 57 64 55])
sc = ss.ReturnClean();
% b = loadbang([fid '.bang']);

avgFR_1hr  = length(sc.time(sc.time > max(sc.time) - 1*3600))/(1*3600)
avgFR_3hr  = length(sc.time(sc.time > max(sc.time) - 3*3600))/(3*3600)
avgFR_6hr  = length(sc.time(sc.time > max(sc.time) - 6*3600))/(6*3600)
avgFR_12hr = length(sc.time(sc.time > max(sc.time) - 12*3600))/(12*3600)

%%
close all
figure
dt_asdr = 60; % sec
%bin = max(sc.time)-12*3600:dt_asdr:max(sc.time);
bin = min(sc.time):dt_asdr:max(sc.time);
asdr = histc(sc.time,bin);

plot([bin(6),bin(end)]/3600,[2*34.0024 2*34.0024],'-g','LineWidth',2); hold on;
plot(bin(1:end-1)/3600,asdr(1:end-1)/dt_asdr,'k-','LineWidth',1);
% plot([max(sc.time)-1*3600, max(sc.time)]/3600,[avgFR_1hr,avgFR_1hr],'-m','LineWidth',2);
% plot([max(sc.time)-3*3600, max(sc.time)]/3600,[avgFR_3hr,avgFR_3hr],'-g','LineWidth',2);
% plot([max(sc.time)-6*3600, max(sc.time)]/3600,[avgFR_6hr,avgFR_6hr],'-b','LineWidth',2);
% plot([max(sc.time)-12*3600,max(sc.time)]/3600,[avgFR_12hr,avgFR_12hr],'-r','LineWidth',2);
grid on;

xlim([0 17]);

xlabel('Time (hours)'); ylabel('Array-Wide Firing Rate (Hz)');

%%
% close all
% ss.ASDR(0.01)
% plot(ss.asdr.bin,ss.asdr.asdr,'r')
% hold on
% plot(b.time,b.meas)
% 
% sum(b.meas/100)
% length(ss.time)
% 
% mean(b.meas)
% mean(ss.asdr.asdr)