The brain talks in voltage blips, each about one millisecond wide. Drive a model neuron with current, watch four gates open and close, and see why every spike comes out the same size.
Build the Hodgkin-Huxley neuron from zero: a membrane, three kinds of ion channel, four gates, and the one equation that ties them together. This is the signal every brain-computer interface records.
Set a current and press Fire. Try a weak pulse, then a strong one, then switch to Hold and keep the current on. Then we build, piece by piece, what happens inside the cell to make that trace.
You need a feel for a slope (how fast a number changes) and a little Python for the code. We build the electricity from zero.
Lesson 1 of the Brain-Computer Interfaces series. Sources: Hodgkin and Huxley, “A quantitative description of membrane current…” (J Physiol, 1952), and the opening chapter of Rieke, Warland, de Ruyter van Steveninck and Bialek, Spikes, the first reading of Princeton NEU 560 (Jonathan Pillow), spikes_intro.pdf. Everything is re-taught here in our own words and devices.
Current in microamps per square centimetre (µA/cm²). The model is the 1952 squid giant axon of Hodgkin and Huxley at 6.3 °C, with the resting voltage drawn at −65 mV, solved live in your browser. Pulses start at 5 ms.
Chapter 0
See why a lone wire near one neuron hears the same tiny pulse again and again, and why that one fact shapes every brain-computer interface
Picture an electrode thinner than a hair, resting next to one nerve cell in a monkey’s motor cortex. The monkey reaches for a cup. On the screen, a noisy line wanders along, and now and then it jumps: a sharp pulse, about a thousandth of a second wide. The pulses come faster when the arm moves left, and slower when it moves right.
Those pulses are the whole message. A decoder in a brain-computer interface (a BCI, a device that reads brain activity and turns it into commands) has no other raw material from this cell. Every cursor move and every typed letter starts as a list of times at which a pulse happened.
The pulse has a name: the action potential, or spike. It is a brief swing in the voltage across the cell’s skin, which is called its membrane. The opening chapter of the Princeton NEU 560 reading says it plainly: when we see, we do not read the light on the retina but the pattern of spikes in the optic nerve, and when we act, the brain sends spikes to the muscles. Spikes are the language the brain speaks to itself.
In 1926 the physiologist E. D. Adrian recorded from single nerve fibres, and he found three facts that still hold. We will test each one with a model you can drive.
First, the all-or-none law: a stimulus either makes a spike or it does not, and every spike looks the same. A stronger push does not make a bigger spike. So a neuron can tell the brain something only through when its spikes arrive.
Second, rate coding: a stronger stimulus makes more spikes per second. The neuron says “louder” by talking faster, not by shouting. Third, adaptation: if the stimulus stays on, the rate slowly falls. Our model will show the first two clearly. The third is a useful surprise, and Chapter 8 returns to it.
Try the first two now. The device below holds a steady current on a model neuron for 100 milliseconds. Pick a strength and compare the spikes.
Each button holds a different current on the same model cell. Look at the height of the spikes, then count them.
Buttons are the held current in µA/cm². The model is Hodgkin and Huxley’s 1952 squid axon at 6.3 °C, simulated live. A real cortical cell is different in detail; the all-or-none shape and the rate code are not.
The tallest spike and the shortest are almost the same height. What grew was the count. That is the deal a recording electrode is offered: a binary event, many times a second, at times the cell chooses.
Here is how an electrode turns these pulses into something a program can use. Say the line jumps at 12, 31, 52, 70 and 91 milliseconds, in a window of 100 milliseconds. That is five spikes. Five spikes in a tenth of a second is a firing rate of 50 spikes per second. These times are illustrative, not a recording.
Now suppose the monkey reaches left and the same cell jumps at 8, 22, 35, 49, 62, 75 and 88 milliseconds. That is seven spikes, a rate of 70 per second. The pulses look identical in both windows. Only the count differs. A decoder that sees 70 where it usually sees 50 can guess the arm moved left. It has no other clue from this cell.
This is why the lesson builds a neuron instead of just describing one. If you know what makes a spike, you know what the electrode can and cannot tell you: when the cell fired, and nothing about how hard it was pushed at that moment, except through how often it fires. The failure mode is trusting one short window. With only 100 milliseconds a cell that fires 50 times a second can easily give four spikes one time and six the next, so a single count is a noisy vote, and Chapter 8 returns to this.
Adrian told us what a spike is. In 1952 Alan Hodgkin and Andrew Huxley explained why, with four equations fitted to measurements on the giant axon of a squid. Their model needs no biology beyond electricity: a battery, a capacitor, and some doors that open and close with voltage. We build it in that order. The last chapters turn the model into the numbers a decoder sees.
Chapter 1
Learn why a quiet cell holds a voltage of about −65 mV, and compute the pull that each kind of ion exerts
Drop a nerve cell into salt water and it behaves like a tiny charged battery. Between the inside of the cell and the water outside, there is a steady voltage. A neuron at rest sits near −65 mV, with the inside more negative than the outside. A millivolt (mV) is a thousandth of a volt, so this is about a twentieth of the voltage of a single AA cell.
Where does that voltage come from? Not from magic: from salt. The water inside and outside the cell holds the same ions (atoms with an electric charge) in very different amounts. The two that matter most are sodium (Na+) and potassium (K+). Outside the cell there is a lot of sodium. Inside there is a lot of potassium.
The cell’s skin, the membrane, is a thin layer of fat. Charged ions cannot pass through fat, so the membrane acts as a wall. But the wall has doors: protein tubes called ion channels. Each kind of channel lets one kind of ion through. A potassium channel passes K+ and almost nothing else.
Now open only the potassium doors. Potassium is crowded inside and sparse outside. Like people leaving a packed room, the ions drift out, down their concentration gradient (the difference in amount from one side to the other). This drift is called diffusion.
Each K+ that leaves carries a positive charge with it. The outside becomes slightly positive and the inside slightly negative. That voltage pulls the next ion back in. It is a brake. The drift slows, then stops, when the electric pull back exactly equals the diffusion push out. The voltage at that balance point is the equilibrium potential of the ion, also called its reversal potential. Only a tiny fraction of the cell’s potassium needs to cross, so the concentrations hardly change.
Walther Nernst worked out the balance point. Thermal motion pushes ions across, and the electric field pulls them back. The result is one line:
Work one by hand. Take the squid axon at 6.3 °C, with illustrative textbook-order concentrations: potassium 20 mM outside, 400 mM inside. The ratio is 20 / 400 = 0.05. The natural log of 0.05 is −3.00. Multiply by 24.1 mV and you get EK ≈ −72 mV. For sodium, with 440 mM outside and 50 mM inside, the ratio is 8.8, its log is 2.17, and ENa ≈ +52 mV.
24.1 mV × ln(20 / 400) = 24.1 × (−3.00) = −72 mV (potassium, illustrative)
Hodgkin and Huxley fitted their own values to the measurements: EK = −77 mV and ENa = +50 mV, drawn as yellow dashes in the device and on the hero. Our hand numbers land within a few millivolts. Try your own concentrations.
The dots show how crowded each side is. Pick an ion, drag the two concentrations, and watch the marker on the voltage scale. Try making both sides equal.
Concentrations in mM. The squid starting values (K 20 out and 400 in, Na 440 out and 50 in) are textbook-order and illustrative. The yellow dashes are Hodgkin and Huxley’s fitted ENa = +50 mV and EK = −77 mV. Dot counts are scaled for the picture.
Look at what the device shows when the two sides match. The log of 1 is zero, so E is 0 mV: no pull in either direction. The battery is flat. A cell cannot rest on a flat battery, and it cannot fire either. This is the failure mode of the whole mechanism. Left alone, leaking channels would run the gradients down. So every cell runs pumps, proteins that burn energy to push Na+ out and K+ in, and keep the batteries charged. A spike spends a little charge. The pump pays it back over the next seconds.
One more check: a neuron at rest is not at EK and not at ENa. It sits at −65 mV, between the two batteries and closer to potassium. Which battery wins depends on how wide each door is open. That is the next chapter.
Notice what the equation hides. It says nothing about how fast the balance is reached, or how many channels the cell has. It gives only the endpoint. A cell with ten potassium doors and a cell with ten thousand reach the same EK; the second one simply gets there sooner. So the next chapters ask two separate questions. Where does each ion pull the voltage? That is its battery. And how hard does it pull? That is its conductance.
Mind the sign too. Voltage here is always the inside minus the outside. A negative EK means that, at balance, the inside is the negative side. That is why a quiet cell reads a negative number.
Chapter 2
Treat each kind of channel as a wire to its own battery, and see how the cell’s voltage settles in a tug of war
Chapter 1 gave each ion a battery: sodium wants the inside at +50 mV, potassium wants it at −77 mV. A cell has both kinds of door in its wall at once. If sodium doors were wide open, the voltage would be dragged toward +50. If potassium doors were wide open, it would be dragged toward −77. So what voltage does the cell actually take?
Think of a tug of war with three teams. Each team pulls the voltage toward its own battery. The strength of a team is how many doors it has open. The voltage settles where the pulls cancel. To do this with numbers, we need a measure of how open the doors are.
Electricians describe a wire by its conductance, written g. A big g means current flows easily. It is the inverse of resistance. For a patch of membrane, Hodgkin and Huxley measure g in millisiemens per square centimetre (mS/cm²). A wide-open door has a big g. A shut door has a g near zero.
The current through one kind of channel follows Ohm’s law, with a twist. The push on the ions is not the voltage V itself but the distance of V from that ion’s battery. This gap is the driving force.
Hodgkin and Huxley split the membrane current into three parts. A sodium current through Na+ channels, a potassium current through K+ channels, and a leak current that lumps together everything else (mostly chloride and other leaking ions). Their fitted batteries are ENa = +50 mV, EK = −77 mV and EL = −54.4 mV. The leak conductance is a fixed gL = 0.3 mS/cm².
At rest the model has gNa = 0.0106 and gK = 0.367 mS/cm². (Chapter 4 shows where these come from.) Put V = −65 mV into the law for each ion.
IK = 0.367 × (−65 + 77) = +4.40 INa = 0.0106 × (−65 − 50) = −1.22 IL = 0.3 × (−65 + 54.4) = −3.18
Potassium pushes 4.40 outward. Sodium and the leak pull 1.22 + 3.18 = 4.40 inward. The sum is zero, so the voltage does not move. That is what “rest” means: not that nothing flows, but that the flows cancel. Rest is a steady tug of war, with pumps quietly refilling the batteries.
Setting the total current to zero gives a clean formula for the settled voltage. Write gi(V − Ei) for each team, add them, and solve for V.
Vsettled = ( gNaENa + gKEK + gLEL ) / ( gNa + gK + gL )
It is a weighted average of the batteries, where each weight is how open that team’s doors are. A team with twice the conductance has twice the vote. Play with it below.
The yellow ticks are the three batteries. The warm dot is where the voltage settles. Drag the two door sliders, or pick a preset. The leak stays at 0.3.
Sliders are logarithmic (each step multiplies the conductance) and give mS/cm². Batteries and gL are Hodgkin and Huxley’s 1952 fitted constants; the presets are illustrative points on the sliders.
Slide sodium up until it dwarfs the others. The voltage races to +50 mV and stops there, because at +50 the sodium driving force vanishes. Slide potassium up instead and the voltage sinks to −77 mV. Neither battery can pull the voltage past its own value. A spike lives between those two walls.
Now the key question. At rest the sodium team is almost asleep, with 0.0106 against potassium’s 0.367. A spike needs the sodium team to wake up, fast, and then be put back to sleep. Who controls the doors? The voltage itself. That feedback is the whole trick of the next two chapters, and it is what makes a neuron more than a leaky battery.
One more consequence of the law deserves a look. The current changes sign when V crosses E. If V sits above EK, say at −60 mV, potassium flows out. If V is pushed below EK, say to −80 mV, the driving force flips and potassium flows in. This is why E is also called the reversal potential: it is the voltage at which the current reverses. The same flip will matter at the end of the spike, when the voltage dips close to EK and the potassium current fades.
Chapter 3
Write the one equation that says how current changes voltage, and see why a cell with fixed doors can never make a spike
You turn on a tap over a bucket. The water level rises. Drill a hole in the side and the level rises more slowly, then settles where inflow equals outflow. A nerve cell works the same way, with charge in place of water and voltage in place of level.
The membrane is a thin insulator with conductors on both sides: salt water inside and salt water outside. An insulator between two conductors is a capacitor, a device that stores charge. The more charge Q sits on its two faces, the bigger the voltage across it. Hodgkin and Huxley measured the membrane’s capacitance, C, at about 1 microfarad per square centimetre, and every membrane since has come out close to that.
A capacitor obeys Q = C · V. Current is charge per second, so current is the slope of Q. Divide by C and you get the slope of V. A current I into the bucket makes the voltage rise at the rate I / C.
Add the holes. Each ion current from Chapter 2 drains the bucket. Any current you inject through an electrode fills it. Put together, this is the equation of the whole lesson:
Units check: (µF/cm²) × (mV/ms) = µA/cm². Every term is a current per area, so the equation is consistent. This is the “current clamp” experiment: you choose Iext and record V.
First, freeze every door at its resting width. Then gNa, gK and gL are fixed numbers, and the three currents add up to one total conductance times the distance from rest:
gtot = 0.0106 + 0.3668 + 0.3 = 0.677 mS/cm² C dV/dt = Iext − gtot (V − Vrest)
This is the leaky bucket. Its answer is an exponential climb. Hold a steady current Iext and the voltage rises toward a final value and stops:
Vfinal = Vrest + Iext / gtot τ = C / gtot = 1 / 0.677 = 1.48 ms
The time constant τ says how fast. After one τ the voltage has covered 63% of the way to its final value. After three τ it has covered 95%. Worked example: inject 8 µA/cm². Then Vfinal = −65 + 8 / 0.677 = −65 + 11.8 = −53.2 mV. After 1.48 ms the voltage is at −65 + 0.63 × 11.8 = −57.6 mV.
Grey: the cell with doors frozen at rest. Warm: the full model. Both get the same 25 ms current step. Raise the current, then change the capacitance.
Current in µA/cm², capacitance in µF/cm² (1.0 is Hodgkin and Huxley’s measured value; 0.5 and 2.0 are illustrative). The grey curve is the exact exponential above; the warm curve is the full model.
Play with the grey trace first. It is smooth and predictable. It climbs, it plateaus, and when the current stops it sinks back with the same time constant. Double C and the climb takes twice as long. A passive cell is a low-pass filter: it smooths away fast changes. That is why a signal sent through a passive wire fades and blurs.
Now the failure mode. Raise the current to 8. The grey trace levels at −53 mV and just sits there. A neuron built from frozen doors would never send a crisp pulse; it would only smear its input. The measurement is the warm trace: at the same current the real cell shoots to +40 mV. The difference is that the real doors are not frozen. They move with the voltage. That is the next chapter.
For the code: the equation above is a single line of Euler stepping. Pick a small step dt, then repeat: compute the slope, move the voltage by slope times dt.
python C, g_tot, V_rest, dt = 1.0, 0.677, -65.0, 0.02 # uF/cm2, mS/cm2, mV, ms V = V_rest for k in range(int(40 / dt)): t = k * dt I_ext = 8.0 if 5 <= t < 30 else 0.0 # the current clamp V += dt * (I_ext - g_tot * (V - V_rest)) / C # input shape: scalars; output: one voltage per step
Why is C given per square centimetre? Because the membrane is the same thin film everywhere. A bigger cell has more membrane and so more total capacitance, but also more channels, more leak and more injected current per cell. Dividing everything by area makes the cell’s size cancel, so one set of numbers describes a patch of any cell. The thin film is only a few nanometres across, which is why it stores so much charge for its area.
Chapter 4
Let the voltage open and close the doors, and read off how fast sodium wakes and how slowly it is put back to sleep
In Chapter 2 we left the doors alone, and Chapter 3 showed that a cell with fixed doors only smooths its input. The real cell has doors that react to the voltage. Depolarise the cell (make the inside less negative) and sodium doors swing open. That is a feedback loop: sodium entering depolarises the cell more, which opens more sodium doors.
Hodgkin and Huxley could not see a single channel in 1952. They measured the total current and worked out a mechanism that fitted it. To measure it, they needed to cut the loop. The trick is the voltage clamp: an electronic circuit that holds the voltage at a value you choose, whatever the cell does. With V frozen, the loop is broken, and the current you must supply shows how the doors respond to that one voltage.
Their finding was that the doors behave as if each has a few independent latches, called gates, and the door passes current only when every latch is open. A potassium door has four identical latches, each open with probability n. All four open with probability n×n×n×n. A sodium door has three identical fast latches (m) and one slow extra latch (h). The conductances are:
Later work found that potassium channels are built from four matching subunits, which fits the n4 picture. But the model stands on its fit to the data, not on the later biology.
Each gate variable x (that is m, h or n) obeys a simple rule: latches open at a rate α, closed ones fall shut at a rate β, and both rates depend on the voltage.
dx/dt = α(V) · (1 − x) − β(V) · x
Hold V steady and x slides to a fixed target, x∞ = α / (α + β), with time constant τx = 1 / (α + β). Work the three gates at rest, where u = V − Vrest = 0 mV. The 1952 rate functions give:
n: α = 0.0582, β = 0.125 → n∞ = 0.318, τ = 5.46 ms
m: α = 0.2236, β = 4.0 → m∞ = 0.0529, τ = 0.237 ms
h: α = 0.07, β = 0.0474 → h∞ = 0.596, τ = 8.52 ms
Now check the conductances Chapter 2 used. gK = 36 × 0.3184 = 0.367. gNa = 120 × 0.05293 × 0.596 = 0.0106. They match. The resting conductances are not extra constants: they fall out of the gates at rest.
Read the time constants side by side. The m gate has τ = 0.24 ms, more than twenty times faster than h (8.5 ms) or n (5.5 ms). When the cell depolarises, sodium wakes fast. The two slow gates, h closing and n opening, then arrive a few milliseconds later and shut sodium and open potassium. Speed differences, not new ingredients, make the spike. Run the clamp below and watch them.
The voltage sits at −65 mV, then jumps to the value you choose at 5 ms. Top: the three gates. Bottom: the two conductances they build. Try −20, then +20.
Computed live from the 1952 rate functions with the membrane voltage held fixed. Gates start at their resting values (m 0.053, h 0.596, n 0.318). Conductances in mS/cm².
Step to −20 mV. The m gate (purple) leaps up within about a millisecond, so sodium conductance surges to a peak near 18 mS/cm². A moment later the h gate (pink) sinks and sodium shuts again, even though the voltage never changed. This is inactivation. Meanwhile n (blue) creeps up and potassium conductance keeps climbing and stays up. Sodium is a short burst. Potassium is a long push.
Step to a small value like −60 and almost nothing happens: the sodium conductance peaks at 0.06 mS/cm², tiny next to the 18 you see at −20 mV. Step to +40 and the conductance is larger still, but the sodium current is small, because V is then close to the +50 mV battery and the driving force is gone. Both edges matter in the next chapters.
One implementation trap, the failure mode of this chapter. The rate functions αn and αm have the form x / (ex/y − 1). At the exact voltage where x is zero, that is 0 / 0, and a program gives a not-a-number error value for every number after. The measurement is a trace that goes blank at one step. The fix is the limit: x / (ex/y − 1) tends to y when x tends to zero, so a small-x series replaces the formula.
Chapter 5
Put the capacitor, the three currents and the three gates together, and step through one spike to see which current does what
Now we have every part. The membrane equation from Chapter 3 gives the slope of V. Three currents from Chapter 2 feed it. Three gates from Chapter 4 set two of those currents. The gates, in turn, listen to V. Four numbers change together: V, m, h and n. That is the Hodgkin-Huxley model, four coupled equations, and it fits on a postcard:
Nobody can solve these by hand. A computer can step them forward: at each tiny time step of 0.02 ms, compute the three currents from the present V and gates, nudge V by its slope, nudge each gate by its slope, repeat. This is what runs under every device on this page. Each step takes four numbers in and gives four numbers out.
Give the cell a 2 ms pulse of 8 µA/cm², enough to fire it. The pulse itself is small. The numbers below show how tiny it is next to what the cell does with it.
Phase 1, charging (5 to 6.5 ms). Current charges the capacitor, as in Chapter 3. V climbs from −65 to −53 mV. The gates barely move: m goes from 0.05 to 0.14. Sodium current is a feeble −19 µA/cm².
Phase 2, the upstroke (6.5 to 7.5 ms). Now the feedback starts. A little sodium enters, which raises V, which raises m, which lets more sodium in. This is positive feedback. In one millisecond m goes from 0.14 to 0.94. V rises at up to about 300 mV per ms and leaps from −53 to +40 mV, close to ENa. The sodium current peaks near −790 µA/cm², almost 100 times bigger than the 8 you injected. The cell does the work. Your pulse only pulls the trigger.
Phase 3, the fall (7.5 to 9.5 ms). Two slow gates now arrive. The h gate drops from 0.32 to 0.08, which locks the sodium doors shut. The n gate climbs from 0.53 to 0.76, which opens the potassium doors wide. Potassium current hits about +830 µA/cm² outward and drags V back down. This is negative feedback: the spike builds the things that end it.
Phase 4, undershoot and recovery (after 9.5 ms). V dips to −76.2 mV at 10.2 ms, almost at EK, because potassium is still open. Then n relaxes with a time constant of about 5 ms and h creeps back toward 0.6 with a time constant of about 8.5 ms. During this recovery the cell is hard or impossible to fire again. Chapter 6 measures it.
Drag the cursor through the spike below, or press Play for slow motion. Watch the three bars on the left (which current is strong) and the three gate bars on the right.
Top: voltage. Bottom left: sodium (purple, inward), potassium (blue, outward) and leak. Bottom right: gates m, h and n. Press Play, or drag the time.
The 2 ms, 8 µA/cm² pulse starts at 5 ms. Computed live with the 1952 constants at 6.3 °C. Currents are in µA/cm²; the bars share one scale so you can compare them.
Stop at 8.5 ms. The sodium bar and the potassium bar are almost equal and opposite: −768 against +803. Yet V is falling quickly. Why? The leak and the capacitor take up the small difference. A tiny imbalance of two huge currents moves a voltage fast. That is a feature of every real neuron: the spike is made of large flows that nearly cancel.
The failure mode of this chapter shows if you break the loop. In a real lab, a drug called tetrodotoxin blocks sodium doors; the cell then has no upstroke, however hard you drive it. In our model, set gNa to zero and the same pulse gives only Chapter 3’s smooth bump. If instead you block potassium, the spike falls only as h closes, and it stays wide. Each gate has one job.
One practical warning, and the failure mode of the solver itself. Euler stepping needs a small step. Run the same 8 µA/cm² pulse with steps of 0.01, 0.02 and 0.05 ms and the peak reads +39.9, +40.1 and +40.7 mV: a slow drift in the answer. Take 0.1 ms and the numbers blow up and the program returns not-a-number. The symptom is a trace that goes blank mid-spike. The measurement is to halve the step and see if the answer moves. The fix is a smaller step or a better integrator, such as a Runge-Kutta method.
Chapter 6
Find the cliff edge where a push becomes a spike, then measure the shadow a spike leaves behind it
Imagine a boulder on a hilltop, in a small dip. Nudge it a little and it rolls back into the dip. Nudge it past the lip and it rolls all the way down, whatever your push was. The size of the slope below has nothing to do with the size of your nudge. A neuron has the same shape, and Adrian’s all-or-none law is its name.
The lip is the threshold: the voltage, or the smallest stimulus, beyond which the sodium feedback of Chapter 5 takes over. Below it, the leak and the potassium doors win and V falls back. Above it, sodium wins and V runs away to near +40 mV.
Use short pulses of one millisecond and raise the amplitude step by step. This is what our solver gives for the peak voltage:
6.8 µA/cm² → peak −57.9 mV 6.9 → peak +30.5 mV 8.0 → peak +38.4 mV
A change of 0.1 µA/cm², one part in seventy, moves the peak by 88 mV. After the cliff the peak barely grows: from 6.9 to 8 it gains only 8 mV, and it can never pass the sodium battery at +50. The spike is not exactly the same size every time near the edge (30 to 41 mV in our model), but it is nearly constant, and utterly unlike the smooth growth of the passive cell in Chapter 3.
The threshold depends on how long the pulse lasts. A short push needs more current. Our solver finds the smallest current that fires the cell:
1 ms pulse: 6.90 2 ms: 3.85 5 ms: 2.34 µA/cm² (charge: 6.9, 7.7 and 11.7 µA·ms/cm²)
The pattern makes sense. The capacitor must be charged to the lip. A fast, strong pulse delivers that charge before the leak drains it. A slow, weak one loses charge as it goes, so it needs more total charge. Try it yourself.
Each trace is a 1 ms pulse. The grey ones are the weaker pulses you passed on the way up. Drag past the cliff, then back, and look for the jump.
Pulse of 1 ms starting at 5 ms, in µA/cm². Grey traces step by 1.0 up to your value. The threshold is found live by bisection on the full model.
Chapter 5 ended with a loose thread: after a spike, h is low and n is high. Sodium doors are locked and potassium doors are open. Fire the cell again right now and it cannot answer, however hard you push. This is the refractory period. Until h and n relax (time constants near 8.5 and 5.5 ms), the cell needs a bigger push, and for a short time it cannot fire at all.
Measure it. Give a first pulse of 12 µA/cm² (a clear spike), then a second pulse after a gap. Ask how short the gap can be before the second pulse still makes a spike.
Choose how hard the second pulse is, then slide the gap shorter. Find where the second spike disappears.
Both pulses last 1 ms. The first is 12 µA/cm². The second is a multiple of the 1 ms threshold (6.9 µA/cm²). The shortest gap that still works is found by scanning the full model in 0.5 ms steps.
With a second pulse 3 times threshold, the gap must be at least about 11.5 ms for a second spike. A harder pulse of 6 times threshold shrinks that to 9 ms, and even a 100 µA/cm² pulse needs 7 ms. A stronger push can shorten the shadow but not remove it. This sets a speed limit on a neuron: at 6.3 °C this squid axon cannot fire much faster than about once per 7 to 10 ms after a hard push. Warmer, faster cells have shorter shadows but the same logic.
For a decoder, the shadow has a consequence. Spikes from one cell are never closer than a minimum interval, so the spike train is not a pure random scatter; Chapter 8 shows how this affects the statistics we use.
Last, the link to Adrian’s second fact. Hold a steady current and count spikes. In our model a held current below 2.3 µA/cm² gives no spike, 2.4 to 5 gives one, and from about 6.2 the cell fires repeatedly: 51 spikes per second at 6.2, 98 per second at 30 and 124 per second at 60. Stronger drive gives a faster rate. Beyond that, at 100, the voltage gets stuck high and the cell fires just once, a failure called depolarisation block. Rate coding holds over a range and breaks at its ends.
Notice that the model has two thresholds in the held-current test. The first, near 2.3 µA/cm², is the smallest steady current that makes any spike. The second, near 6.2, is where repeated firing begins. Between them the cell fires once and then sits on a raised plateau, because the voltage stays in a range where the h gate stays shut and the sodium doors cannot restart. The jump from silent to about 51 spikes per second in a single step is a signature of this model, and a reminder that a neuron’s response to drive is not a smooth ramp.
Chapter 7
See why a wire near a cell hears a sharp, tiny, upside-down echo of the spike, and set a threshold that catches it
Everything so far was measured from inside the cell, with a glass pipette poked through the membrane. That is a lab technique. A brain-computer interface cannot push a pipette into thousands of cells for years. It puts metal electrodes in the salty fluid next to the cells and listens from outside. The NEU 560 reading shows the classic version: a fine tungsten wire near one neuron, with the voltage measured against a reference electrode in the body fluids. The trace is noisy, but clear, stereotyped events stand out.
The fluid around the cell conducts, a little like salt water in a bath. Current that leaves or enters the cell through the membrane flows through that fluid, and by Ohm’s law it makes a small voltage. A wire near the membrane picks it up. The voltage depends on the membrane current, not on the membrane voltage. During the upstroke, sodium current flows into the cell. From outside, that looks like a current sink, and the nearby fluid goes negative. During the fall, current flows out, and the signal swings slightly positive.
A simple picture is that the outside signal looks like the slope of the inside one, turned upside down: Voutside ≈ −k · dV/dt. The inside spike is up and then down; the outside one is a sharp downward needle with a small upward bump after it. It is also very small. Instead of 100 mV across the membrane, an electrode records microvolts. The signal also fades quickly with distance from the cell, so each wire hears only the few cells nearest it.
Two things make this the central practical problem of the field. The signal is small. And everything else the electrode hears is also in the trace: thermal noise in the wire and electronics, and the far-off activity of thousands of other cells blending into hiss. A BCI chip must decide, thousands of times a second, whether a given dip is a spike.
The simplest detector asks whether the voltage went below a line. Choose the line too close to zero and the noise crosses it by chance: false alarms. Choose it too far away and small spikes pass under it unseen: misses. The line should be set relative to the noise.
How big is the noise? Measure its standard deviation, written σ. But spikes inflate the standard deviation of the raw trace. A robust estimate ignores them: take the median of the absolute values and divide by 0.6745. For pure Gaussian noise, half of all samples lie within 0.6745 σ of zero, so this recovers σ. Spikes are rare and large, and the median hardly notices them. This estimator is used in the spike-detection and sorting pipeline of Quian Quiroga, Nadasdy and Ben-Shaul (2004), with a threshold of a few σ (4 to 5 are common choices).
Worked example. Suppose the noise has σ = 20 µV and a typical spike dips to −100 µV, which is 5σ. For Gaussian noise, a sample falls below −2σ with probability 2.3%. At 20,000 samples per second that is about 455 false crossings every second, far more than real spikes. At −4σ the chance drops to 0.0032%, about 0.6 false crossings per second. At −5σ it is 0.00003%, or 0.006 per second, but a spike that dips only to −80 µV would now be missed. Try the trade yourself.
Warm ticks under the trace mark the true spikes. Green rings are spikes your threshold caught. Red marks are false alarms. Move the line, then raise the noise.
Illustrative: spikes are the model’s own voltage turned into −dV/dt and scaled to the size you choose, added to seeded Gaussian noise at 20 kHz over 150 ms, with 6 true spikes. Sizes in µV are toy values, not a recording. The estimate σ̂ uses the median rule above.
Find the sweet spot: with noise 20 and size 100, k near 4.5 catches every spike and makes no false alarms. Lower k to 2 and the trace fills with red. Raise k to 7 and the line drops to −140 µV and the spikes slip over it. Now raise the noise to 40 µV: the same spikes are only 2.5σ deep, and no setting of k is clean. This is what low signal-to-noise means. Better electrodes, closer cells, or smarter detectors help; a threshold alone cannot.
The data flow is worth stating. The electrode gives a float array of shape (samples, channels), say 20,000 samples per second for each channel. Detection turns each channel into a short list of integers, the sample index of each crossing. A raw trace becomes a few dozen numbers a second. This is a compression step done early, often on the implant chip, because radio bandwidth and power are scarce. The converter that turns volts into integers adds its own error; see quantization noise, and for filtering see the DFT and the STFT.
Chapter 8
Turn a list of spike times into the count table a decoder reads, and see what each choice of bin width costs
Chapter 7 left us with a list of integers per electrode: the instants at which a spike was detected. A decoder, the program that guesses what the person wants, expects a table of numbers with a fixed shape. The step between the two is simple and full of choices. This chapter takes it slowly, because every later lesson in this series starts from this table.
Because every spike looks alike (Chapter 6), a neuron’s whole output is its spike train: the sorted list of times at which it fired. For one cell it might read [7.0, 21.9, 36.5, 51.1, ...] in milliseconds. That is all the information the cell sends.
To feed a decoder we cut time into equal slices, called bins, and count the spikes in each. A cell that fires at 68 spikes per second, in bins of 50 ms, gives counts near 3 or 4. Divide a count by the bin width and you get a firing rate, here 68 spikes per second. Do this for every cell and you get a table:
X has shape (nbins, Nunits) X[t, i] = spikes of unit i in bin t
One row per time bin, one column per recorded cell. For 200 ms of activity in bins of 20 ms from six cells, X is 10 × 6: sixty small whole numbers. This is the input to a Kalman filter, a generalised linear model or a neural network. Here is the whole step in code:
python import numpy as np def bin_counts(spike_times, T_ms, width_ms): # spike_times: list of N arrays (ms). Returns X with shape (n_bins, N), integer counts edges = np.arange(0, T_ms + width_ms, width_ms) return np.stack([np.histogram(s, edges)[0] for s in spike_times], axis=1)
Bins are a trade between two errors. A narrow bin (say 5 ms) tracks quick changes, but holds 0 or 1 spikes, so each number is mostly luck: a rate of 68 per second means 0.34 spikes per 5 ms bin, and the count is 0 or 1. A wide bin (say 100 ms) holds 6 or 7 spikes and is steady, but blurs together everything that happened in a tenth of a second. A decoder that must steer a cursor smoothly cannot wait that long. Bins of 10 to 50 ms are common choices; the right one depends on the task and is a number to tune, not a law.
The device below drives six model neurons with currents that grow with a "stimulus" value. Every cell has a different gain, as real cells have different preferences. Change the stimulus and the bin width, and read the table.
Top: the raster, one row per cell, one tick per spike. Bottom: the same spikes as counts in bins, darker meaning more. Move the stimulus, then change the bin width.
Cell i receives a held current of gaini × stimulus, with gains 7, 8.5, 10, 13, 18 and 28 µA/cm², and a start time staggered by 3 ms per cell. All six run the full 1952 model for 200 ms. The gains are illustrative.
Watch what the stimulus does. At 0.5, three cells fire once and the other three fire 11, 13 and 15 times. The weak cells have not crossed the repeating-firing threshold of Chapter 6. At 1.0 all six fire repeatedly, from 12 to 18 times. At 0.2 only the three strongest-driven cells fire, once each. The count in each bin carries information about the stimulus. The shape of each spike carries none.
A common first mistake is to treat X as a smooth signal and feed it to a method that assumes bell-shaped noise. Counts are non-negative whole numbers. For a cell firing at random, the count in a bin has a mean m and a variance that is also about m: a Poisson pattern, where the ratio variance over mean (the Fano factor) is 1. Our model neuron is far more regular. Under a steady 10 µA/cm² it fires at gaps of 14.9 ms, then 14.6 ms after 14 spikes, nearly the same, so its counts hardly vary at all. Real cortical cells sit between these extremes. The practical fix is a model that knows about counts: the Poisson model of generalised linear models is the standard first choice.
And Adrian’s third fact, adaptation? Hold the current steady and the real sensory cell slows down. Our squid model does not: gaps of 14.9 and 14.6 ms are almost the same. The model of 1952 has only three kinds of door and no slow currents. Real cortical cells have more channel types, and the extra slow ones create adaptation. The gap is a reminder that this is the first model, not the last.
From here a decoder can smooth the table over time (Kalman filter, RTS smoothing), reduce the 100 or so columns to a few directions (PCA), or model the counts directly (GLM, HMM). Those are the next lessons of the series.
Chapter 9
Replace the four equations with one and a rule, and measure exactly what the shortcut keeps and what it throws away
The Hodgkin-Huxley model is a gem, and it is expensive. Every step needs six exponentials, three gates and a voltage. We used a step of 0.02 ms, so one simulated millisecond costs 50 steps. A brain-scale simulation with millions of cells, or a chip that must model a neuron on a few microwatts, cannot afford that. Engineers ask a sharp question: what is the least we must keep?
Look back at Chapter 6. The spike is a stereotyped event. Once V crosses the threshold, the shape that follows is the same every time. If we only care when the spike happens, we can skip the shape. The leaky integrate-and-fire model (LIF) does exactly that. It keeps the leaky bucket of Chapter 3, which integrates the input, and adds a bright-line rule for the spike.
Worked example with I = 10 µA/cm². The voltage would climb toward Vfinal = −65 + 10 / 0.677 = −50.2 mV. It starts at −65 and must reach −55. The time is τ × ln[(Vfinal − Vstart) / (Vfinal − Vth)] = 1.48 × ln(14.8 / 4.8) = 1.67 ms. Add the wait. With tref = 13 ms the gap between spikes is 14.7 ms, a rate of 68 per second. The full model at 10 gives gaps near 14.6 to 14.9 ms. The shortcut matches, because we set tref to make it so.
The costs are different by a wide margin. LIF needs one multiply-add per step, no exponentials, and a step of 0.1 ms is fine. Counting roughly, that is tens of times fewer operations per simulated millisecond (an illustrative estimate, not a benchmark). That is why spiking networks and neuromorphic hardware are built from LIF-like units. The comparison below shows what we pay.
Same held current for both. Top: the full model. Bottom: LIF, with spikes drawn as a mark at the threshold. Try 5, then 10, then 60.
Current held for 100 ms from 5 ms, in µA/cm². LIF constants: gL 0.677, EL −65 mV, Vth −55 mV, reset −65 mV, pause 13 ms by default (tuned by us to match the full model at 10). They are illustrative fits, not published values.
At 10, the two neurons agree: 7 spikes each in 100 ms. Now raise the current to 60. The full model fires 13 times. The LIF stays at 8, because its pause is fixed: it can never beat one spike per 13 ms, which is 77 spikes a second. The real model shortens its refractory time as you push harder (Chapter 6 measured 7 ms for a 100 µA/cm² second pulse). That is the failure mode: a shortcut tuned in one regime saturates in another.
Lower the current to 5. The full model fires once; this is its single-spike band from Chapter 6. The LIF fires nothing, because its Vfinal of −57.6 mV never reaches −55. The shortcut has no way to make a lone spike from a modest push.
Now what does a BCI need? A decoder needs times and counts, which LIF supplies. A spike sorter needs shape, because it tells neighbouring cells apart by their waveforms. Shapes depend on the sodium and potassium currents of Chapters 4 and 5, which LIF removes. So both models live on: LIF for networks and chips, richer models for the physics of recording. Modern neural-data models go the other way and drop the biology completely. They treat each spike as an event with a time and a unit label, a token in a sequence, and ask a transformer to learn the rest. The next lessons of the series pick up from there.
There is a hardware reason too. A LIF update is one multiply and one add, and it can run in plain integer (fixed-point) arithmetic. The Hodgkin-Huxley update needs exponentials, which cost far more silicon and energy. For an implant that must process many channels on a tiny power budget, the cheaper model is the one that fits. The price is exactly what the device above shows: a model that is right in the regime where it was tuned, and wrong outside it.
Chapter 10
Keep the numbers, the code and the checklist, and find where to go next
A spike is a short event made by a membrane that acts as a capacitor with voltage-controlled doors. Sodium doors open fast and inactivate slowly. Potassium doors open slowly and finish the job. The result is a stereotyped pulse that arrives or does not arrive, whose strength shows up as a rate. An electrode hears its slope, upside down and tiny. A threshold turns that into times. Bins turn the times into a table. Every later lesson in this series starts from that table.
| Quantity | Value | Where it comes from |
|---|---|---|
| Membrane capacitance C | 1 µF/cm² | Hodgkin and Huxley 1952 |
| Maximum gNa, gK, gL | 120, 36, 0.3 mS/cm² | Hodgkin and Huxley 1952 (fitted) |
| ENa, EK, EL | +50, −77, −54.4 mV (rest −65) | 1952 values (+115, −12, +10.6 above rest) drawn on the −65 scale |
| Temperature of the model | 6.3 °C, squid giant axon | Hodgkin and Huxley 1952 |
| Conductances | gK = 36 n⁴, gNa = 120 m³h | Hodgkin and Huxley 1952 |
| Gates at rest m, h, n | 0.053, 0.596, 0.318 | Computed from the rate functions |
| Time constants at rest m, h, n | 0.24, 8.5, 5.5 ms | Computed |
| Conductances at rest gNa, gK | 0.0106, 0.367 mS/cm² | Computed; currents cancel at −65 mV |
| Passive time constant | 1.48 ms (gtot 0.677) | Computed, C / gtot |
| Spike (2 ms, 8 µA/cm² pulse) | peak +40 mV, undershoot −76 mV, half-width 1.5 ms | Our solver, Euler step 0.02 ms |
| Threshold, 1 / 2 / 5 ms pulse | 6.90 / 3.85 / 2.34 µA/cm² | Our solver (bisection) |
| Repeating firing onset (held) | about 6.2 µA/cm², 51 spikes per second | Our solver |
| Robust noise estimate | median(|x|) / 0.6745; threshold a few σ below zero | Form used by Quian Quiroga et al. 2004; the multiplier is a choice |
python import numpy as np C, gNa, gK, gL = 1.0, 120.0, 36.0, 0.3 # uF/cm2, mS/cm2 ENa, EK, EL, Vrest = 50.0, -77.0, -54.387, -65.0 # mV def vtrap(x, y): # x / (exp(x/y) - 1), safe at x = 0 return y if abs(x / y) < 1e-6 else x / np.expm1(x / y) def rates(V): # u = V - Vrest; rates in 1/ms u = V - Vrest return (0.01 * vtrap(10 - u, 10), 0.125 * np.exp(-u / 80), # alpha_n, beta_n 0.1 * vtrap(25 - u, 10), 4.0 * np.exp(-u / 18), # alpha_m, beta_m 0.07 * np.exp(-u / 20), 1 / (np.exp((30 - u) / 10) + 1)) # alpha_h, beta_h def run(I_of_t, T=40.0, dt=0.02): # returns V, shape (T/dt,), in mV an, bn, am, bm, ah, bh = rates(Vrest) n, m, h = an / (an + bn), am / (am + bm), ah / (ah + bh) # gates start at rest V, out = Vrest, [] for k in range(int(T / dt)): an, bn, am, bm, ah, bh = rates(V) INa = gNa * m**3 * h * (V - ENa) IK = gK * n**4 * (V - EK) IL = gL * (V - EL) V += dt * (I_of_t(k * dt) - INa - IK - IL) / C n += dt * (an * (1 - n) - bn * n) m += dt * (am * (1 - m) - bm * m) h += dt * (ah * (1 - h) - bh * h) out.append(V) return np.array(out) V = run(lambda t: 8.0 if 5 <= t < 7 else 0.0) # peak near +40 mV at about 7.5 ms
Everything above is the forward story: cell to spikes to recording. A BCI runs it backwards: recording to spikes to the user’s intent. Each link has a tool you can already name. The detector of Chapter 7 is the start of a spike-sorting pipeline. The table of Chapter 8 feeds smoothing and state estimation (Kalman filter, RTS smoothing, adaptive Kalman), dimension reduction (PCA, ICA), mixture and latent-state models (EM for Gaussian mixtures, HMM), count models (GLM) and, at the frontier, sequence models that treat spikes as tokens (the transformer). The signal chain itself rests on quantization, the DFT, the STFT and wavelets. The next lessons of the BCI series continue from the spike table.
Hodgkin, A. L. and Huxley, A. F. (1952), “A quantitative description of membrane current and its application to conduction and excitation in nerve”, J Physiol 117:500–544 (open access; DOI 10.1113/jphysiol.1952.sp004764). The constants and rate functions were taken from the published CellML re-implementation and cross-checked against the standard forms in Gerstner et al., Neuronal Dynamics, chapter 2; the open copy of the 1952 paper is page images, so we did not read the printed tables directly. Rieke, Warland, de Ruyter van Steveninck and Bialek, Spikes: Exploring the Neural Code, chapter 1, as the course reading spikes_intro.pdf (Adrian’s three facts, the extracellular recording). Quian Quiroga, Nadasdy and Ben-Shaul (2004), Neural Computation, DOI 10.1162/089976604774201631 (median noise estimate for threshold detection). Every number marked “our solver” was computed by the page’s own Euler integration of the 1952 model, and concentrations, spike sizes in microvolts and the LIF constants are illustrative.
The reading belongs to Princeton NEU 560, Statistical Modeling and Analysis of Neural Data (Spring 2024), taught by Jonathan Pillow, whose course site also hosts the slides and notes. We re-taught the ideas in our own words and devices and did not copy course material.
Try Teach to explain the four gates on a whiteboard, or open the Sparks for a quick review. When you are ready, go back to the hero and drive the neuron again: this time you know what every wiggle means.