Sampling, Nyquist and aliasing
The sampling theorem, alias frequencies, why decimation needs an anti-alias filter, and choosing a rate for a target analysis.
Prerequisites: L0.3 · Amplifiers, sampling and recording
1 claim on this page is 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
- State the sampling theorem
- Predict alias frequencies
- Explain why decimation requires anti-alias filtering
- Choose a sampling rate for a target analysis
Why this matters
Downsampling is the first processing step in many pipelines, because it makes everything after it faster, and it is the step most often done wrong. Take every fifth sample of a 500 Hz recording and you have not thrown away the content above 50 Hz; you have folded it into the band you kept, where it is indistinguishable from brain activity. The same arithmetic explains why a 60 Hz mains harmonic can turn up at 40 Hz, why a 160 Hz recording cannot show you its own line-noise harmonics, and why a headset’s sampling rate says nothing about the frequencies it can record. Twenty minutes with the formula saves years of chasing artifacts that were manufactured by a resampling call.
Concepts
The sampling theorem
A continuous signal that contains no frequencies above B hertz is completely determined by its samples taken at any rate fs greater than 2B; from those samples the continuous signal can be reconstructed exactly (by sinc interpolation). Stated the other way round: a recording sampled at fs can faithfully represent frequencies only up to fs/2, the Nyquist frequency. At 160 Hz (ds-eegbci) the Nyquist frequency is 80 Hz; at 500 Hz (ds-iowapd) it is 250 Hz; at 2500 Hz (ds-lemon raw) it is 1250 Hz.
The condition is strict. A component at the Nyquist frequency is not represented properly (its amplitude depends on its phase relative to the sampling instants), and a real anti-alias filter needs a transition band, so usable content ends somewhat below fs/2 in every practical system.
Aliasing: where a frequency above Nyquist goes
A component above the Nyquist frequency does not vanish when sampled; the samples are exactly consistent with a lower frequency, and that lower frequency is what every later analysis will see. The folded frequency is
f_alias = | f − round(f / fs) · fs |
that is, the distance from f to the nearest integer multiple of the sampling rate. Two worked cases:
- A 140 Hz tone sampled at 200 Hz: the nearest multiple of 200 is 200, so the alias is |140 − 200| = 60 Hz. The samples of a 140 Hz sinusoid and of a 60 Hz sinusoid are identical.
- A 70 Hz component in a 500 Hz recording decimated to 100 Hz without filtering: the nearest multiple of 100 is 100, so it appears at |70 − 100| = 30 Hz, squarely inside the beta band. This is the notebook’s demonstration on
ds-iowapd.
Line noise gives a third case that matters in ds-eegbci: at 160 Hz the mains harmonics at 120 Hz and 180 Hz lie above the 80 Hz Nyquist frequency. If they reached the converter unfiltered they would alias to |120 − 160| = 40 Hz and |180 − 160| = 20 Hz. Whether any such aliased residue is present in the data is TODO(confirm) from the recordings themselves (§6 L1.6); the arithmetic tells you where to look.
Anti-alias filtering, in hardware and in software
Because aliasing happens at the moment of sampling, the only defence is to remove the offending content before sampling. In the amplifier this is a hardware low-pass ahead of the converter (L0.3). In software the same rule applies to decimation: to reduce a 500 Hz recording to 100 Hz you must first low-pass filter it below the new Nyquist frequency of 50 Hz, and only then keep every fifth sample. raw.resample() in MNE does both steps (an anti-alias low-pass followed by resampling), and so do scipy.signal.decimate and scipy.signal.resample_poly; taking data[::5] does neither. The site’s DSP library offers both resample (filtered) and decimateNaive (unfiltered) so that the widget can show you the difference on real data.
Resampling versus decimation. Decimation keeps every n-th sample and so only allows integer rate ratios; resampling interpolates to an arbitrary rate. Both need the anti-alias filter when the rate goes down; going up needs no filter (there is nothing above the old Nyquist frequency to fold) but creates no new information either. Resampling also shifts event samples: MNE resamples the stimulus channel and annotations along with the data, but any event table you keep separately must be converted with the same ratio, and rounding can move an event by a sample.
Choosing a sampling rate
The rate is set by the highest frequency you will analyse plus room for the anti-alias filter’s transition band, not by habit and not by the maximum your amplifier offers:
- For ERPs and oscillations up to the beta band, 250 Hz is generous; for gamma and for high-frequency oscillations, higher rates and, above all, an amplifier whose hardware bandwidth actually extends that far.
- Record at a higher rate than you need and downsample properly afterwards; you can always throw information away, never recover it.
- Keep enough rate that filter transition bands (L1.5) have room: a 45 Hz low-pass with a wide transition band needs the Nyquist frequency comfortably above it.
And read the hardware bandwidth before believing the rate. ds-arithmetic is nominally 500 Hz but was hardware low-pass filtered near 30 Hz (the descriptor’s wording is ambiguous, and the catalog reads it as a low-pass); the consumer datasets in the directory output 128 or 256 Hz from hardware with about 43 Hz of bandwidth and built-in mains notches (§10.9). In all of them the band between the hardware ceiling and the Nyquist frequency contains attenuated signal and noise, not brain activity.
ds-eegbci cannot host the decimation demonstration: at 160 Hz there is nothing recorded above 80 Hz to fold. The notebook uses ds-iowapd (500 Hz, CC0); ds-lemon raw at 2500 Hz is the alternative. ds-hup is a reminder that a rate can even vary within a dataset (256–1024 Hz across patients), and ds-aszed mixes two amplifiers at 200 and 256 Hz, so harmonizing rates is itself a pipeline step (L2.8).
The data behind this lesson
ds-iowapdsub-001, channel Oz, 10 s at 500 Hz (raw, 0.1 Hz online high-pass, 60 Hz mains with harmonics): the widget’s real snippet and the notebook’s decimation subject. CC0.ds-eegbciS001 R02, channel O1, 10 s at 160 Hz: the counterpart snippet, to show a recording whose usable band is already narrow. ODC-By 1.0.ds-arithmetic(500 Hz, ~30 Hz hardware cut-off, 50 Hz hardware notch): the counter-example that a sampling rate says nothing about bandwidth. ODC-By 1.0.
Explore
Type 140 Hz at a 200 Hz rate and read the alias; then sweep the tone across the Nyquist frequency and watch the alias reflect back. Switch to the real 500 Hz snippet, decimate to 100 Hz with the anti-alias filter off, and find the mains line that has moved: 60 Hz folds to |60 − 100| = 40 Hz. Turn the filter on and it is gone rather than moved.
Practice
Sampling, Nyquist and aliasing: raw.resample() versus naive decimation on a 500 Hz recording nb-1-1-resampling
Downloads from ds-iowapd, ds-arithmetic.
The notebook compares raw.resample() with naive decimation on ds-iowapd, shows a 70 Hz component folding to 30 Hz when 500 Hz is decimated to 100 Hz without filtering, and then plots the PSD of ds-arithmetic up to its Nyquist frequency to find the hardware knee.
Exercises
Exercise ex-1-1-alias-140-at-200
NumericA 140 Hz tone is sampled at 200 Hz with no anti-alias filter. At what frequency does it appear in the sampled data?
Pitfalls
Downsampling without anti-alias filtering
- Symptom
- High-frequency content folds into the band of interest.
- Cause
Keeping every n-th sample of a recording (data[::n]) lowers the sampling rate without removing the content above the new Nyquist frequency. That content does not disappear; it aliases, reappearing at the distance from its true frequency to the nearest multiple of the new rate (L1.1: falias = |f − round(f / fs) · fs|). Decimating 500 Hz to 100 Hz without filtering moves a 70 Hz component to 30 Hz…
- Detect
- Compare PSDs before and after downsampling on the same axes up to the new Nyquist frequency: any feature that is present after and absent before is aliased. - Check the code: raw.resample(), scipy.signal.decimate, scipy.signal.resamplepoly and scipy.signal.resample filter or band-limit; array slicing does not. - Compute where known lines (mains and harmonics) would land under the new rate, and…
- Fix
- Use a resampling routine that includes the anti-alias filter (raw.resample() in MNE, decimate or resamplepoly in SciPy); if you must decimate by hand, low-pass filter below the new Nyquist frequency first, with a transition band that ends below it. - Choose the new rate with room for the filter’s transition band above the highest frequency you will analyse. - Resample events and annotations wit…
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_resampleEEGLAB
FieldTrip
ft_resampledataFieldTrip
Names checked 2026-09-18 against EEGLAB 2026.0.0 (plugins at the versions in EEGLAB’s own plugin list) and FieldTrip 20251218.
Reading
- Cohen (2014). Analyzing Neural Time Series Data. unverified