epsp.m


%%% taur: rise time
%%% tauf: fall time
%%% dt: iterations over 1 millisecond
%%% W: weight
%%% I: binary spike value at time t
%%% g: conductance at the last two timestep set to 0 if first iteration
%%% C: are constants, set to zero at first iteration or if rise or fall changes
%%% returns %%%%
% g: conductance at t
function [g, C] = epsp(taur,tauf,dt,W,I, g, C)


%% designed to speed up process if taur or tauf does not change
%% if change clear C before entering this function
if length(C)<3
  %%% for div 0 case
  if (taur==tauf)
    tauf = tauf+0.01;
  end
  [c1 c2 c3] = preComputeCst(taur,tauf,dt);    %Constants for epsp to neuron
  C=[c1, c2, c3];
end

% shift g down to contain past 2
gE=0;
if length(g)<2
  g=zeros(1,2);
else
  gE=g(1);
end

g(1) = W*I*C(1) + g(1)*C(2) + g(2)*C(3);
g(2) = gE;



function [c1 c2 c3] = preComputeCst(taur,tauf,dt)
%PRECOMPUTECST computes three constants required to calculate eq. 2.11 for
%fast conductance calculations based on Kohn and Worgotter (1998).
%
%   [C1 C2 C3] = PRECOMPUTECST(TAUR,TAUF,DT,P) computes C1, C2 and C3 based
%   on Figure 2B of Kohn and Worgotter (1998). TAUR and TAUF are rise and
%   fall times respectively for the post-synaptic potentials, DT is the
%   numerical integration timestep.
%
%   References: Kohn, J. and Worgotter, F. (1998). Employing the
%   Z-transform to optimize calculation of the synaptic conductance of NMDA
%   and other synaptic channels in network simulations. Neural Computation,
%   vol. 10, 1639-1651.
%
%   See also scaleP
c1 = scaleP(taur,tauf) / (tauf-taur) * ( exp(-dt/tauf) - exp(-dt/taur) );
c2 = exp(-dt/tauf) + exp(-dt/taur);
c3 = - exp(-dt/tauf) * exp(-dt/taur);   %This is a negative constant


function out = scaleP(taur,tauf)
%SCALEP determines the value of p such that the area under the conductance curve is constant.
%First find maximum
maxt = tauf*taur / (taur-tauf) * log(taur/tauf);
%Find the value at that point
v = 1/(tauf-taur) * (exp(-maxt/tauf) - exp(-maxt/taur));
%Determine p based on that
out = 1/v;