%% load data

fid = 'C:\Users\Jon\Desktop\mingledorf\2012-09-10_APV-CNQX-tests\2012-09-10_fatty-21368_nodrug.spk';
loadspk(fid);


w(1,:) = [3 4 5 12 13 20 21 28 29];
w(2,:) = [7 14 15 16 22 23 24 30 31];
w(3,:) = [38 39 40 46 47 48 55 56 63];
w(4,:) = [36 37 44 45 52 53 60 61 62];
w(5,:) = [34 35 41 42 43 49 50 51 58];
w(6,:) = [2 9 10 17 18 19 25 26 27];

time = ans.time;
channel = ans.channel;
unit = ans.unit;
meta = ans.meta;
waveform = ans.waveform;
threshold = ans.threshold;

% save fatty21368_22DIV_drugs_01 time channel unit meta threshold;


%% generate asdr
clear t asdr c
dt = 1;
bins = 0:dt:max(time);
asdr = zeros(6,length(bins));

for i = 1:6
    %t{i} = time(clean==1 & ismember(channel,w(i,:))==1);
    t{i} = time(ismember(channel,w(i,:))==1);
    c{i} = channel(ismember(channel,w(i,:))==1);
    asdr(i,:) = hist(t{i},bins)/dt;
end

%% raster
subplot(2,3,1)
plot(t{4},c{4}+randn(size(c{4}))*0.15,'.k','MarkerSize',2);
set(gca,'XTick',[0:5*60:6*5*60],'XTickLabel',[0:5:30]);
xlim([15 30]*60)
%title('2012-09-10_fatty21369_wellE_nodrug','Interpreter','none');

subplot(2,3,4)
plot(t{6},c{6}+randn(size(c{6}))*0.15,'.k','MarkerSize',2);
set(gca,'XTick',[0:5*60:3*5*60],'XTickLabel',[0:5:15]);
xlim([15 30]*60)
%title('2012-09-10_fatty21369_wellF_nodrug','Interpreter','none');

%% plot stuff
    stairs(bins/3600,asdr(i,:),'-k');
    %plot(bins(1:end-1)/3600+.5,asdr(i,1:end-1),'-ok','LineWidth',2,'MarkerSize',5);
    %xlim([0 .5]);
    ylim([0 50]); grid on;
    set(gca,'XTick',0:4:max(time)/3600);
    ylabel('ASDR (Hz)');
    
xlabel('Time (hours)');

subplot(6,1,1);
title(['fatty21368 (third 24 hours with drugs)']);