Amplifiers, sampling and recording
Differential amplification, acquisition metadata, events and triggers, clock sync, and the common file formats.
Prerequisites: L0.2 · Electrodes, montages and the 10-20 system
4 claims on this page are unverified. TODO(confirm) marks a specific statement the author has not yet checked against a
primary source. Everything else on this page has been reviewed. Treat a marked claim as
provisional and go to the cited source rather than quoting the sentence.
Objectives
- Explain differential amplification and common-mode rejection
- Read acquisition metadata: sampling rate, resolution, hardware filters
- Explain events, triggers, annotations and clock sync
- Recognize the main EEG file formats
Why this matters
Between the scalp and your first plot sits an amplifier, an analog-to-digital converter, a set of hardware filters, a clock, and a file format, each of which has already made decisions about your data. The sampling rate in the header does not tell you the usable bandwidth; the trigger channel does not tell you when the stimulus appeared; the file’s timestamps do not guarantee that no samples were lost. Every one of these is a documented failure mode in real public datasets. This lesson teaches you to read what the acquisition system recorded about itself, and to check it.
Concepts
Differential amplification and common-mode rejection
An EEG amplifier does not measure the potential at an electrode; it measures the difference between two inputs, electrode and reference, and amplifies that. Any signal that is identical at both inputs, the common-mode signal, is subtracted away. Mains interference coupled onto the whole body is the classic common-mode signal, and the microvolt brain signal is the differential one. How well an amplifier removes the common-mode part is its common-mode rejection ratio (CMRR), quoted in decibels (TODO(confirm) typical values the author wants quoted for research amplifiers).
Rejection is only as good as the balance of the two inputs. If the two electrodes have very different impedances, the common-mode signal reaches the amplifier with different amplitudes at the two inputs, so part of it no longer cancels and appears as line noise in that channel. That is the practical reason impedance is checked (L0.2). The ground electrode gives the amplifier its zero for this subtraction; without it the common-mode voltage can exceed the amplifier’s input range.
DC versus AC coupling, and the hardware high-pass
The electrode–skin interface produces slowly varying offsets of many millivolts, thousands of times larger than the EEG. An AC-coupled amplifier removes them with a hardware high-pass filter (a cutoff on the order of 0.1 Hz or higher) before digitization; a DC-coupled amplifier digitizes from 0 Hz with a large enough input range to hold the offset. The choice is written into the data forever: an AC-coupled recording has already lost its slowest content, and a DC recording carries drift you will have to handle yourself. The curriculum’s datasets span both: ds-eegbci was recorded with no hardware filters at all; ds-iowapd carries a 0.1 Hz online high-pass; ds-lemon’s raw release is band-limited to 0.015–1000 Hz; ds-dortmund has a 250 Hz online low-pass and no online high-pass. Read the header, then read the dataset description, because headers do not always know.
Bit depth and microvolts per least-significant bit
The analog-to-digital converter turns a voltage into an integer. Its resolution is the input range divided by the number of levels: for a range of ±V volts and b bits, one least-significant bit (LSB) is 2V / 2^b. A ±5 mV range at 16 bits gives about 0.15 µV per LSB; the same range at 24 bits gives about 0.0006 µV per LSB (these are arithmetic illustrations, not device specifications). Sixteen bits is enough for an AC-coupled system whose offsets have been removed; DC systems with large input ranges rely on 24-bit converters so that the microvolt signal is still resolved on top of the millivolt offset. File formats carry this scaling: EDF stores 16-bit integers with a physical-minimum/maximum calibration in the header, BDF stores 24-bit integers, and a wrong calibration field makes every trace wrong by a constant factor.
Anti-alias filtering, and why bandwidth is not Nyquist
Sampling at rate fs can represent frequencies only up to fs/2, the Nyquist frequency; anything above it does not disappear but aliases, reappearing at a lower frequency indistinguishable from real content. So every acquisition system low-pass filters the analog signal before digitizing it. That hardware anti-alias filter is usually set well below Nyquist, and consumer systems often decimate from a high internal rate after a low-pass that ends far below the output rate. The consequence is a rule you will use for the rest of the curriculum: the sampling rate does not tell you the usable bandwidth. ds-arithmetic is sampled at 500 Hz but its descriptor reports a “30 Hz cut-off”; the consumer-headset datasets in the directory output 128 or 256 Hz samples from hardware whose bandwidth is about 43 Hz and which includes built-in mains notches (§10.9). Level 1 makes aliasing quantitative; the pitfall entry on hardware bandwidth is the one to remember here.
Line-noise pickup
Mains interference at 50 Hz or 60 Hz (by country; ds-brainlat mixes both within one dataset) reaches the recording by capacitive coupling from cables and the environment, through ground loops, and through any imbalance that defeats common-mode rejection. It shows as a sharp spectral line plus harmonics. Some systems remove it with a hardware notch before the data are stored, leaving a hole in the spectrum (ds-arithmetic at 50 Hz, ds-mouse at 60 Hz, the consumer sets); others leave it in (ds-eegbci, ds-lemon, ds-respect, ds-pearl-neuro). Both are facts to read from the description before L1.6 tells you how to remove what is left.
Events, triggers, annotations and clock synchronization
An event is a time-stamped label. It reaches the file in one of three ways:
- Hardware triggers: a digital code (a TTL pulse or a bit pattern) sent by the stimulus computer into a dedicated trigger input of the amplifier and sampled with the same clock as the EEG. This is the most precise route, because the trigger and the data share one clock.
- Software markers: events written by the acquisition software from messages it received, timestamped with the acquisition computer’s clock.
- Annotations: labelled time spans (onset, duration, description) added during or after recording: bad segments, block boundaries, eyes-closed periods. MNE represents both events and annotations; annotations carry durations, events do not.
Two timing errors follow from this architecture, and both have pitfall entries. Trigger latency: the trigger marks when the computer sent the stimulus, not when the screen displayed it or the sound reached the ear; monitor refresh, graphics buffering and audio latency add a delay that is usually constant within a setup but differs between labs. The only measurement that settles it is a photodiode on the screen (or a microphone at the speaker) recorded as an extra channel, whose onset can be compared with the trigger directly. Dropped samples and clock drift: when the stimulus stream and the EEG stream are timestamped by different clocks, or when the acquisition buffer overflows, samples are lost or the two clocks diverge, and events drift relative to the data across the recording. Multi-stream systems (LSL and its XDF file format) address this by recording every stream’s clock offsets so that streams can be aligned afterwards, provided nothing was dropped.
File formats you will meet
| Format | Typical content | Notes | MNE reader |
|---|---|---|---|
| EDF / EDF+ | 16-bit integers with physical scaling; annotations in EDF+ | ds-eegbci, ds-srm, ds-dortmund, ds-hup | mne.io.read_raw_edf |
| BDF | 24-bit BioSemi variant of EDF | status channel carries the triggers | mne.io.read_raw_bdf |
| BrainVision | .vhdr header, .vmrk markers, .eeg binary | ds-lemon raw, ds-respect | mne.io.read_raw_brainvision |
| FIF | MNE’s native format | info, data, annotations in one file | mne.io.read_raw_fif |
EEGLAB .set / .fdt | MATLAB structure plus binary data | ds-iowapd, ds-lemon preprocessed | mne.io.read_raw_eeglab |
| XDF | multi-stream container written by LSL | per-stream clocks and offsets | pyxdf (third party) |
| Vendor CSV exports | one row per sample, columns per channel and often vendor-derived extras | the consumer sets in the directory interleave raw and derived columns (§10.9) | pandas, then mne.io.RawArray |
Whatever the format, the loader produces the same object, and its info is where you read the acquisition metadata: sfreq (sampling rate), highpass and lowpass (the hardware filter settings the file claims), nchan and channel types, bads, and meas_date. Treat every one of those values as a claim to be checked, not a fact: the header’s high-pass and low-pass fields are frequently defaults written by the converter rather than the amplifier’s settings, and L0.6 shows a file whose header sampling rate is simply wrong.
The first time you open a file from a new system, do three checks that take a minute: compute the sampling rate from the number of samples and the recording duration and compare it with the header; plot the trigger channel next to the data and look at the spacing of events; and look at the spectrum up to the Nyquist frequency for the knee where the hardware bandwidth ends. Each check catches a class of error that no later processing can undo.
The data behind this lesson
- The notebook loads each spine dataset in its native format:
ds-eegbci(EDF+),ds-lemonraw (BrainVision) andds-erpcore(format and accessTODO(confirm), §13 item 22; if it cannot be fetched,ds-brain-invadersstands in).ds-iowapd(EEGLAB) supplies a fourth format. - The trigger-offset exercise needs a recording with a photodiode channel. No spine or directory dataset documents one (TODO(confirm) — §6 L0.3), so the exercise uses a synthetic recording with a known stimulus–trigger offset, generated by the notebook or by
data/scripts/(a synthetic file carriessynthetic: true,derived_fromand amodificationslist in its sidecar, §4.5). The exercise says so; the answer key comes from the notebook. The trigger-offset pitfall’s figure shows such a recording with a planted 23 ms offset; the exercise’s own value need not be the same.
Explore
Set a signal with one component well above half the sampling rate and watch its samples trace out a slower wave; switch the anti-alias filter on and watch that component vanish before sampling rather than fold. Then lower the sampling rate until a component you care about is lost, and note that the reconstruction from the samples matches the continuous signal only while the sampling theorem holds. The spectrum before and after sampling makes the folding explicit; L1.1 gives the arithmetic.
Practice
Amplifiers, sampling and recording: native formats, headers, events, timing, and a photodiode-measured trigger offset nb-0-3-first-load
The notebook loads one file from each spine dataset in its native format, prints info, lists channel types, counts events per code, checks for timing gaps between the first and last sample, and loads the synthetic photodiode recording whose stimulus–trigger offset the exercise asks for.
Exercises
Exercise ex-0-3-trigger-offset
NumericThe notebook's synthetic recording (a labelled synthetic file with a planted, known offset) contains a trigger channel and a photodiode channel. For each trigger, measure the delay from the trigger to the photodiode onset and report the mean offset (positive = stimulus appears after the trigger).
Pitfalls
Uncorrected stimulus–trigger latency
- Symptom
- Components shifted by a constant; latencies differ between labs.
- Cause
The trigger records when the stimulus computer sent the stimulus, not when it reached the subject. Between the two sit the monitor’s refresh cycle and its response time (a stimulus sent just after a refresh waits for the next one), graphics buffering, audio-driver and amplifier latency for sounds, and the time the acquisition system takes to register a software marker. Each contributes a delay th…
- Detect
- Record a photodiode taped to the screen (or a microphone at the speaker) as an extra channel in a pilot session, and measure the delay from each trigger to the onset of the sensor signal: the mean is the offset, the spread is the jitter. - Check the acquisition metadata and the lab’s documentation for a stated offset; if none is stated, assume the offset is unknown, not zero. - Compare an early…
- Fix
- Measure the offset with a photodiode or microphone for each setup, and store it with the dataset (EEG-BIDS has a place for it: the StimulusOnsetDelay style of metadata in the events sidecar, or a documented correction in the dataset description; TODO(confirm) the exact BIDS field the author wants named). - Shift the event onsets by the measured offset when loading (mne.Annotations or the events…
Dropped samples and clock drift
- Symptom
- Events drift relative to the data across the recording.
- Cause
Two mechanisms, often together. Dropped samples: the acquisition buffer overflows (a busy computer, a slow disk, a wireless link) and a block of samples is lost without a gap being written; every later sample is now earlier in the file than it was in time, by the length of the dropped block, and events timestamped by a separate clock no longer match. Clock drift: two devices with their own oscill…
- Detect
- Compare the sample count with the sampling rate times the recorded duration (from an independent clock: the file’s start and end timestamps, or the stimulus log). - Plot the interval between successive periodic events (a fixed-rate stimulus, a clock marker) across the recording: dropped samples show as a jump, drift as a slope. - Look for discontinuities in the data at the moment of a drop: an…
- Fix
- Prevent it at acquisition: hardware triggers on the amplifier’s own clock, adequate buffers, a wired link, and a periodic hardware sync pulse recorded in both streams. - For drift with a known reference (a sync pulse or periodic marker), resample or linearly rescale the event times to the EEG clock; LSL-style recordings store the offsets needed to do it. - For dropped samples that can be locate…
Usable bandwidth far below the Nyquist frequency
- Symptom
- "Gamma" analysed at 128 Hz output from a headset whose hardware rolls off near 43 Hz; a 500 Hz recording with a ~30 Hz hardware low-pass.
- Cause
The sampling rate sets the Nyquist frequency (half the rate), which is the highest frequency the file could represent. It says nothing about the highest frequency the amplifier passed. Anti-alias and other hardware low-pass filters sit well below Nyquist by design; consumer devices decimate from a high internal rate after a low-pass that ends far below the output rate. The band between the hardwa…
- Detect
- Read the device specification and the dataset descriptor for hardware bandwidth, not just the sampling rate. - Compute a PSD up to Nyquist on a quiet segment: a knee after which the spectrum falls steeply, then flattens onto a floor, marks the ceiling. The knee is at the same frequency in every channel and every subject. - Check that the spectrum above the knee shows no physiology: no reactivit…
- Fix
- Restrict every analysis to the hardware passband and state that passband in the methods. - For decimation and resampling, the anti-alias filter must sit below the new Nyquist frequency (L1.1) — and the usable band is still bounded by the hardware ceiling, whichever is lower. - When a research question needs a band the device cannot deliver, change the device, not the analysis. - Teach it as a f…
In other tools
In other toolsEEGLAB · FieldTrip — names only
The equivalents of what this lesson does, for a reader who works in another toolbox. Function names only: their own documentation is the place to learn how to call them.
EEGLAB
pop_biosigEEGLABpop_loadbvbva-io plugin (install separately)
FieldTrip
ft_read_headerFieldTripft_read_eventFieldTrip
Names checked 2026-09-18 against EEGLAB 2026.0.0 (plugins at the versions in EEGLAB’s own plugin list) and FieldTrip 20251218.
Reading
- Luck (2014). An Introduction to the Event-Related Potential Technique, 2nd ed.. unverified
- Pernet et al. (2019). EEG-BIDS. unverified