Skip to content

Simulate ERP — Signal Averaging Demo

Interactive ERP simulator for teaching how trial averaging extracts signals from noise.

Simulate ERP

What it shows

ElementDescription
Grey linesIndividual simulated EEG trials with realistic 1/f background noise
Blue lineTrial-average ERP — clarifies as more trials are added
ComponentsUp to 5 independent ERP components, each shaped as a single cosine lobe (the central peak of a cosine wave, masked to ±π/2) to produce a smooth, bell-like waveform

The core insight: The signal-to-noise ratio of the ERP average scales with √N (where N is the number of trials). Doubling the number of trials improves SNR by ~41%; to halve the noise, you need 4× as many trials.

The background noise uses a realistic human EEG power spectrum (1/f structure), not white noise — so individual trials look like real EEG epochs rather than random static.

This demo builds directly on Signal Example 2: the ERP waveform you see in the average is a real-world instance of multiple frequency components summing together, now embedded in realistic noise.

Things to Try

  • Start with 1 trial and a single active component — the ERP equals the single trial.

  • Add noise and increase trials to watch the ERP "emerge" from the background activity.

  • Activate a second component at a different latency to show how components superpose — and try setting one to a negative amplitude to model typical ERP polarities (N1 negative, P3 positive).

  • Introduce latency jitter to show how trial-to-trial variability smears and attenuates the average — a key confound in real ERP research.

  • Introduce amplitude jitter to show how variability in peak amplitude scales the average downward.

Controls

Each component has its own row of controls in the right panel.

ControlRangeDescription
Number of Trials1–500Trials to average
Noise Amplitude0–20Background 1/f EEG noise level
Active toggle (×5)on/offEnable or disable each component
Freq (×5)0.1–5.0 HzComponent shape (cosine frequency)
Amp (×5)−10 to 10 μVPeak amplitude (negative = typical N-wave polarity)
Latency (×5)0–1000 ms (steps: 10 ms)Peak latency
Amp Jitter (×5)0–20 (Gaussian SD)Trial-to-trial amplitude variability
Lat Jitter (×5)0–50 ms (Gaussian SD)Trial-to-trial latency variability

See Also

Code

julia
using EegFun
EegFun.simulate_erp()