2
Tutorial 1g: Recording membrane potentials
3
******************************************
5
In the previous part of this tutorial, we plotted a raster plot of
6
the firing times of the network. In this tutorial, we introduce
7
a way to record the value of the membrane potential for a neuron
8
during the simulation, and plot it. We continue as before:
12
tau = 20 * msecond # membrane time constant
13
Vt = -50 * mvolt # spike threshold
14
Vr = -60 * mvolt # reset value
15
El = -49 * mvolt # resting potential (same as the reset)
16
psp = 0.5 * mvolt # postsynaptic potential size
18
G = NeuronGroup(N=40, model='dV/dt = -(V-El)/tau : volt',
19
threshold=Vt, reset=Vr)
22
C.connect_random(sparseness=0.1, weight=psp)
24
This time we won't record the spikes.
29
Now we introduce a second type of monitor, the :class:`StateMonitor`.
30
The first argument is the group to monitor, and the second is
31
the state variable to monitor. The keyword ``record`` can be
32
an integer, list or the value ``True``. If it is an integer ``i``,
33
the monitor will record the state of the variable for neuron ``i``.
34
If it's a list of integers, it will record the states for
35
each neuron in the list. If it's set to ``True`` it will record
36
for all the neurons in the group.
38
M = StateMonitor(G, 'V', record=0)
40
And then we continue as before:
42
G.V = Vr + rand(40) * (Vt - Vr)
44
But this time we run it for a shorter time so we can look at
45
the output in more detail:
49
Having run the simulation, we plot the results using the
50
``plot`` command from PyLab which has the same syntax as the Matlab
51
:class:`plot`` command, i.e. ``plot(xvals,yvals,...)``. The :class:`StateMonitor`
52
monitors the times at which it monitored a value in the
53
array ``M.times``, and the values in the array ``M[0]``. The notation
54
``M[i]`` means the array of values of the monitored state
55
variable for neuron ``i``.
57
In the following lines, we scale the times so that they're
58
measured in ms and the values so that they're measured in
59
mV. We also label the plot using PyLab's ``xlabel``, ``ylabel`` and
60
``title`` functions, which again mimic the Matlab equivalents.
62
plot(M.times / ms, M[0] / mV)
63
xlabel('Time (in ms)')
64
ylabel('Membrane potential (in mV)')
65
title('Membrane potential for neuron 0')
68
.. image:: images/tutorials/1g.jpg
70
You can clearly see the leaky integration exponential decay
71
toward the resting potential, as well as the jumps when a