From electrode to bytes

What one electrode pair actually records, how that becomes whole numbers and then bytes in a file, and how you can tell alpha from deep sleep in nothing but those numbers.

Not yet verified. The sources on this page haven't been checked against the originals yet. What this means

Until someone checks them, treat the claims and figures here as unverified.

How we verify: each cited claim is an exact sentence on this page plus the source that should back it. A reviewer reads the source itself, not a summary, and records per claim whether it supports the sentence and where. Three independent Claude runs will check the claims too; anything they don't all agree on goes to a person. The label turns green only when every claim is supported and a named reviewer has signed off this exact text; when the text changes, the label goes back to red until someone checks it again. How to verify a source.

  • An electrode pair gives one voltage that changes all the time. The recorder looks at it 100 times a second and writes each look down as a whole number.
  • Each whole number goes into the file as 2 bytes. That’s all the file holds for the brain: no word like “alpha” or “sleep” anywhere.
  • Alpha or deep sleep is something you work out from the numbers: how many times a second they go up and down (the speed, in Hz), and how far (the size, in µV).

Educational, not medical advice. Every number on this page comes from one real recording: the EEG channel Pz-Oz of night SC4001 in Sleep-EDF Expanded, the same night as Lab 9a.

1. Where the electrodes are, and why always two

The names are positions. Electrodes are placed with the 10-20 system, an international standard from 1958. You measure the head from the bridge of the nose (the nasion) over the very top to the bump at the back of the skull (the inion), and put the midline electrodes at fixed percentages of that line: Fpz 10% from the nasion, then Fz, Cz and Pz every 20%, and Oz 20% after Pz, which is 10% before the inion. Because these are percentages, the same name lands on the same place on a small head and a large one.

The letters say what lies underneath: Fp frontopolar, F frontal, C central (a region, not a lobe), P parietal, O occipital. The z means zero: the midline. So Pz sits over the parietal lobe and Oz over the occipital lobe, both on the midline.

Why always two? A voltage is always a difference between two points, and there is no place on the head or the body that is electrically zero to measure against. So every EEG channel is one electrode measured against another, and the name says which: Pz-Oz means Pz minus Oz. When the two electrodes are near each other, as here, the pair is called bipolar. Whatever reaches both electrodes equally drops out in the subtraction, so a bipolar pair mostly shows what differs between those two spots: activity close to them, and less from deep in the brain. The amplifier works the same way: it amplifies the difference and amplifies what both electrodes share much less.

Try it. Below, both electrodes pick up the same noise: a hum at 50 Hz, the frequency of the mains power in Europe, and a slow drift. On its own, each electrode shows almost only noise. Subtract them and the noise is gone. Then make the contact of Oz worse: it no longer picks up the same amount of noise as Pz, the subtraction can’t remove it, and the hum comes through. This is one reason why good, equal contact on every electrode matters so much.

A simulation: the bottom line is the real Pz-Oz recording (awake page, 06:47). How it splits into Pz and Oz, and the noise, are made up to show the principle.

Why these two pairs? This file has two EEG channels: Fpz-Cz at the front and top, and Pz-Oz at the back. The technicians scored the night from these two, instead of the C4-A1 and C3-A2 pairs of the 1968 scoring manual. The back of the head matters for one rhythm in particular: alpha, which in relaxed wakefulness shows over the back of the head, strongest over the occipital area, and best with the eyes closed. You can see it in this night: on the awake morning page used further down, Pz-Oz has 54% of its power in alpha, Fpz-Cz on the forehead only 5%.

The head in the figure is a simplified oval around a real brain, so the positions are close, not exact.

2. What the pair measures

The voltage between Pz and Oz is tiny, a few to about a hundred millionths of a volt (microvolts, µV), and it changes all the time with the electrical activity of the brain.

3 seconds of EEG Pz-Oz, awake, from night SC4001: 300 numbers drawn as one line.

Before the signal is saved, the recorder filters it. The file says which filters, in the signal header of Pz-Oz: HP:0.5Hz LP:100Hz. A high-pass filter at 0.5 Hz removes very slow drifts, and a low-pass filter at 100 Hz removes very fast changes. What is left is the part sleep scoring looks at.

One honest note about this figure: we don’t have the voltage itself, only the numbers the recorder wrote down. The line is drawn through those numbers. Steps 3 and 4 show what that means.

3. Sampling: the recorder looks 100 times a second

A file can’t hold a line, only numbers. So the recorder samples: at fixed moments it measures the voltage and keeps that one value. In this file that happens 100 times a second (the header says 3000 numbers per 30-second record, so 3000 / 30 = 100 Hz).

Try a slower recorder below. The faint line is what the file really has; the bright line and dots are what you would keep if you only looked less often.

At 100 Hz an alpha wave of about 10 per second gets about 10 dots per wave, plenty to see its shape. At 20 Hz it gets 2 dots per wave and its shape is gone; at 10 Hz it gets 1 dot per wave and you can no longer see that it’s a wave at all. The rule behind this: to see a wave you need more than two samples per wave. This figure simply drops samples to show the problem; it is not how a real recorder at a lower rate would behave.

4. Rounding: every look becomes a whole number

The recorder doesn’t store −3.14 µV. It stores a whole number, here −28, from a fixed range, and lets the header say what that range means. For Pz-Oz the header says: stored numbers from −2048 to 2047 stand for −197 to +196 µV. That is 4,096 possible numbers, so one step is 393 / 4,095 = 0.096 µV.

With 4,096 steps the rounding is far smaller than the wave itself, and you can’t see it. With 32 steps (one step = 12.7 µV) the alpha wave turns into a staircase, and with 8 almost all of it falls into a single step. That’s why the four numbers in the header (physical and digital minimum and maximum) matter: they decide how finely the voltage is kept, and how to turn the stored numbers back into µV.

5. Into the file: two bytes per number

A whole number from −2048 to 2047 fits in 2 bytes (16 bits). The table shows the first six numbers of one awake 30-second page, exactly as they sit in SC4001E0-PSG.edf.

Three things to notice:

  • Negative numbers are stored as 65,536 minus the number (this is called two’s complement). −28 becomes 65,508, which is hex FF E4.
  • The low byte comes first (little-endian). So FF E4 is written as E4 FF. A program reading the file has to know that, or −28 becomes a completely different number.
  • The position is the meaning. Nothing next to these bytes says “Pz-Oz” or “this is 06:47 in the morning”. A program knows it because every record has the same layout: header first, then records of 18,240 bytes, and inside each record first 3,000 numbers of Fpz-Cz, then 3,000 of Pz-Oz. Lab 9a walks through that layout in 3D.

6. From numbers to rhythm: speed and size

So the file has only numbers. Where does “alpha” come from? From two things you can measure in them:

  • Speed: how many times a second the line goes up and down. That is the frequency, in hertz (Hz). One wave per second is 1 Hz.
  • Size: how far it goes up and down, in µV.

The bands have names. This page uses the default bands of YASA, an open-source sleep-analysis tool: delta 0.5–4 Hz, theta 4–8 Hz, alpha 8–12 Hz, sigma 12–16 Hz and beta 16–30 Hz. Other sources draw the borders slightly differently.

First, by counting. Below are 2 seconds awake and 2 seconds in deep sleep (N3), both scored by the technician. Every red mark is a place where the line goes up through its middle, once per wave.

Each red mark is one place where the line goes up through its middle: one mark per wave. The lighter band is the first second.

Awake, you count about 10 waves a second: alpha. In deep sleep, 1 or 2 a second: delta, and much bigger (look at the µV on each). Counting is a good intuition, but a rough one. On a big slow wave, small fast ripples ride along, and a simple counter can mistake them for waves. If you count every little peak instead of upward passes through the middle, deep sleep also comes out at 7 to 12 “waves” a second.

Then properly: the spectrum. A spectrum takes a stretch of signal and splits it into speeds: how much of the signal goes up and down once a second, twice a second, and so on up to 30. The method used here (Welch’s method) cuts the 30-second page into 4-second pieces, takes the spectrum of each and averages them.

Share of the power between 0.5 and 30 Hz in each band, for the whole 30-second page.

Awake, this page has a clear peak just above 8 Hz, and alpha holds about half the power. In deep sleep almost all the power is below 4 Hz, in delta. That difference, computed from nothing but the stored numbers, is what a person sees by eye when scoring, and what a classifier gets as input.

7. Where this goes next

  • Lab 9a: Open a real night opens the whole file in your browser. Under the viewer, the same spectrum is computed live for whatever page you’re looking at: press “first N3”, then “first REM”, and watch the bands change.
  • The classifiers in lesson 9 start here. DreamentoScorer and eegUsability compute numbers like these band shares for every epoch and learn from them; ezscore-f is a deep network that learns from the raw numbers directly.

What this doesn’t show

  • One channel of one night, and two hand-picked pages: the awake page with the clearest alpha in this night, and the N3 page with the most delta. Most pages are less clear than these.
  • Not every awake page shows alpha. In this night, awake pages average about 19% alpha power on Pz-Oz; this one has 54%.
  • The figures in steps 2 and 3 change the real data to show an idea. They are not what any real recorder would produce.

Sources

  • Electrode positions and names. Seeck, Koessler, Bast, Leijten, Michel, Baumgartner, He and Beniczky (2017), The standardized EEG electrode array of the IFCN, Clinical Neurophysiology 128(10):2070–2077, https://doi.org/10.1016/j.clinph.2017.06.254: midline percentages (“Fpz (10% from the nasion) … Oz (20% from P and 10% anterior to the inion)”), the letters and “z (for zero)”. The 10-20 system itself: Jasper (1958), The ten-twenty electrode system of the International Federation, Electroencephalography and Clinical Neurophysiology 10(2):371–375 (the ACNS guideline cites pages 367–380; we could not check the original).
  • Why two electrodes. Yao, Qin, Hu, Dong, Bringas Vega and Valdés Sosa (2019), Which Reference Should We Use for EEG and ERP practice?, Brain Topography 32(4):530–549, open access, https://doi.org/10.1007/s10548-019-00707-x: a channel records “the potential differences of two electrodes”; “there is no electrically neutral site on the head or body surface”; bipolar recordings are “less sensitive to signal from deep neural source”. Kane et al. (2017), A revised glossary of terms most commonly used by clinical electroencephalographers, Clinical Neurophysiology Practice 2:170–185, open access, https://doi.org/10.1016/j.cnp.2017.07.002: a channel shows “potential differences between a pair of electrodes”; differential amplifiers give “markedly reduced amplification of common mode signals”; and alpha rhythm: over “the posterior regions of the head, generally with maximum amplitudes over the occipital areas”, “best seen with the eyes closed”.
  • The 3D brain. The CC0 atlas the Brain Atlas game uses, from OpenNeuro dataset ds006128, subject sub-01 (CC0 1.0), https://doi.org/10.18112/openneuro.ds006128.v1.0.11. The head around it is our own simplified oval.
  • The data. Sleep-EDF Expanded, PhysioNet, Open Data Commons Attribution License v1.0: https://doi.org/10.13026/C2X676. Original paper: Kemp, Zwinderman, Tuk, Kamphuisen and Oberyé (2000), IEEE Transactions on Biomedical Engineering 47(9):1185–1194. Electrode positions Fpz-Cz and Pz-Oz as named on the PhysioNet page: https://physionet.org/content/sleep-edfx/1.0.0/.
  • The file format. EDF: Kemp, Värri, Rosa, Nielsen and Gade (1992), Electroencephalography and Clinical Neurophysiology 82:391–393. EDF+: Kemp and Olivan (2003), Clinical Neurophysiology 114:1755–1761. Specs: https://www.edfplus.info/specs/edf.html, which describes each sample as “a 2-byte integer in 2’s complement format”, and https://www.edfplus.info/specs/edfplus.html, which says samples are little-endian.
  • The bands. YASA, yasa.bandpower, default bands in the documentation of version 0.8.1: https://yasa-sleep.org/generated/yasa.bandpower.html. YASA paper: Vallat and Walker (2021), eLife 10:e70092: https://doi.org/10.7554/eLife.70092.
  • Our own checks on the file. The stored numbers and bytes were read straight from SC4001E0-PSG.edf and match what MNE-Python reads (−3.14, −3.43, −0.64 µV for the first three). The awake page starts 52,470 s into the recording, the N3 page 35,040 s. The 54% and 5% alpha for Pz-Oz and Fpz-Cz on the awake page come from the spectrum in Lab 9a, which matches SciPy. The spectra use Welch’s method (SciPy, 4-second pieces) on those two pages; the 19% average comes from all awake pages within the night, from 30 minutes before the first sleep to 30 minutes after the last.