A comprehensive, interactive web-based tool for understanding EEG forward modeling. This advanced simulation visualizes how neural sources (modeled as current dipoles or distributed active regions) generate electrical potentials across the scalp, bridging the gap between underlying brain activity and the waveforms measured by EEG.
Live Demo | Zero Dependencies | Offline Capable
This project is a significantly enhanced fork of the original EEG-Dipole-Demo by dbrang, extended with comprehensive scientific documentation, advanced features, and educational materials.
- Overview
- Key Features
- Quick Start
- Understanding EEG Forward Modeling
- User Interface Guide
- Source Types
- Reference Configurations
- Signal Quality Simulation
- Time Series & Animation
- 3D Brain Visualization
- Pan & Zoom Controls
- Keyboard Shortcuts
- Data Export
- Technical Details
- Educational Use Cases
- Contributing
- License
Understanding EEG requires grasping two fundamental problems:
- Forward Problem: Given a known neural source, calculate the resulting scalp potentials
- Inverse Problem: Given measured scalp potentials, estimate the underlying source(s)
This tool provides a real-time interactive visualization of the Forward Problem, enabling students, researchers, and engineers to develop intuition about:
- How dipole position, orientation, and strength affect scalp topography
- The difference between radial and tangential sources
- Volume conduction effects through brain, skull, and scalp
- Reference electrode configurations and their impact on signals
- Common mode rejection and DRL circuit behavior
- 3D Brain View: Interactive WebGL rendering with orbit controls, showing sources in anatomical context
- Coronal Slice: Cross-sectional view with MRI background, ideal for understanding depth effects
- Scalp Topomap: Classic 2D interpolated heatmap using the 10-20 electrode system
- Single Dipoles: Point-source current dipoles with adjustable position, amplitude, and orientation
- Active Regions (Blobs): Distributed Gaussian clusters simulating cortical patches
- Multiple Sources: Add, duplicate, and manage multiple simultaneous sources
- Average Reference: Software-based common average reference
- Single Electrode Reference: Traditional linked-ears or mastoid reference
- CMS/DRL (Design 1): Hardware common-mode sense with driven right leg
- Virtual CMS/DRL (Design 2): Reference electrode with computed CMS and DRL injection
- Gaussian Noise: Adjustable baseline noise level
- Electrode Impedance: Per-electrode impedance modeling with random or custom values
- Mains Hum: 50/60 Hz powerline interference simulation
- Body Transfer Function: Phase lag and attenuation modeling for DRL stability analysis
- CSV Upload: Import time series data to animate source activity
- Channel Mapping: Map CSV channels to individual sources
- Playback Controls: Play, pause, seek, loop, and speed adjustment
- Dark/Light Mode: Toggle between themes with persistent preference
- Pan & Zoom: Navigate 2D views with scroll wheel and shift-drag
- Responsive Design: Works on desktop and tablet screens
No build process, no installation, no server required.
- Download or clone the repository
- Open
index.htmlin any modern browser (Chrome, Firefox, Safari, Edge) - Interact with the controls to explore EEG forward modeling
# Clone the repository
git clone https://github.com/AdityaAsopa/EEG-Forward-Model.git
# Open in browser
open index.htmlEEG forward modeling calculates scalp potentials from known neural sources using the quasi-static approximation of Maxwell's equations. For a current dipole in a homogeneous conductive medium:
V(r) = (1/4ΟΟ) Γ (p Β· R) / |R|Β³
Where:
V(r)= potential at point rΟ= conductivity of the mediump= dipole moment vectorR= vector from dipole to measurement point
The head is modeled as concentric shells (brain, skull, scalp) with different conductivities:
- Brain: ~0.33 S/m (highly conductive)
- Skull: ~0.0042 S/m (poorly conductive - 80x less than brain)
- Scalp: ~0.33 S/m (similar to brain)
The skull acts as a spatial low-pass filter, smearing and attenuating the neural signals.
- Radial dipoles (pointing toward the scalp) produce focal, symmetric patterns
- Tangential dipoles (parallel to the scalp) produce dipolar patterns with positive and negative poles
- Most cortical activity is tangential (perpendicular to the cortical surface)
| Section | Description |
|---|---|
| Source Mode | Toggle between single dipole and blob (active region) modes |
| Sources | Add, duplicate, delete, and manage sources with position inputs |
| Preset Locations | Jump to anatomically-relevant positions (motor cortex, visual, etc.) |
| Dipole/Blob Controls | Adjust amplitude, angle, radius, orientation |
| Y Position | Move source anterior-posterior (into/out of the coronal plane) |
| Time Series | Upload and control animated source activity |
| View Options | Toggle labels, values, MRI overlay, auto-scaling |
| Signal Quality | Add noise, impedance variations, mains hum |
| Reference & DRL | Configure reference scheme and DRL parameters |
| Electrode Montage | Enable/disable individual electrodes |
| Export | Download electrode values as CSV |
| View | Description |
|---|---|
| 3D Brain View | Interactive WebGL rendering with orbit, pan, zoom |
| Coronal Slice | Cross-sectional anatomical view with electrodes |
| Scalp Topomap | 2D interpolated potential map |
A point-source current dipole representing a small, coherent patch of cortical activity.
Parameters:
- Position (x, y, z): Location in normalized coordinates (-1 to 1)
- Amplitude: Dipole moment magnitude (arbitrary units)
- Angle: Orientation in the coronal plane (0Β° = right, 90Β° = up, 180Β° = left)
A Gaussian-distributed cluster of coherent dipoles, better representing extended cortical activation.
Parameters:
- Position (x, y, z): Center location
- Radius: Spatial extent (sigma of Gaussian)
- Strength: Overall activity magnitude
- Theta (ΞΈ): Polar angle from vertical (0Β° = up, 90Β° = horizontal)
- Phi (Ο): Azimuthal rotation angle
Sources automatically turn INACTIVE (shown in red) when positioned outside the brain volume. Only sources inside the brain ellipsoid contribute to scalp potentials.
No reference applied. Shows absolute potentials (rarely used in practice).
Subtracts the mean of all electrode values. Common for research applications.
V'α΅’ = Vα΅’ - (1/N)βVβ±Ό
Subtracts the value at a chosen reference electrode (e.g., Cz, linked mastoids).
V'α΅’ = Vα΅’ - Vα΅£βf
Hardware-based common mode rejection with dedicated electrodes:
- CMS (Common Mode Sense): A dedicated electrode measures common mode noise
- DRL (Driven Right Leg): An integrator amplifies and inverts the CMS signal
- The inverted signal is injected back into the body via the DRL electrode
- All recording electrodes are referenced to CMS
Configurable Parameters:
- CMS electrode position (10-20 location)
- DRL electrode position (typically forehead or mastoid)
- DRL gain, time constant, injection efficiency
- Body transfer function (attenuation, phase lag)
- Upload custom frequency-dependent LUT
Alternative design where:
- A Reference electrode provides the actual signal reference
- Virtual CMS is computed by averaging all electrode values
- DRL injects the inverted virtual CMS signal
The DRL feedback loop can become unstable if phase margin is too low. The UI displays:
- Phase Margin: Degrees of margin before instability (>45Β° is safe)
- Stability Indicator: Green = stable, Red = warning
Add random baseline noise to simulate thermal and biological noise sources.
Model the effects of poor electrode contact:
- Higher impedance = signal attenuation
- Impedance mismatch = increased common mode pickup
- Randomize impedances to simulate realistic conditions
Simulate powerline interference:
- Select 50 Hz (Europe/Asia) or 60 Hz (Americas)
- Adjust amplitude to see DRL rejection in action
Upload CSV files with time series data:
time,channel1,channel2,channel3
0.000,0.5,0.3,-0.2
0.004,0.6,0.4,-0.1
0.008,0.7,0.5,0.0
...Requirements:
- First column must be time (seconds)
- Subsequent columns are channel values
- Header row with channel names is recommended
Map each CSV channel to one or more sources:
- Click the dropdown next to each channel
- Select which source(s) should be modulated by that channel
- Sources without mapping remain static
| Control | Function |
|---|---|
| βΆ Play | Start animation |
| βΉ Stop | Stop and reset to beginning |
| π Loop | Toggle looping |
| Timeline | Seek to any time point |
| Speed | 0.25x to 4x playback speed |
The 3D view uses Three.js to render:
- Semi-transparent brain mesh (GLB model)
- Source positions as spheres/arrows
- Color coding for inside/outside brain
| Action | Method |
|---|---|
| Rotate | Click and drag |
| Zoom | Scroll wheel |
| Pan | Right-click drag |
| Reset | Click "Reset" button |
| Preset Views | Front, Top, Side buttons |
- Show Brain: Toggle brain mesh visibility
- Opacity: Adjust brain transparency
Both 2D views (Coronal and Topomap) support pan and zoom:
| Action | Method |
|---|---|
| Zoom In | Scroll up or click + |
| Zoom Out | Scroll down or click - |
| Pan | Hold Shift + drag |
| Reset | Click β² button |
Zoom range: 50% to 300%
| Key | Action |
|---|---|
Delete / Backspace |
Remove selected source |
A |
Rotate counter-clockwise |
D |
Rotate clockwise |
W |
Increase amplitude/strength |
S |
Decrease amplitude/strength |
Download a CSV with electrode names and current potential values.
Download the full animation as CSV with all time points and all electrodes.
Output Format:
time,Fp1,Fp2,F7,F3,Fz,F4,F8,...
0.000,0.123,-0.456,0.789,...
0.004,0.234,-0.567,0.890,...EEG-Forward-Model/
βββ index.html # Main HTML structure
βββ css/
β βββ styles.css # Styling (dark/light themes)
βββ js/
β βββ main.js # Application entry point
β βββ core/
β β βββ physics.js # Forward model calculations
β β βββ math.js # Math utilities, color mapping
β β βββ electrodes.js # 10-20 electrode positions
β β βββ reference.js # Reference schemes, DRL
β β βββ presets.js # Anatomical preset locations
β βββ models/
β β βββ state.js # Application state management
β β βββ dipole.js # Dipole model
β β βββ blob.js # Blob model
β β βββ timeseries.js # Time series handling
β βββ views/
β β βββ coronal.js # Coronal slice rendering
β β βββ topomap.js # Topographic map rendering
β β βββ brain3d.js # 3D WebGL view
β βββ ui/
β β βββ controls.js # UI control bindings
β β βββ timeline.js # Playback controls
β β βββ file-upload.js # CSV upload handling
β βββ export/
β βββ csv.js # CSV export utilities
βββ assets/
βββ coronal-slice.png # MRI background
βββ brain_human.glb # 3D brain model
Dipole Potential:
V = (p Β· R) / |R|Β³Blob (Gaussian Cluster):
- 27-point 3D grid sampling
- Gaussian-weighted contributions
- Normalized to preserve total dipole moment
Brain Boundary:
- 3D ellipsoid: center (0, 0, -0.05), radii (0.75, 0.80, 0.70)
- Sources outside are inactive (no contribution)
- Three.js v0.160.0: 3D rendering (loaded from CDN)
- GLTFLoader: Brain model loading
- OrbitControls: 3D camera interaction
All other functionality is vanilla JavaScript with no build tools required.
- Chrome 90+
- Firefox 88+
- Safari 14+
- Edge 90+
- Forward vs. Inverse Problem: Demonstrate why source localization is ill-posed
- Dipole Orientation: Show radial vs. tangential source patterns
- Volume Conduction: Visualize how skull attenuates and spreads signals
- Reference Effects: Compare different montages and their artifacts
- Electrode Placement: See how position affects recorded signals
- Impedance Effects: Understand importance of good electrode contact
- Artifact Recognition: Recognize patterns from different noise sources
- DRL Circuit Design: Explore loop gain, phase margin, stability
- CMRR Optimization: Tune parameters for optimal noise rejection
- Transfer Functions: Upload and test custom DRL characteristics
- Source Modeling: Prototype source configurations before experiments
- Montage Design: Evaluate electrode placement strategies
- Data Quality: Understand noise sources and mitigation
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- No build tools required - edit files directly
- Test in multiple browsers before submitting
- Follow existing code style and documentation patterns
Distributed under the MIT License. See LICENSE for more information.
- Three.js for 3D rendering capabilities
- The neuroscience and EEG research community for inspiration
- All contributors and users providing feedback
Developed for educational purposes in Neuroscience, Signal Processing, and Biomedical Engineering.
Questions? Issues? Open a GitHub issue or reach out to the maintainers.
