\documentclass[a4paper,12pt,pdftex]{exam}

\newcommand{\ptitle}{Integrate-and-fire neuron}
\input{../header.tex}
\firstpagefooter{Supervisor: Jan Benda}{}{email: jan.benda@uni-tuebingen.de}

\begin{document}

\input{../instructions.tex}

The leaky integrate-and-fire model is a simple but powerful model of
spiking neurons. It adds to the dynamics of a passive membrane a
voltage threshold to simulate the generation of action potentials. In
this project you learn how to simulate such a model and explore some
of its stimulus encoding properties.

The temporal evolution of the membrane voltage $V(t)$ of a passive
neuron is described by the membrane equation
\begin{equation}
  \label{passivemembrane}
  \tau \frac{dV}{dt} = -V + E
\end{equation}
where $\tau=10$\,ms is the membrane time constant and $E(t)$ is the
reversal potential that also depends on time $t$.

Such a differential equation can be numerically solved with the Euler
method.  For this the time is discretized by a time step $\Delta
t=0.1$\,ms.  The $i$-th time point is then at time $t_i = i \cdot
\Delta t$.  In matlab we get the time points $t_i$ simply by
\begin{lstlisting}
dt = 0.1;
tmax = 100.0;
time = [0.0:dt:tmax]; % t_i
\end{lstlisting}
When the membrane potential at time $t_0 = 0$ is $V_0$, the so called
``initial condition'', then we can iteratively compute the membrane
potentials $V_i$ for successive time points $t_i$ according to
\begin{equation}
  \label{euler}
  V_{i+1} = V_i + (-V_i + E_i) \frac{\Delta t}{\tau}
\end{equation}

\begin{questions}
  \question Passive membrane
  \begin{parts}
    \part Write a function that computes the time course of the
    membrane potential of the passive membrane. The function gets as
    input arguments the initial condition $V_0$, the vector with the
    time course of $E(t)$, the value of the membrane time-constant
    $\tau$, and the time step $\Delta t$.

    \part In order to test your function set $V_0=1$\,mV and $E(t)=0$
    and compute $V(t)$ for $t_{max}=50$\,ms. Plot $V(t)$ and compare it to 
    the expected result of $V(t) = \exp(-t/\tau)$.

    Vary the time step $\Delta t$ by factors of 10 and discuss the
    accuracy of the numerical solutions. What is a good time step?
    Why is $V=0$ the resting potential of this neuron?

    \part Response of the passive membrane to a step input. 

    Set $V_0=0$. Construct a vector for the input $E(t)$ such that
    $E(t)=0$ for $t\le 20$\,ms or $t\ge 70$\,ms, and $E(t)=10$\,mV for
    $20$\,ms $<t<70$\,ms. Plot $E(t)$ and the resulting $V(t)$ for
    $t_{max}=120$\,ms.

    \part Response to sine waves.

    As an input we now use $E(t)=\sin(2\pi f t)$. Compute the time
    course of the membrane potential in response to this input
    ($t_{max}=1$\,s). Vary the frequency $f$ between 1 and 100\,Hz.
    Be careful with the units within the sine function --- $f \cdot t$
    must be unitless.

    What do you observe?

    \part Filter function of the passive neuron.

    Measure the amplitude of the voltage responses evoked by the
    sinusoidal inputs as the maximum of the last 900\,ms of the
    responses.  Plot the amplitude of the response as a function of
    input frequency. This is the filter function of the passive
    neuron.

    How does the filter function depend on the membrane time constant?
  \end{parts}

  \question Leaky integrate-and-fire neuron

  The passive neuron can be turned into a spiking neuron by
  introducing a fixed voltage threshold. Whenever the computed
  membrane potential of the passive neuron crosses the voltage
  threshold a spike is generated and the membrane voltage is set to
  the reset potential $V_R$ that we here set to zero. ``Generating a
  spike'' only means that we note down the time of the threshold
  crossing as a time where an action potential occurred. The waveform
  of the action potential is not modeled. Here we use a voltage
  threshold of 1\,mV.

  \begin{parts}
    \part 
    Write a function that implements this leaky integrate-and-fire
    neuron by expanding the function for the passive neuron
    appropriately. The function returns a vector of spike times.

    Illustrate how this model works by appropriate plot(s) and
    input(s) $E(t)$, e.g. constant inputs lower and higher than the
    voltage threshold.

    \part Show the response of the leaky integrate-and-fire neuron to
    a sine wave $E(t)=A\sin(2\pi ft)$ with $A=2$\,mV and frequency
    $f=10$, 20, and 30\,Hz.

    \part Compute the firing rate (number of spikes per time) as a
    function of the frequency of the stimulating sine wave ($A=2$\,mV
    and frequencies between 5 and 30\,Hz).
    
    What do you observe? Does the firing rate encode the frequency of
    the stimulus? Look at the spike trains in response to the sine
    waves to figure out what is going on.
  \end{parts}

\end{questions}

\end{document}
