%% load and concatenate data

dirID = 'C:\Users\USER\Documents\mingfaifong\goonI3588\';
fid = 'goonI3588_12DIV_no-drug_02';
loadspk([dirID fid '.spk']);
time = ans.time-max(ans.time);
channel = ans.channel;
%unit = ans.unit;
meta.nodrug = ans.meta;
%waveform = ans.waveform;
threshold = ans.threshold;

fid = 'goonI3588_13DIV_40uM-CNQX_OB-control_01';
loadspk([dirID fid '.spk']);
time = [time; ans.time];
channel = [channel; ans.channel];
%unit = [unit; ans.unit];
meta.CNQX1 = ans.meta;
%waveform = ans.waveform;
threshold = [threshold; ans.threshold];

t_switch = max(time);

fid = 'goonI3588_13DIV_40uM-CNQX_OB-control_02-0.5hz';
loadspk([dirID fid '.spk']);
time = [time; ans.time+max(time)];
channel = [channel; ans.channel];
%unit = [unit; ans.unit];
meta.CNQX2 = ans.meta;
%waveform = ans.waveform;
threshold = [threshold; ans.threshold];

%save([dirID 'goonI3588.mat'],'time','channel','unit','meta','threshold','t_switch');
save([dirID 'goonI3588.mat'],'time','channel','meta','threshold','t_switch');

%% generate asdr
clear t asdr
dt = 60;
bins = ceil(min(time)/dt)*dt:dt:floor(max(time)/dt)*dt;
asdr = histc(time,bins)/dt;


%% plot stuff
stairs(bins/3600,asdr,'-k');
ylabel('ASDR (Hz)');
xlabel('Time (hours)');
xlim([-12 22]);
hold on;
plot([5.5/60 21.93333],[42.5256 42.5256],':r','LineWidth',2);
set(gca,'TickDir','out','TickLength',[0.0025 0.025],'XTick',[-12:1:22],'FontSize',12);
xlabel('Time (hours)','FontSize',16);
ylabel(['Array-Wide Firing Rate (Hz)',10,'[60-sec bins]'],'FontSize',16);
box off;
hold off;
