%  Genearates Figure 6 using the script "threePulsePredict.m"
%     Oh & Matveev (2010)

global C ECa EK EL Esyn gCa gK gL Iapp tSyn tRise gSyn Vth PP;

DT1 = 0.3; DT2 = 3; DT3 = 5;

actualSet = [];
predictedSet = [];
sameSet = [];
firstSet = [];
zeroSet = [];
phi2Set = [];
phi3Set = [];
gSynSet = [];

for gSyn = 0.1:0.1:2
    
    threePulsePredict;
    actualSet    = [actualSet, Actual];
    predictedSet = [predictedSet, Predicted];
    zeroSet      = [zeroSet, Zero];
    firstSet     = [firstSet, First];
    sameSet      = [sameSet, Same];
    
    phi2Set = [phi2Set, phi2];
    phi3Set = [phi3Set, phi3];
    gSynSet = [gSynSet, gSyn];
    
    subplot(3,1,[1 2]);   hold on;
    plot(gSynSet, sameSet,  'b+:');
    plot(gSynSet, firstSet, 'm*-');
    plot(gSynSet, predictedSet, '.-r'); 
    plot(gSynSet, actualSet, 'ko');
    
    h=legend('\Delta(\phi_n<0)=\Delta(\phi_{n-1})', ...
             '\Delta(\phi_n<0)=\Delta(\phi_{min})', ...
             'Predicted (extended STRC)', 'Actual delay');
    %set(h,'Interpreter','latex');
    xlabel('g_{syn}'); 
    ylabel('Delay due to 3 pulses, normalized by T_0');
    axis([0.1 2 0.2 0.55]);
    
    %plot(gSynSet, zeroSet, 'c.-');
    %plot(gSyn, Delta1, '.k'); 
    %plot(gSyn, Delta2, '.b'); 
    %plot(gSyn, Delta3, '.g'); 
    
    subplot(313); hold on;
    %plot(gSyn, Slope);
    plot(gSynSet, phi3Set, 'd-b', 'markerfacecolor', 'blue');
    plot(gSynSet, phi2Set, 's-k', 'markerfacecolor', 'black'); 
    hl = legend('\phi_3', '\phi_2');
    %set(hl,'Interpreter','latex');
    xlabel('g_{syn}'); 
    h = ylabel('\phi_2, \phi_3', 'fontsize', 12);
    %set(h,'Interpreter','latex','string','$\varphi_2, \varphi_3$');
    
    drawnow;
end;

plot([0.1 2], [0 0],':k');
    
