% This file is licensed under the Allen Institute Terms of Use, which can be found at:
%http://www.alleninstitute.org/Media/policies/terms_of_use_content.html

%Script for Supp. Fig. S5 showing possible EPSPs that give rise to DiPDE
%bds. for non-instantaneous synapses. Refer Methods: Non-instantaneous
%synapses in paper

clear variables;

%Parameters
dt1 = 0.1*10^-3;
t1 = 0:dt1:15*10^-3;
V0 = 5*10^-3;         % (V) value of (J_syn*tau_syn/C_m) used in simulations
taum = 20*10^-3;      % (s) membrane time constant
taus = 1*10^-3;       %synaptic time constant

%EPSPs
tmax = ((taum*taus)/(taum-taus))*log(taum/taus); %time taken to reach maximum depolarization
Vm = V0*(taum)/(taum-taus)*((taus/taum)^(taus/(taum-taus))-(taus/taum)^(taum/(taum-taus)));  %max depolarization
V_q = V0*exp(-t1/taum);     %EPSP for equating total charge
V_ex = (V0*taum)/(taum-taus)*(exp(-t1/taum)-exp(-t1/taus)); %exact EPSP for non-instantaneous synapse
V_l = Vm*exp(-(t1)/taum);   %EPSP for equating max depolarization
V_u = V0*((taum)/(taum-taus))*exp(-t1/taum); %EPSP for upper bound

%Settings for plot
fnt = 36;
fntlab=18;
xtc = [0;5;10;15]*10^-3;  %x-axis ticks for time in (ms)
ytc = [0;1;2;3;4;5;6]*10^-3; %y-axis ticks for membrane potential in (mV)
xtl = [0;5;10;15]; %x-axis labels for time in (ms)
ytl = [0;1;2;3;4;5;6]; %y-axis labels for membrane potential in (mV)

set(0,'DefaultFigureWindowStyle','docked');
set(0,'defaultAxesFontName', 'Arial');

figure;
plot(t1,V_q,'--',t1,V_ex,'--',t1,V_l,'--',t1,V_u,'--','LineWidth',4);
set(gca,'FontSize',fnt);
set(gca,'XTick',xtc);
set(gca,'XTickLabel',xtl);
set(gca,'YTick',ytc);
set(gca,'YTickLabel',ytl);
leg1 = legend('V_{q}','V_{ex}','V_{l}','V_{u}','Location','NorthEast');
set(gca,'FontSize',fnt);
ylabel('EPSP (mV)');xlabel('time (ms)');
set(leg1,'FontSize',fntlab,'Interpreter','tex');
axis square; box on;

print2eps Fig_S5.eps
