% Jon Newman
% Look at control performance

k = 1;
st = {};
sp = {};

% Pre-drug
fid = '2013_12_20_Smiley-24728_01';
[sp{k} st{k}] = smoosh(fid);
k = k+1;
ko = 1;

fid = '2013_12_20_Smiley-24728_02';
[sp{k} st{k}] = smoosh(fid);
k = k+1;
% 
fid = '2013_12_20_Smiley-24728_03';
[sp{k} st{k}] = smoosh(fid);
ko = k;
k = k+1;
% 
fid = '2013_12_20_Smiley-24728_04';
[sp{k} st{k}] = smoosh(fid);
k = k+1;

fid = '2013_12_20_Smiley-24728_05';
[sp{k} st{k}] = smoosh(fid);
bng = loadoc2([fid '.oc2.gz']);

k = k+1;



%%
close all
figure
dt_asdr = 300; % sec
xlimit = [-3 4];

subplot(311)
hold on
for i = 1:length(st)
    
    
    bin = 0:dt_asdr:max(sp{i}.time);
    asdr = hist(sp{i}.time,bin)/max(sp{i}.unit);
    bin = bin + 24*3600*(st{i} - st{ko});
    if i == 3
        da = bin(1);
    end
    stairs(bin/3600,asdr/dt_asdr,'k-');
    
    
end

plot([1/6 5],[max(bng.targ) max(bng.targ)],'r-')
ylim([0 2])
xlim(xlimit)
xlabel('Time (hrs)')
ylabel('FR (Hz/unit)')
grid on

subplot(312)
plot(bng.time/3600,bng.out2);
xlabel('Time (hrs)')
ylabel('Control singal (%)')
% ylim([0 1.2])
xlim(xlimit)

subplot(313)
bin = 0:1:max(bng.time);
transitions = [false diff(bng.out2) > 0];
plot(bng.time(transitions)/3600, [0 diff(bng.time(transitions))])
xlabel('Time (hrs)')
ylabel('on/on period (sec)')
% ylim([0 1.2])
xlim(xlimit)

%%
export_fig('2013_12_20_Smiley-24728_summary_01','-pdf','-transparent',gcf)





