% gtrain.m
% Principles of Computational Modelling in Neuroscience
% Sterratt, Graham, Gillies, Willshaw
% Cambridge University Press, June 2011
% Fig. 7.3: Synaptic conductance waveforms responding to trains of APs
% B. Graham, Computing Science & Maths, University of Stirling
% Contact: b.graham@cs.stir.ac.uk
% Last update: 1-7-2011

tmax=100;
dt=0.1;
t=0:dt:tmax;
sp=zeros(1,length(t));
for i=1:5
    sp(i*20/dt)=1;  % 50Hz
end
tau=10;

% Approx 1
% (as used by Graham & Redman, 1994 for force in a muscle fibre)
g1=zeros(1,length(t));
fdt=1-(dt/tau);
for i=3:length(t)
  g1(i) = (2*fdt*g1(i-1)) - ((fdt^2)*g1(i-2)) + (((dt/tau)^2)*sp(i-2));
end;

% Approx 2
% (as used by Wilson & Bower, 1989 in GENESIS)
z=zeros(1,length(t));
g2=zeros(1,length(t));
fdt=exp(-dt/tau);
for i=2:length(t)
  z(i) = (z(i-1)*fdt) + (tau*(1-fdt)/dt)*sp(i-1);
  g2(i) = (g2(i-1)*fdt) + (z(i-1)*tau*(1-fdt));
end;

tsize=12;
lsize=9;
nsize=9;

plot(t,g1./max(g1),'k-');
xlabel('t (msecs)','FontSize',lsize,'FontName','Helvetica');
ylabel('Conductance','FontSize',lsize,'FontName','Helvetica');
axis([0 tmax 0 1.02]);

set(gca,'Box','off');
set(findobj('Type','line'),'LineWidth',0.8);
set(findobj('Type','text'),'FontSize',nsize,'FontName','Helvetica');

