Can brainwaves explain a brain scan?
EEG hears the brain's electricity a thousand times a second. fMRI watches its blood, slowly. I built a pipeline to test whether one could explain the other, with one rule above everything else: it had to be able to tell me no.
It did. Here is why.
Eyes closed, inside the magnet. The idle rhythm is loud, and the heartbeat is still louder.
Does the brain's explain second-to-second changes in the , beyond what "eyes open or closed" already explains?
The fMRI. 120 clean snapshots, almost no head movement, good signal quality.
Two separate things. Nobody recorded which 5 of 125 snapshots were thrown away, so the timing has six possible answers. And nothing could scrub out the without mangling the brain signal underneath.
I stopped before fitting a single model. That is a bounded negative result, not a verdict on the data, and the tooling carries over to the next dataset.
Two cameras on one brain.
The dots are all fMRI ever sees. To compare the two, the EEG has to be delayed and smeared by the same curve, then read off at the exact moment of each dot. That last step needs the dots' timestamps. Hold that thought.
- Measures
- Tiny voltages when big groups of neurons fire in sync
- Speed
- 1,000 readings a second in this dataset
- Weak at
- Where. And inside an MRI it picks up huge noise from the scanner and the heart
- Here
- 32 electrodes plus one heart (ECG) channel
- Measures
- How oxygenated the blood is, cube by cube
- Speed
- One snapshot every 2 s. The response peaks about 5 s after the activity
- Strong at
- Where, down to 4 mm cubes
- Here
- A 64 x 64 x 35 grid, 120 snapshots
Does EEG add anything the eyes don't already tell you?
Slice sizes are made up to show the idea. The real ones were never computed.
Add the idle rhythm, delayed to match the blood response. The whole project is the size of this last slice, measured on data the model never trained on.
= (Model 2) minus (Model 1), scored on stretches of time the model never saw. Near zero would read as "no evidence EEG adds anything," which is not the same as "EEG and blood are unrelated."
Weigh a known 1 kg first.
You don't trust a scale until it reads a known weight correctly. My known weight: when the idle rhythm rises, blood oxygen in visual cortex tends to fall (Goldman et al., 2002; Laufs et al., 2003). That was the , called Q0. If the pipeline couldn't find it, nothing it said about theta or beta would count.
Five contiguous test blocks, with 3 snapshots (6 s) dropped from training on each side, so the model never trains on the immediate neighbours of what it is tested on. That is .
Slide the EEG in time against the blood signal, 200 times, and rerun. That breaks the real alignment but keeps the EEG's own smoothness, which gives an honest .
Ridge regression, a linear model with a penalty that stops it overfitting correlated inputs. The penalty is picked from 0.1, 1, 10, or 100 using training data only.
All of this was built and tested on simulated data. None of it was ever pointed at real EEG and blood data, for reasons chapters 04 and 05 explain.
The rules I set before touching the data.
- 01Stay blind
While deciding how to process EEG and line up timing: no blood values, no eyes-open/closed effect sizes, no model results.
- 02Freeze before looking
Every protocol and pass/fail line went into version control before any result existed. None was loosened afterwards.
- 03Calibrate somewhere else
Methods were tuned on separate recordings, never on the one that would be analysed.
- 04Use known answers
Where possible, test on clean data with real noise added, so the right output is known.
- 05Lock the door
Code that touches the target checks a hashed authorization file. If calibration failed, it refuses to run.
- 06"Can't tell" is an answer
A stage can return a bounded set of possibilities instead of forcing one.
- 07Raw data never changes
Input files are fingerprinted (SHA-256) before and after every stage.
- 08Negatives stay negative
Null results get reported as null. No reframing.
The scan was fine. Its clock was not.
Then the problem.
Normally the scanner stamps a marker into the EEG file for every , and lining the two up is trivial. This dataset stored zero markers. Zero trigger channels. No events file.
So I rebuilt the clock from the itself. It shows up as a sharp block from 96.2 to 346.4 s, pulsing every 2.0 s, with the 35 Hz slice rhythm about 2,750 times stronger inside the block than outside. Counting the pulses gave 125 complete snapshots. The saved file has 120.
Scanners usually throw away a few at the start. But they could be at the start, the end, or split between both, and nothing in the files says which. Try it:
Four places the answer could have been hiding.
None of them involve brain signals, on purpose. I also tried spotting the save boundary as a step in per-snapshot buzz strength. There was no step.
Subtracting shows where scanner-buzz correction was applied. It covered 121 snapshot-lengths in two pieces (3 + 118), not 120 in a row, because the correction uses a five-snapshot moving template with start-up and end effects.
The EEG files have no events or correction log. All 20 MRI headers say 120 snapshots and have no warm-up field.
The dataset and its paper say hardware markers were used during correction. Not whether they skipped the warm-up snapshots.
The same 3 + 118 split shows up across people. So it is a quirk of the correction workflow, not a marker of what was saved.
Every heartbeat is louder than the brain.
Each beat nudges the head and electrodes a tiny amount and pushes a pulse of blood through the scalp.
Moving a conductor through a strong magnetic field generates a voltage. Physics, not biology.
Bigger than the brain signal, locked to the pulse, and overlapping the exact frequencies alpha lives in.
Here is the trap. Turn the dial.
The fair way to judge a cleaner is the : take clean EEG recorded outside the scanner, add real heartbeat noise, clean it, and see if you get the original back. Scrub too gently and the heartbeat stays. Scrub too hard and you carve into the brain signal.
Too timid. Most of the heartbeat is still in there, drowning the rhythm.
Removing the noise is not the same as getting the signal back.
Four attempts, each narrower than the last.
Every one had its pass/fail lines frozen before it ran. Three channels were flagged as bad along the way (two of them at the back of the head, right where alpha lives) and about 14% of samples were masked out.
Find every heartbeat from the ECG channel (534 of them; two detectors agreed on 99.6% within 40 ms). Then run two textbook cleaners side by side. One unmixes the 32 channels and throws out the 3 sources that look like heartbeat. The other learns the 4 main shapes of the heartbeat blip and subtracts a fitted copy at every beat.
The unmixer cleaned too little. The template cleaned so hard it removed 57% of everything.
| Check | Unmixer (ICA) | Template (OBS4) |
|---|---|---|
| Heartbeat blip reduced (need 25% or more) | 23.4% fail | 98.7% pass |
| Link to the ECG reduced | 11.9% warn | 86.0% pass |
| Total signal removed (must stay under 40%) | 19.2% pass | 57.2% fail |
| Alpha peak shifted | 0.5 Hz pass | 0.5 Hz pass |
| Overall | fail | fail |
ICA missed its floor by 1.6 points. Its confidence interval was positive and most channels improved. The floor stayed at 25%.
Where every stage landed.
It doesn't rest on one borderline number. Four independent approaches failed in consistent ways, and the six-way timing problem would still be there even if one had worked. Going further meant lowering thresholds after seeing failures, or letting the eyes-open/closed labels and blood data into the method. Either one breaks the thing the project was built to protect.
The dataset's own companion paper recovered alpha reasonably well using ICA with condition-aware component picking. This doesn't contradict that. I asked a stricter question: can the signal be picked and validated without the labels or the blood data? Here, it couldn't.
The fMRI, the timing forensics, and the calibration recordings all produced valid work.
ICA, OBS, AAS, hybrids and spatial filters all have their uses. This result is specific to this recording, these controls, these gates.
That question never got asked. Stage 4B never started.
The two things that broke become the entrance exam.
One physical scanner marker per snapshot, a table mapping one EEG sample to every saved snapshot, and clock error within about 10 ms.
Timing guessed from scanner buzz alone, undocumented warm-up deletion, or more than one possible alignment.
An ECG channel, raw data or an auditable cleaning chain, electrode positions, and heartbeat removal plus alpha preservation reproduced blind, before any blood data.
Cleaned-only data with no provenance, no ECG, or tuning on the target only.
Real alpha variation (ideally eyes open and closed), at least one continuous 6-minute run, and at least 240 saved snapshots per person.
Too little continuous data for honest held-out testing.
Public and versioned, a license that allows analysis, open processing code, complete metadata.
A mutable archive, an unclear license, or access behind a data-use agreement.
At least 12 expected usable participants and 10 passing the early stages. 20+ preferred. Power target frozen in advance.
Fewer than 10 possible usable participants.
ds006040 goes first. It is a candidate for an audit, not an accepted dataset.
It keeps the original question intact: eyes open and closed, enough people, long simultaneous runs, ECG, raw EEG, public code, an open license. Two risks have to clear first. The trigger records must prove a unique snapshot mapping at the file level, and heartbeat cleaning must be shown to preserve spontaneous alpha.
28 adults. Separate 6-min eyes-open and eyes-closed runs, ECG, raw and corrected EEG, CC0 license.
Trigger docs are inconsistent (4 s triggers described for a 2 s snapshot interval). Cleaning was validated on a flickering checkerboard, not alpha.
22 adults. Eyes-open rest and movies, marker at every snapshot.
No eyes-closed. A 12 Hz checkerboard response is not spontaneous alpha.
24 adults, 47 sessions. Eyes-open rest and an attention task.
Documented end-marker mismatches. Would need a reframed question.
39 adults. Strong artifact instrumentation (carbon-wire loops).
Needs a data-use agreement. No eyes open/closed.
8 adults, alternating blocks.
Too small to be the main cohort.
33 adults, rest and sleep.
The eyes open/closed scan was never deposited.
The plan, front-loaded so it fails fast.
Prove timing and EEG before spending anything on full fMRI processing. The first smoke test ends after N2.
Pin version, license, fingerprints. Pick 3 pilot subjects without looking at quality.
A one-to-one EEG sample to trigger to snapshot table. Stop if any alternative survives.
Heartbeat removal and alpha preservation against pre-set gates. Freeze one method.
smoke test endsFreeze warm-up removal, slice timing, motion and exclusion rules.
One alpha feature for every subject who passed N1 and N2.
Exact alignment and blood-delay design with run-aware test splits.
Q0, with held-out testing, chance baselines, and replication across subjects.
Only if Q0 works, each with its own quality check.
Most of the machinery survives. None of the outputs do.
The config loader, fingerprinting, report writing, blood-delay math, chance-baseline generators and plotting all move to the next dataset with their tests. The timing machinery, the EGI-specific electrode geometry and every piece of rescue code get retired into the repo history.
Every cleaned EEG file, extracted component and trained filter from these stages is explicitly forbidden from ever entering a model. Kept, not deleted, and never quietly promoted.
There is also enough here for a short negative-methods note, working title: Outcome-blind stopping in simultaneous EEG-fMRI.