%% Simulation of (leaky) integrate-and-fire neuron
% Taken from Trappenberg: Fundamentals of Computational Neuroscience
% 
% Materials for Neuroscience (course a6m33nin) at dept. of Cybernetics, 
% Faculty of Electrical Engineering, CTU Prague, 2012
% Adapted by Eduard Bakstein, eduard.bakstein@fel.cvut.cz
 
clear; clf;

%% parameters of the model
 dt=0.1;       % integration time step [ms]
 tau=10;       % time constant [ms]
 E_L=-65;      % resting potential [mV]
 theta=-55;    % firing threshold [mV]
 RI_ext=12;     % constant external input [mA/Ohm]
 
%% Integration with Euler method
 t_step=0; v=E_L;
 for t=0:dt:500;
     t_step=t_step+1;
     s=v>theta;
     v=s*E_L+(1-s)*(v-dt/tau*((v-E_L)-RI_ext));
     v_rec(t_step)=v;
     t_rec(t_step)=t;
     s_rec(t_step)=s;
 end
 

