Project E: The zero-dollar version
Real EEG from 109 people, downloaded free, opened in Python. Find alpha, find a blink, find the heartbeat leaking in. Everything in Phase 1 without buying a part.
On this pageOne evening
If you have no parts yet, or you want to see what a properly recorded 64-channel EEGElectroencephalography (EEG) Recording the brain's electrical activity from electrodes on the scalp, a few tens of microvolts of blurred, summed cortical activity. Related: Electrocorticography (ECoG)Electrocorticography (ECoG) Recording from electrodes placed on the surface of the brain under the skull, usually during epilepsy surgery evaluation; cleaner and sharper than EEG. , Magnetoencephalography (MEG)Magnetoencephalography (MEG) Recording the tiny magnetic fields produced by cortical currents with superconducting sensors in a shielded room; less blurred by the skull than EEG, and far more expensive. , Volume conductionVolume conduction The spreading of currents from a source through the conductive tissues of the head, which is why one source shows up on many electrodes and why scalp EEG is blurry. , Microvolt (µV)Microvolt (µV) One millionth of a volt. Scalp EEG is tens of microvolts; a AA battery is 1.5 million of them. . Glossary entry looks like before you build a one-channel version, this is the project. PhysioNetPhysioNet A free archive of physiological recordings including EEG, ECG, and sleep data, run out of MIT. Related: Sleep-EDFSleep-EDF A public PhysioNet dataset of whole-night sleep recordings with expert stage labels, the standard training set for automatic sleep staging.. Glossary entry hosts the EEGElectroencephalography (EEG) Recording the brain's electrical activity from electrodes on the scalp, a few tens of microvolts of blurred, summed cortical activity. Related: Electrocorticography (ECoG)Electrocorticography (ECoG) Recording from electrodes placed on the surface of the brain under the skull, usually during epilepsy surgery evaluation; cleaner and sharper than EEG. , Magnetoencephalography (MEG)Magnetoencephalography (MEG) Recording the tiny magnetic fields produced by cortical currents with superconducting sensors in a shielded room; less blurred by the skull than EEG, and far more expensive. , Volume conductionVolume conduction The spreading of currents from a source through the conductive tissues of the head, which is why one source shows up on many electrodes and why scalp EEG is blurry. , Microvolt (µV)Microvolt (µV) One millionth of a volt. Scalp EEG is tens of microvolts; a AA battery is 1.5 million of them. . Glossary entry Motor Movement/Imagery dataset: 109 people, 64 electrodesElectrode The conductor that turns ion currents in tissue into electron currents in a wire; its chemistry and contact quality set the noise you live with. Related: Silver/silver-chloride (Ag/AgCl)Silver/silver-chloride (Ag/AgCl) The standard electrode material for biopotentials, because its chemistry produces a stable, low-noise, low-drift interface with salty gel. , Electrode impedanceElectrode impedance How hard it is to push current through the skin-electrode contact, typically 5 to 50 kilohms with gel and megohms dry, higher at low frequencies. , Half-cell potentialHalf-cell potential The DC voltage that appears wherever a metal meets an electrolyte; two electrodes with different half-cell potentials produce an offset that can swamp the signal. . Glossary entry, sampled at 160 Hz, with two one-minute baseline recordings for each person, one with eyes open and one with eyes closed. MNE-PythonMNE-Python The standard open-source Python library for EEG and MEG analysis: filtering, epoching, ICA, topographies, source localization. Related: Independent component analysis (ICA)Independent component analysis (ICA) A method that unmixes multichannel data into statistically independent sources, so blinks and heartbeat can be identified and removed.. Glossary entry will download it for you. In an hour you will have found alpha in a stranger’s brain and know what a blink and a heartbeat look like on a real recording.
On a 64-channel recording, in which channel will a blink be biggest?
Fp1, the frontal-polar electrodeElectrode The conductor that turns ion currents in tissue into electron currents in a wire; its chemistry and contact quality set the noise you live with. Related: Silver/silver-chloride (Ag/AgCl)Silver/silver-chloride (Ag/AgCl) The standard electrode material for biopotentials, because its chemistry produces a stable, low-noise, low-drift interface with salty gel. , Electrode impedanceElectrode impedance How hard it is to push current through the skin-electrode contact, typically 5 to 50 kilohms with gel and megohms dry, higher at low frequencies. , Half-cell potentialHalf-cell potential The DC voltage that appears wherever a metal meets an electrolyte; two electrodes with different half-cell potentials produce an offset that can swamp the signal. . Glossary entry just above the eye. Blinks are eye movement, and the eyeball is a battery whose field is strongest right next to it. At Oz the same blink is a tenth the size.
Setup
pip install mne matplotlib
MNEMNE-Python The standard open-source Python library for EEG and MEG analysis: filtering, epoching, ICA, topographies, source localization. Related: Independent component analysis (ICA)Independent component analysis (ICA) A method that unmixes multichannel data into statistically independent sources, so blinks and heartbeat can be identified and removed. . Glossary entry has a loader for this dataset that fetches only the files you ask for. Run 1 is eyes open, run 2 is eyes closed.
import mne
from mne.datasets import eegbci
paths = eegbci.load_data(subject=1, runs=[1, 2]) # downloads ~2 MB per run
open_eyes = mne.io.read_raw_edf(paths[0], preload=True)
closed = mne.io.read_raw_edf(paths[1], preload=True)
for raw in (open_eyes, closed):
eegbci.standardize(raw) # clean up channel names
raw.set_montage('standard_1005') # tell MNE where the electrodes are
raw.filter(0.5, 40.) # the same band-pass as Project B
Find alpha
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
for raw, label in ((open_eyes, 'eyes open'), (closed, 'eyes closed')):
spec = raw.compute_psd(picks=['O1'], fmax=40)
freqs = spec.freqs; psd = spec.get_data()[0]
ax.semilogy(freqs, psd, label=label)
ax.set(xlabel='Hz', ylabel='power (V²/Hz)', title='Subject 1, O1'); ax.legend(); plt.show()
Two curves. The eyes-closed one has a peak somewhere between 8 and 12 Hz that the eyes-open one does not. That is alpha, in a person you have never met, recorded with a research amplifier. Note the peak frequency; it differs by a hertz or two between people, and it is stable within a person for years.
Try a few subjects. Some have enormous alpha; a few have almost none. Both are normal.
Find a blink
open_eyes.plot(start=0, duration=10, n_channels=8, scalings=dict(eeg=100e-6))
Look at Fp1 and Fp2 at the top. Blinks are the big, slow, paired deflections, a few hundred microvolts, about a third of a second wide, that show up in both frontal channels and fade as you go back. Now look at Oz at the same moment. Small or absent. You have just seen how a source’s location shows up as a pattern across electrodesElectrode The conductor that turns ion currents in tissue into electron currents in a wire; its chemistry and contact quality set the noise you live with. Related: Silver/silver-chloride (Ag/AgCl)Silver/silver-chloride (Ag/AgCl) The standard electrode material for biopotentials, because its chemistry produces a stable, low-noise, low-drift interface with salty gel. , Electrode impedanceElectrode impedance How hard it is to push current through the skin-electrode contact, typically 5 to 50 kilohms with gel and megohms dry, higher at low frequencies. , Half-cell potentialHalf-cell potential The DC voltage that appears wherever a metal meets an electrolyte; two electrodes with different half-cell potentials produce an offset that can swamp the signal. . Glossary entry, which is the physics that Phase 4’s head model is about.
Find the heartbeat
Pick a channel near an ear, such as T7 or TP7, and plot ten seconds with a smaller scaling. Look for a small sharp spikeSpike Shorthand for an action potential as seen by an electrode, a brief blip about a millisecond wide. Related: Action potentialAction potential The brief, all-or-nothing voltage spike a neuron fires, about a millisecond long and about 100 millivolts tall across its membrane. , Spike sortingSpike sorting Deciding which spikes on an electrode came from which neuron, by clustering their waveform shapes. , Extracellular recordingExtracellular recording Recording with an electrode near neurons rather than inside one; you see small, fast blips from nearby cells rather than the full membrane swing. . Glossary entry about once a second. That is the heart’s electrical activity, a millivolt on the chest, leaking to the head as a few microvolts. It is in almost every EEGElectroencephalography (EEG) Recording the brain's electrical activity from electrodes on the scalp, a few tens of microvolts of blurred, summed cortical activity. Related: Electrocorticography (ECoG)Electrocorticography (ECoG) Recording from electrodes placed on the surface of the brain under the skull, usually during epilepsy surgery evaluation; cleaner and sharper than EEG. , Magnetoencephalography (MEG)Magnetoencephalography (MEG) Recording the tiny magnetic fields produced by cortical currents with superconducting sensors in a shielded room; less blurred by the skull than EEG, and far more expensive. , Volume conductionVolume conduction The spreading of currents from a source through the conductive tissues of the head, which is why one source shows up on many electrodes and why scalp EEG is blurry. , Microvolt (µV)Microvolt (µV) One millionth of a volt. Scalp EEG is tens of microvolts; a AA battery is 1.5 million of them. . Glossary entry and most people never notice it until it shows up in their average.
Draw the map
closed.compute_psd(fmax=40).plot_topomap(bands={'alpha (8-12 Hz)': (8, 12)})
A head, coloured by alpha power. It should be brightest at the back. This single picture is why Project B puts the electrodeElectrode The conductor that turns ion currents in tissue into electron currents in a wire; its chemistry and contact quality set the noise you live with. Related: Silver/silver-chloride (Ag/AgCl)Silver/silver-chloride (Ag/AgCl) The standard electrode material for biopotentials, because its chemistry produces a stable, low-noise, low-drift interface with salty gel. , Electrode impedanceElectrode impedance How hard it is to push current through the skin-electrode contact, typically 5 to 50 kilohms with gel and megohms dry, higher at low frequencies. , Half-cell potentialHalf-cell potential The DC voltage that appears wherever a metal meets an electrolyte; two electrodes with different half-cell potentials produce an offset that can swamp the signal. . Glossary entry where it does.
- Install MNEMNE-Python The standard open-source Python library for EEG and MEG analysis: filtering, epoching, ICA, topographies, source localization. Related: Independent component analysis (ICA)Independent component analysis (ICA) A method that unmixes multichannel data into statistically independent sources, so blinks and heartbeat can be identified and removed. . Glossary entry and run the loader for subject 1, runs 1 and 2.
- Plot the O1 spectrumSpectrum A plot of how much of a signal lives at each frequency. Related: Fast Fourier transform (FFT)Fast Fourier transform (FFT) The algorithm that breaks a stretch of signal into the sinusoids that would add up to it, giving amplitude and phase at each frequency. , Power spectral density (PSD)Power spectral density (PSD) The spectrum expressed as power per hertz, the standard way to quantify how strong alpha is. . Glossary entry for both runs and identify the alpha peak. Write down its frequency.
- Plot ten seconds of the eyes-open run and find two blinks in Fp1. Measure their amplitude and width from the plot.
- Find the heartbeat in a temporal channel.
- Plot the alpha topography for eyes closed.
- Repeat step 2 for three more subjects. Save the four spectra as one figure with a legend, axes labelled.
Going further
Load run 3 (a motor task: open and close the left or right fist) and plot the C3 and C4 spectra while the subject moves versus rests. You will see the mu rhythm drop over the hemisphere opposite the moving hand. That is the phenomenon that motor imagery BCIs try to decode, and you have just seen it in a minute of data. Then go to the software pipeline project, which turns tonight’s script into a proper analysis.