IntoMindLearn

Chapter 1 · Middle school

The brain's electricity

How can a device resting on your head pick up what your brain is doing?

Your brain runs on electricity

Your brain is made of about 86 billion cells called neurons, and each one connects to thousands of others. A neuron sends a message as a tiny pulse of electricity that runs along it in about a thousandth of a second. Where it meets the next neuron, chemicals carry the message across, and the next neuron may fire a pulse of its own.

Everything you see, think and do involves millions of these pulses.

Try it

The neuron chain

Stand in a line holding hands, with your eyes closed. The timekeeper says go and starts the timer. The first person squeezes the next hand, and each person passes the squeeze on as soon as they feel it. The last person raises their free hand, and the timekeeper stops the timer. Do it three times.

PredictThe squeeze will take about seconds to reach the end of the line.

People in the lineTry 1, secondsTry 2, secondsTry 3, seconds

Work it outDivide your fastest time by the number of people. Each squeeze took about seconds.

You should seeA squeeze that takes time to travel, person by person, about a quarter of a second each. A neuron passes its pulse on in about a thousandth of a second, hundreds of times faster.

Many neurons in step

One neuron's pulse is far too small to notice from outside your head. Your skull and skin are in the way, and they spread every signal out.

But when millions of neurons near each other pulse together, in step, their signals add up. The sum is strong enough to reach your scalp, as a voltage of a few millionths of a volt. That is what the IntoMind One picks up, and a recording of it is called EEG.

Simulated Fourteen neurons, each with its own rhythm. Out of step, they mostly cancel out. Press the button to put them in step, and see what they add up to.

Try it

Clapping in step

Half the class goes into the hallway and closes the door. The other half claps for ten seconds, each person at their own speed. Then everyone claps together, in step, for ten seconds. In the hallway, listen: can you hear a beat each time? Then swap.

You should seeA beat in the hallway only when the claps were in step. The door is like your skull: what gets through clearly is many signals in step.

From your brain to the screen

The IntoMind One rests on your head. Its electrodes, small contacts on its underside, touch your skin and pick up the voltage. Inside it, a chip measures that voltage hundreds of times every second and turns each measurement into a number.

Bluetooth carries the numbers to your computer, where a demo shows them. They go nowhere else.

A system that turns a signal from the brain into a command, with no muscles in between, is called a brain-computer interface, or BCI. In this course, you will build one.

The path From neurons in step, through the skull and skin, into the IntoMind One's electrodes and chip, and over Bluetooth to your computer.

Try it

Draw the path

On paper, draw the path from your neurons to the screen: neurons in step, skull and skin, electrodes, chip, Bluetooth, computer. Then mark the part of the path where the signal is electricity, and the part where it has become numbers.

Talk about it

  1. What do neurons use to send messages to each other?

  2. Why can the IntoMind One pick up your brain only when many neurons pulse in step?

  3. Where does the signal stop being electricity and become numbers? Why does that matter?

Chapter 1 · High school

The brain's electricity

How does a pulse in one neuron, a thousandth of a second long, become a voltage you can measure on the scalp?

One neuron's pulse

Your brain has about 86 billion neurons. At rest, a neuron holds a voltage of about −70 millivolts across its membrane. When it fires, an action potential flips that voltage for about a millisecond and travels along its axon.

Where the axon meets the next neuron, at a synapse, the pulse releases neurotransmitters. They open channels in the next neuron and change its voltage for tens of milliseconds: a postsynaptic potential.

Drawn to scale in time One neuron's action potential lasts about a millisecond. The postsynaptic potential it causes in the next neuron lasts tens of times longer.

Try it

The neuron chain

Stand in a line holding hands, eyes closed. A timekeeper says go and starts the timer. The first person squeezes the next hand, and each person passes the squeeze on as soon as they feel it. The last person raises their free hand, and the timekeeper stops the timer. Do it three times.

PredictEach person will take about seconds to pass the squeeze on.

People in the lineTry 1, secondsTry 2, secondsTry 3, seconds

Work it outFastest time ÷ people = seconds a person, about times slower than a neuron passing on its pulse in about a thousandth of a second.

You should seeA squeeze that takes a few tenths of a second a person: hundreds of times slower than a neuron.

Many neurons in step

EEG comes mostly from postsynaptic currents in the cortex's pyramidal neurons, which line up side by side, at right angles to the surface. Because postsynaptic potentials last tens of milliseconds, those of many neurons overlap in time and add up.

Neurons firing together are in synchrony. In step, a hundred sources add up to a hundred times one. Out of step they mostly cancel, and their sum grows only like the square root of their number: about ten times one, for a hundred.

Simulated Fourteen neurons, each with its own rhythm. Out of step, their sum is small and ragged. Press the button to put them in step.

Try it

Clapping in step

Half the class goes into the hallway and closes the door. The other half claps for ten seconds, each person at their own speed, then ten seconds all together, in step. In the hallway, listen for a beat each time. Then swap.

You should seeA beat that gets through the door only when the claps are in step.

Try it

In step and out of step

In a spreadsheet, put the times 0, 0.01, 0.02 and so on down column A, to 1 second. In row 1, from column B across to column CW, put 100 starting points, called phases: first all 0, for in step. Fill each cell below with =SIN(2*PI()*10*$A2+B$1), and add each row's 100 waves in a last column. Note the biggest sum. Then change every phase to =RAND()*2*PI(), for out of step, and note the biggest sum again. Do the random case five times.

PhasesBiggest sum
All in step
Random, try 1
Random, try 2
Random, try 3
Random, try 4
Random, try 5

You should seeIn step, a sum of 100. Out of step, a sum near 10, different each time.

What EEG can and can't see

The skull spreads every signal over centimeters, so EEG can't say precisely where a signal came from, and sources deep in the brain barely reach the scalp. But it follows changes within milliseconds, faster than almost any other way of measuring a living brain.

The IntoMind One's four electrodes pick up that voltage, a few millionths of a volt, and its chip turns it into numbers, hundreds of times a second. A recording of it is called EEG.

The path From neurons in step, through the skull and skin, into the IntoMind One's electrodes and chip, and over Bluetooth to the computer.

Try it

Time against space

Compare EEG with fMRI, the kind of MRI that follows changes in blood flow as the brain works. Look up what you need.

EEGfMRI
What it measures
How fast it follows a change
How precisely it says where
What it costs
Can you wear it?

Work it outWith four channels, the IntoMind One is good for , and poor for .

Talk about it

  1. Why does EEG reflect postsynaptic potentials more than action potentials?

  2. A hundred sources in step add up to a hundred times one. Out of step, about ten times. Why the square root?

  3. A company says its four electrodes can tell exactly which part of your brain is active. What would you ask?

Sources

Nunez, P. L., and Srinivasan, R. (2006). Electric Fields of the Brain: The Neurophysics of EEG. Oxford University Press.

Chapter 1 · College

The brain's electricity

How does synaptic current in the cortex become a few microvolts on the scalp, and what does the choice of reference do to what you measure?

From synapse to scalp

A neuron's action potential lasts about a millisecond. The postsynaptic potential it causes in the next neuron lasts tens of milliseconds, so in a population the second kind overlaps in time and adds up, and the first rarely does.

Scalp EEG comes mostly from postsynaptic currents in the pyramidal neurons of the cortex. They stand side by side, perpendicular to the surface, so their currents line up. A patch of them active together behaves as a current dipole.

Drawn to scale in time An action potential, about a millisecond, and the postsynaptic potential it causes, tens of times longer.

In step, and out of step

Give each of N sources an oscillation of amplitude a. In step, they add to N·a. With independent, random phases, the sum is a random walk, and its typical amplitude is only √N·a.

So a rhythm reaches the scalp only when very many neurons are synchronized, typically over several square centimeters of cortex. EEG measures synchrony as much as activity: a region can be busy and show little, if its neurons are out of step.

Simulated Fourteen oscillations and their sum. Out of step, the sum is small and ragged. Press the button to bring them into step.

Try it

Adding sources

Sum N ten-hertz sources with random phases, twenty times over, and compare the typical amplitude of the sum with N, the amplitude in step, for N of 1, 100 and 10,000.

import numpy as np

rng = np.random.default_rng(0)
t = np.arange(0, 1, 1 / 500)            # one second, 500 samples a second
for n in (1, 100, 10_000):
    sizes = []
    for _ in range(20):
        phases = rng.uniform(0, 2 * np.pi, n)
        total = np.sin(2 * np.pi * 10 * t[:, None] + phases).sum(axis=1)
        # the amplitude of the summed sinusoid
        sizes.append(np.sqrt(2 * np.mean(total ** 2)))
    typical = np.sqrt(np.mean(np.square(sizes)))
    print(n, "in step:", n, "out of step:", round(typical, 1))

You should seeOut of step, about 1, 10 and 100: √N, against N in step.

Through the head

The head is a volume conductor. A dipole drives currents through brain, cerebrospinal fluid, skull and scalp, and every point on the scalp sees a weighted sum of every active source. In a uniform medium, a dipole's potential falls as cos θ / r², with distance r and angle θ from its axis.

The skull conducts far less than the tissues around it, and spreads each source's potential over several centimeters of scalp. Deep sources contribute little: they are farther away, and many deep structures lack the aligned geometry that lets currents add.

A source and its field A patch of cortex in step acts as a current dipole. The skull spreads its potential over centimeters of scalp, so the peak is broad and every electrode sees a mixture.

The reference and the montage

An EEG channel is always the difference between two electrodes. The reference is the electrode, or the average, every channel is measured against, and a montage is the set of differences you choose to look at. Change either, and every waveform changes.

The IntoMind One has four channels with a shared reference, five gold-plated electrodes on one small device, a few centimeters apart. Each channel is a local difference: a source that reaches an electrode and the reference alike cancels, and a source near one electrode survives.

Try it

Re-referencing

Five electrodes see a broad six-hertz source almost equally, and a local twenty-hertz source near electrode 0. Work out how much of each source four channels carry, measured against electrode 4, then against their own average.

import numpy as np

# how strongly each of five electrodes sees the broad source and the local one
w = np.array([[1.00, 1.0], [0.97, 0.5], [0.94, 0.2], [0.91, 0.1], [0.88, 0.0]])
to_one = w[:4] - w[4]                   # four channels, against electrode 4
to_mean = w[:4] - w[:4].mean(axis=0)    # the same four, against their average
print(np.round(to_one, 2))
print(np.round(to_mean, 2))

# each channel's signal, to plot
t = np.arange(0, 2, 1 / 500)
sources = np.vstack([np.sin(2 * np.pi * 6 * t), np.sin(2 * np.pi * 20 * t)])
channels = to_one @ sources

You should seeThe broad source cut from about 1 to a tenth or less in every channel, under either reference, and the local source kept near electrode 0, at a size that depends on the reference. Under the average, it even changes sign in channels 2 and 3.

What EEG can and can't see

EEG follows the brain millisecond by millisecond, through the skull, with nothing implanted. It pays for that in space: each electrode sees centimeters of cortex, mixed. Four channels close together can describe rhythms and how they change, and can't say where a source is.

MethodWhat it measuresIn timeIn spaceImplanted?
EEGPotentials on the scalp from synchronized postsynaptic currentsMillisecondsCentimetersNo
MEGThe magnetic fields of the same currentsMillisecondsSeveral millimeters to centimetersNo, but a shielded room
fMRIChanges in blood oxygen that follow activitySecondsMillimetersNo, but a scanner
ECoGPotentials on the surface of the cortexMillisecondsMillimetersYes, under the skull

Problems

  1. Why does scalp EEG reflect postsynaptic potentials far more than action potentials?

  2. Ten thousand sources would each contribute 0.01 microvolts at an electrode. What does the electrode see if they are in step, and if their phases are random?

  3. A dipole twice as far from an electrode, at the same angle: what happens to its potential there? Give a second reason deep sources contribute little.

  4. An electrode and its reference both record the same 20-microvolt alpha rhythm, in phase. What does the channel show? What does that mean for a reference a few centimeters away?

  5. A company says its four electrodes can tell exactly which part of your brain is active. What would you ask?

Sources

Nunez, P. L., and Srinivasan, R. (2006). Electric Fields of the Brain: The Neurophysics of EEG. Oxford University Press.

Buzsáki, G., Anastassiou, C. A., and Koch, C. (2012). The origin of extracellular fields and currents: EEG, ECoG, LFP and spikes. Nature Reviews Neuroscience.

Cohen, M. X. (2017). Where does EEG come from and what does it mean? Trends in Neurosciences.

Chapter 1 · Graduate

The brain's electricity

What generates the potential on the scalp, how does the head carry it there, and what can four channels with a shared reference say about where it came from?

Generators

The scalp potential comes mostly from transmembrane currents in cortical pyramidal neurons: synaptic currents above all, with contributions from active currents such as dendritic calcium spikes and afterhyperpolarizations (Buzsáki, Anastassiou and Koch, 2012). Pyramidal cells stand side by side with their apical dendrites perpendicular to the cortical surface, so current entering a cell at one depth and leaving at another adds across neighbors. A patch acting together is a current dipole, of moment p in ampere-meters, normal to the cortex. On a gyral crown it is radial to the scalp. In a sulcal wall it is tangential, and opposite walls of a sulcus partly cancel.

Sources in step add as their number N, and out of step as √N, so the scalp sees synchrony over large areas. In simultaneous scalp and intracranial recordings, 90 percent of interictal spikes with a cortical source above 10 cm² appeared on the scalp, 10 percent of those below it, and none below 6 cm² (Tao and others, 2005). EEG measures how much activity is synchronized, which is not the same as how much there is, and what a synchronized rhythm means for computation is a separate question (Cohen, 2017).

The forward model

At the frequencies of EEG, the tissues' capacitance, induction and propagation delays are negligible (Plonsey and Heppner, 1967). The potential then follows the source current from moment to moment, by Poisson's equation, with conductivity σ and the primary current density Jp of the neurons:

∇·(σ ∇V) = ∇·Jp

In an infinite homogeneous medium, a dipole p at r′ gives

V(r) = p·(r − r′) / (4πσ |r − r′|³)

which falls as 1/r² and as the cosine of the angle from the dipole's axis. The head is not homogeneous. The skull conducts far less than brain and scalp, and spreads each source's potential over centimeters. Source modeling long used a brain-to-skull ratio of 80 (Rush and Driscoll, 1968). In vivo and in vitro measurement gave about 15 (Oostendorp and others, 2000). Spheres, boundary elements and finite elements trade realism for computation (Mosher, Leahy and Lewis, 1999).

The equation is linear in the sources. Place candidate dipoles on a grid, three orientations each, and the electrodes' potentials are

v = L s + n

where s holds the dipole moments, n the noise, and the lead field L, one row per channel and one column per source orientation, comes from the head model. Computing v from s is the forward problem, and it has one answer.

The reference

An amplifier measures differences. With five electrodes, the fifth a shared reference, the four channels are v = D V, where V holds the five potentials against infinity and D = [I4 | −1]. Re-referencing is another linear map of the same channels. None recovers V, which is known only up to a constant common to every electrode, and none adds information: the rank stays at most four. Differences between channels don't depend on the reference at all. The average of a few electrodes close together is not a stand-in for infinity. That needs coverage of the whole head, or a head model, as in Yao's (2001) standardization.

The IntoMind One has four channels with a shared reference: five dry, gold-plated electrodes on one small device. Every channel is a difference across a few centimeters, a spatial high-pass filter. It rejects what reaches an electrode and the reference alike, such as broad or distant sources, and keeps local gradients.

The inverse problem

From v to s, there is no single answer. With four channels and thousands of unknowns, L has a null space of dimension at least the number of unknowns minus four, and any pattern in it can be added to any solution without changing a single channel. An inverse method picks one solution by a prior. The minimum-norm estimate picks the smallest pattern that explains the data (Hämäläinen and Ilmoniemi, 1994):

ŝ = Lᵀ (L Lᵀ + λI)⁻¹ v

It lies in the row space of L, so it is built from the channels' own sensitivity profiles, and it explains a deep source with shallower ones of smaller moment. What a point source becomes after inversion is a column of the resolution matrix R = Lᵀ(L Lᵀ + λI)⁻¹ L. With four channels close together, the prior does nearly all the work: the data can describe a rhythm's amplitude and timing near the device, and can't say where it came from.

Analysis

Analysis

A lead field for a small device

Build the forward model for five electrodes 2 cm apart near Oz, a stand-in for one small device, on a four-shell sphere with the skull at a fifteenth of the brain's conductivity. Reference four channels to the fifth, then find two different source patterns that give the same channels, invert a shallow and a deep source, and see how a source's reach falls with depth.

import numpy as np
import mne

# A spherical head of radius 9 cm in four shells: brain, cerebrospinal fluid, skull and scalp,
# with the skull at a fifteenth of the brain's conductivity.
sphere = mne.make_sphere_model(r0=(0.0, 0.0, 0.0), head_radius=0.09,
                               relative_radii=(0.90, 0.92, 0.97, 1.0),
                               sigmas=(0.33, 1.0, 0.33 / 15, 0.33), verbose="error")

def on_scalp(azimuth, elevation, r=0.09):
    """A point at radius r, by degrees around from the back of the head and up from the ears."""
    a, e = np.radians(azimuth), np.radians(elevation)
    return r * np.array([np.cos(e) * np.sin(a), -np.cos(e) * np.cos(a), np.sin(e)])

# Five electrodes 2 cm apart near Oz: a stand-in for one small device. E5 is the reference.
step = np.degrees(0.02 / 0.09)
spots = [(0, 20 + step), (step, 20), (0, 20 - step), (-step, 20), (0, 20)]
names = ["E1", "E2", "E3", "E4", "E5"]
info = mne.create_info(names, 500.0, "eeg")
info.set_montage(mne.channels.make_dig_montage(
    ch_pos={n: on_scalp(*s) for n, s in zip(names, spots)}, coord_frame="head"))

# Candidate sources on a 1 cm grid inside the brain, each free to point any way.
src = mne.setup_volume_source_space(sphere=sphere, pos=10.0, mindist=5.0, exclude=20.0,
                                    verbose="error")
fwd = mne.make_forward_solution(info, trans=None, src=src, bem=sphere, eeg=True, meg=False,
                                verbose="error")
G = fwd["sol"]["data"]          # 5 electrodes x 3 orientations per source, volts per A m
pos = fwd["source_rr"]
D = np.hstack([np.eye(4), -np.ones((4, 1))])    # each channel against E5
L = D @ G

sv = np.linalg.svd(L, compute_uv=False)
print(f"{len(pos)} sources, {L.shape[1]} unknowns, rank {np.linalg.matrix_rank(L)}")
print("singular values, relative to the largest:", np.round(sv / sv[0], 2))

# Two different patterns of sources, the same four channels.
u = on_scalp(0, 20) / 0.09      # the direction from the center to the device
def source_at(depth, moment=10e-9):
    """A source of `moment` A m pointing out of the head, `depth` m under the device."""
    k = int(np.argmin(np.linalg.norm(pos - u * (0.09 - depth), axis=1)))
    s = np.zeros(L.shape[1])
    s[3 * k:3 * k + 3] = moment * pos[k] / np.linalg.norm(pos[k])
    return s, k
s, k = source_at(0.02)
null = np.linalg.svd(L)[2][4:]  # 5,432 patterns of sources the channels can't see
other = s + 1e-7 * null[0]      # add one of them, ten times the source's size
print("one source, microvolts:   ", np.round(1e6 * L @ s, 3))
print("a different pattern, same:", np.round(1e6 * L @ other, 3))

# The minimum-norm estimate, for a source 2 cm and 5 cm under the device.
lam = 1e-4 * np.trace(L @ L.T) / 4
W = L.T @ np.linalg.inv(L @ L.T + lam * np.eye(4))
deep = lambda i: 100 * (0.09 - np.linalg.norm(pos[i]))
for depth in (0.02, 0.05):
    s, k = source_at(depth)
    peak = int(np.argmax(np.linalg.norm((W @ (L @ s)).reshape(-1, 3), axis=1)))
    away = 100 * np.linalg.norm(pos[peak] - pos[k])
    print(f"a source {deep(k):.1f} cm deep: the estimate peaks {deep(peak):.1f} cm deep, "
          f"{away:.1f} cm from it")

# How strongly a source reaches the channels, by depth: against E5, and against infinity.
for depth in (0.02, 0.03, 0.04, 0.05, 0.06):
    s, k = source_at(depth)
    local, far = 1e6 * np.abs(L @ s).max(), 1e6 * np.abs(G[4] @ s)
    print(f"{deep(k):.1f} cm deep: largest channel against E5 {local:.2f} uV, "
          f"E5 against infinity {far:.2f} uV")

You should seeRank 4 among 5,436 unknowns. A second pattern, the source plus an invisible one ten times its size, giving identical channels. The estimate of a source 1.7 cm deep in the right place, and of one 4.9 cm deep at 1.7 cm, 3.2 cm away. From 1.7 to 4.9 cm deep, the largest local channel falls from 5.40 to 0.43 microvolts, twelvefold, and the electrode above the source against infinity only fourfold, from 8.74 to 2.15.

Then report: how the depth falloff changes with the spacing of the electrodes, at 1, 2 and 4 cm, and with the skull's ratio at 15 and at 80. Which of your conclusions depend on the head model?

Open problems

  1. Deep sources. With 256 channels and recordings from deep brain stimulation electrodes, Seeber and others (2019) found alpha envelopes from the thalamus and the nucleus accumbens reflected in scalp source estimates, in three patients. How much subcortical activity reaches the scalp, and whether any of it can be read from a few channels, is unsettled.
  2. Beyond synapses. In a detailed model of neocortex, active membrane currents shaped the local field potential as much as synaptic ones (Reimann and others, 2013). How their share carries to the scalp, and to which rhythms, is not known.
  3. A neutral reference. Every reference is somewhere. Standardizing to infinity depends on the head model and on coverage (Yao, 2001), and for a few electrodes close together, nothing recovers the potential against infinity.
  4. The skull. Its conductivity differs between people and across one skull, and the literature's ratios differ fivefold. How much that matters depends on the question: little for a rhythm's timing, a great deal for its location.

Problems

  1. A dipole of 10 nA·m in an infinite medium of 0.33 S/m: what potential does it make 3 cm away on its axis, and at 6 cm? At 3 cm and 60 degrees off its axis?

  2. Four channels are recorded against a fifth electrode. Write the matrix that re-references them to their own average. What is its rank, and what is lost? What would keep the rank at four?

  3. In the analysis, how many independent source patterns are invisible to the four channels? Of all the source patterns that fit the data exactly, which does the minimum-norm estimate choose, and why that one?

  4. Why does the minimum-norm estimate move a deep source toward the surface? What does weighting each source by its own gain fix, and what does it assume instead?

  5. A paper reports, from four electrodes over the back of the head, that a participant's thalamus drives their alpha. What evidence would you need before believing it?

Sources

Plonsey, R., and Heppner, D. B. (1967). Considerations of quasi-stationarity in electrophysiological systems. Bulletin of Mathematical Biophysics.

Rush, S., and Driscoll, D. A. (1968). Current distribution in the brain from surface electrodes. Anesthesia and Analgesia.

Hämäläinen, M. S., and Ilmoniemi, R. J. (1994). Interpreting magnetic fields of the brain: minimum norm estimates. Medical and Biological Engineering and Computing.

Mosher, J. C., Leahy, R. M., and Lewis, P. S. (1999). EEG and MEG: forward solutions for inverse methods. IEEE Transactions on Biomedical Engineering.

Oostendorp, T. F., Delbeke, J., and Stegeman, D. F. (2000). The conductivity of the human skull: results of in vivo and in vitro measurements. IEEE Transactions on Biomedical Engineering.

Yao, D. (2001). A method to standardize a reference of scalp EEG recordings to a point at infinity. Physiological Measurement.

Tao, J. X., Ray, A., Hawes-Ebersole, S., and Ebersole, J. S. (2005). Intracranial EEG substrates of scalp EEG interictal spikes. Epilepsia.

Nunez, P. L., and Srinivasan, R. (2006). Electric Fields of the Brain: The Neurophysics of EEG. Oxford University Press.

Buzsáki, G., Anastassiou, C. A., and Koch, C. (2012). The origin of extracellular fields and currents: EEG, ECoG, LFP and spikes. Nature Reviews Neuroscience.

Reimann, M. W., and others (2013). A biophysically detailed model of neocortical local field potentials predicts the critical role of active membrane currents. Neuron.

Cohen, M. X. (2017). Where does EEG come from and what does it mean? Trends in Neurosciences.

Seeber, M., and others (2019). Subcortical electrophysiological activity is detectable with high-density EEG source imaging. Nature Communications.