Integrate and fire


This tutorial describes how to simulate an integrate-and-fire neuron in Matlab.

The leaky integrate-and-fire model


The leaky integrate and fire model is a simple description of a neuron. Real neurons have a membrane and several families of ion channels that control the flow of current across the membrane, which in turn modulates the membrane potential in complex ways, including the firing of action potentials. Further, real neurons have considerable spatial structure, and different areas of the cell could in principle behave differently.

The leaky integrate-and-fire model incorporates only 4 simple features:

  1. The entire cell has a single voltage (let's call it Vm)

  2. It has a membrane with a capacitance (let's call it Cm)

  3. It has a leak channel that allows current to flow across the membrane with resistance Rm (or, inversely, conductance Gm = 1/Rm). The charge carriers traveling across this membrane are driven by a force voltage of V_e.

  4. Action potentials are simulated when the voltage in the cell exceeds some threshold value Vth. When a spike occurs, the voltage is artificially dropped to a value Vreset, which simulates the refractory period between action potentials in real neurons. (There are other variants of this spike-generating behavior; one can actually impose a refractory period, for example, or employ some equation that operates on the voltage.)

Very simple drawing of a leaky integrate-and-fire neuron.


The equation that describes how the voltage of the cell Vm changes over time in the face of an externally-applied membrane current Im is as follows:

(equation 1a)

Multiplying by the membrane resistance Rm, and defining the time constant Tau_m = Cm * Rm, the function is a bit easier to read:

(equation 1b)

or even easier:

(equation 1c)

So Ve, tau_m, and Rm, Vth, and Vreset are taken to be intrinsic properties of the cell, and Im is the external current that can vary depending upon experimenter input or synaptic input, and Vm is the membrane potential which varies indirectly according to the equation above.

Numerical simulations of the equation

We can use the Euler method to simulate the behavior of the equation for discrete steps in time (see Numerical Recipes, Press et al.). Thanks to Paul Miller for reference and equations.

Suppose our time step is ∆t. Since


So the overall behavior of the model is as follows:

If Vm(t) > V_th,

Vm(t+1) = V_reset;


Vm(t+1) = Vm(t) + dt * ( -(Vm(t) - Ve) + Im * Rm) / tau_m


Simulating a leaky integrate-and-fire model in Matlab

Let's try this in Matlab with

V_reset = -0.080; % -80mV

V_e = -0.075; % -75mV

V_th = -0.040; % -40mV

Rm = 10e6; % membrane resistance

tau_m = 10e-3; % membrane time constant

Can you write a function that simulates a current injection of 5nA for 1 seconds? Use a dt of 0.0002 seconds.

Here it is:

integrate and fire script

V_reset = -0.080; % -80mV

V_e = -0.075; % -75mV

V_th = -0.040; % -40mV

Rm = 10e6; % membrane resistance

tau_m = 10e-3; % membrane time constant

dt = 0.0002;

T = 0:dt:1; % 1 second simulation

Vm(1) = V_reset;

Im = 5e-9;

for t=1:length(T)-1,

if Vm(t) > V_th,

Vm(t+1) = V_reset;


Vm(t+1) = Vm(t) + dt * ( -(Vm(t) - V_e) + Im * Rm) / tau_m;





ylabel('Voltage (V)');