Skip to content

Latest commit

 

History

History
874 lines (608 loc) · 19.3 KB

File metadata and controls

874 lines (608 loc) · 19.3 KB

EEG Dipole Demo v2.0

Forward Modeling Simulator

Team Presentation Handout


Slide 1: Title

EEG Dipole Demo v2.0

Interactive Forward Modeling Simulator

Revolutionizing EEG Education & Engineering

  • Real-time visualization of brain-to-scalp signal propagation
  • Zero dependencies, browser-based, works offline
  • Comprehensive reference electrode simulation
  • 3D brain view with source visualization

"See what the brain sees... on the scalp"


Slide 2: The Problem We Solve

Why Forward Modeling Matters

The EEG Challenge:

  • We measure tiny voltages on the scalp (~1-100 μV)
  • These signals originate from billions of neurons inside the brain
  • Volume conduction distorts and spreads the signals

Two Fundamental Problems:

Problem Question Difficulty
Forward Given a source, what do we measure? Solvable
Inverse Given measurements, where's the source? Ill-posed

This tool visualizes the Forward Problem in real-time.


Slide 3: The Physics

How Neural Signals Reach the Scalp

Point Dipole Approximation:

V(r) = (p · R) / |R|³
  • p = dipole moment (neural current × orientation)
  • R = vector from source to electrode
  • Inverse-cube falloff = rapid signal decay with distance

Volume Conduction:

Layer Conductivity Effect
Brain 0.33 S/m Good conductor
Skull 0.0042 S/m 80x more resistive - blurs signals
Scalp 0.33 S/m Good conductor

The skull is the main culprit in signal distortion!


Slide 4: Neurophysiological Origins

Where EEG Signals Come From

Pyramidal Neurons - The Signal Generators:

    Scalp Electrode
         ↑
    ═════════════════  Scalp
         ↑ Volume Conduction
    ─────────────────  Skull (80x resistance!)
         ↑
    ═════════════════  CSF
         ↑
      ──┼──  Apical Dendrites (current sink during EPSP)
        │
        ●    Soma (cell body)
        │
      ──┴──  Axon (current source)

Why Pyramidal Cells Matter:

  1. Geometric Alignment: Perpendicular to cortical surface
  2. Spatial Separation: Long dendrites create dipole moment
  3. Synchronization: ~10,000-50,000 neurons must fire together!

Key Insight: Only synchronized cortical patches produce measurable scalp signals


Slide 5: Cortical Geometry & Dipole Orientation

Gyri vs Sulci: Why Orientation Matters

The Folded Cortex:

Cross-section of cortical fold:

        Scalp Surface
    ════════════════════
          ↑ RADIAL dipole (gyrus top)
    ┌─────●─────┐
    │     ↑     │
    │  ←──●──→  │  TANGENTIAL dipoles (sulcus walls)
    │     │     │
    └─────┴─────┘
       Sulcus

Orientation Effects on Scalp Pattern:

Orientation Location Pattern % of Cortex
Radial Gyri (tops) Focal, symmetric ~1/3
Tangential Sulci (walls) Dipolar, +/- poles ~2/3

Most brain activity is tangential - producing dipolar patterns!


Slide 6: The 10-20 Electrode System

International Standard Electrode Placement

Scalp Layout (Top View):

              Nasion (nose)
                 │
        Fp1    Fpz    Fp2     ← Frontal pole
           ╲    │    ╱
      F7 ── F3 ─ Fz ─ F4 ── F8   ← Frontal
           ╱    │    ╲
      T3 ── C3 ─ Cz ─ C4 ── T4   ← Central (motor)
           ╲    │    ╱
      T5 ── P3 ─ Pz ─ P4 ── T6   ← Parietal
           ╱    │    ╲
        O1    Oz    O2     ← Occipital (visual)
                 │
              Inion

Coordinate System (Normalized -1 to +1):

  • X-axis: Left (-) → Right (+)
  • Y-axis: Posterior (-) → Anterior (+)
  • Z-axis: Inferior (-) → Superior (+)

21 electrodes capture the whole-head spatial pattern


Slide 7: Key Features Overview

What Our Tool Does

Visualization

  • 3D Brain View: WebGL-powered interactive anatomy
  • Coronal Slice: Cross-sectional with MRI background
  • Scalp Topomap: Classic 10-20 electrode heatmap

Source Modeling

  • Point Dipoles: Quick, educational
  • Active Regions (Blobs): Realistic distributed sources
  • Multiple Sources: Complex configurations

Signal Processing

  • Reference Schemes: None, Average, Single, CMS/DRL
  • Noise Simulation: Gaussian, impedance, mains hum
  • Time Series: CSV import, playback, animation

Slide 8: Live Demo - Basic Dipole

Demo: Moving a Dipole

What to observe:

  1. Position Effect

    • Surface source → strong, focal signal
    • Deep source → weak, spread signal
  2. Orientation Effect

    • Radial (90°) → symmetric pattern
    • Tangential (0°/180°) → dipolar pattern
  3. Amplitude Effect

    • Scales the color intensity linearly

Key Insight: Small changes in source position cause large changes in scalp pattern


Slide 9: Live Demo - Blob Mode

Demo: Distributed Source

Active Region (Blob) Features:

  • Radius: 0.02 - 0.4 (normalized units)
  • Gaussian Distribution: Smooth falloff from center
  • 3D Orientation: θ (tilt) and φ (rotation)

Why Blobs Matter:

Single Dipole Blob
Point source Extended region
Sharp gradients Smooth gradients
Less realistic More realistic
Fast computation Slightly slower

Cortical activation is distributed, not point-like!


Slide 10: The Lead Field Concept

How Sources Map to Measurements

Lead Field Matrix:

V = L × s

Where:
┌────┐   ┌─────────────────────┐   ┌────┐
│ V₁ │   │ L₁₁  L₁₂  L₁₃  ... │   │ px │
│ V₂ │ = │ L₂₁  L₂₂  L₂₃  ... │ × │ py │
│ ...│   │ ...  ...  ...  ... │   │ pz │
│ Vₙ │   │ Lₙ₁  Lₙ₂  Lₙ₃  ... │   │ ...│
└────┘   └─────────────────────┘   └────┘
  ↑              ↑                    ↑
Electrode    Sensitivity           Dipole
Potentials    Matrix               Moments

What This Means:

  • Each row = one electrode's sensitivity to all source components
  • Each column = one source component's contribution to all electrodes
  • Superposition: Multiple sources simply add together!

The forward problem is a matrix multiplication


Slide 11: Reference Electrode Deep Dive

Why Reference Matters

The Reference Problem:

  • EEG measures voltage differences, not absolute voltage
  • Every electrode is relative to some reference
  • Different references → different-looking signals!

Available Options:

Reference Formula Use Case
None V = V Theoretical only
Average V' = V - mean(all) Research
Single V' = V - Vref Clinical
CMS/DRL Hardware + feedback Modern systems

Slide 12: CMS/DRL Innovation

Design 1: Common Mode Sense + Driven Right Leg

The Feedback Loop:

       ┌─────────────────────────────────────┐
       │                                     │
       ▼                                     │
   [CMS Electrode] → [Integrator] → [DRL Electrode]
       │                 (-G)            │
       │                                 │
       └─────── Body Impedance ──────────┘

Parameters We Simulate:

  • DRL Gain: 1-1000 (typical: 100)
  • Time Constant: 0.1-10 ms
  • Body Transfer: Attenuation + phase lag
  • Phase Margin: Stability indicator

Upload custom frequency response LUTs!


Slide 13: DRL Circuit Mathematics

The Electronics Behind Noise Cancellation

DRL Transfer Function (Integrator):

H_DRL(s) = -G / (1 + sτ)

Frequency Response:
|H(jω)| = G / √(1 + (ωτ)²)
Phase:  φ(ω) = -90° - arctan(ωτ)

Complete Loop Transfer Function:

L(s) = H_DRL(s) × H_body(s) × η

Where:
- H_body(s) = α / (1 + sRC)    [Body impedance model]
- α = attenuation (0.5-0.9)
- η = injection efficiency

CMRR Improvement:

CMRR_total = CMRR_amp + 20·log₁₀(G × η) dB

Example: G=100, η=0.8 → +38 dB improvement!

DRL can boost CMRR from 80 dB to >110 dB


Slide 14: CMS/DRL Stability

Phase Margin Analysis

Why Stability Matters:

  • DRL is a feedback loop
  • Too much gain + phase lag = oscillation
  • Patient safety concern in real systems

Our Stability Display:

Phase Margin Status Indicator
> 45° Safe Green
20-45° Caution Yellow
< 20° Unstable Red

What Affects Stability:

  • Body impedance (skin prep quality)
  • DRL circuit bandwidth
  • Electrode placement

Slide 15: Signal Quality Simulation

Real-World Degradation

Noise Sources We Model:

Source Control Effect
Thermal Noise slider Random baseline fluctuation
Impedance Per-electrode Signal attenuation + mismatch
Mains Hum 50/60 Hz Common mode interference

Educational Value:

  • Show students why skin prep matters
  • Demonstrate DRL rejection of mains hum
  • Visualize impedance mismatch artifacts

Slide 16: Time Series Animation

Bringing Data to Life

CSV Import Format:

time,motor_left,motor_right,visual
0.000,0.0,0.0,0.0
0.004,0.2,0.1,0.0
0.008,0.5,0.3,0.0
...

Channel Mapping:

  • Map each CSV column to one or more sources
  • Create realistic multi-source animations
  • Playback at 0.25x to 4x speed

Use Cases:

  • Simulate seizure propagation
  • Show motor cortex activation patterns
  • Demonstrate P300 responses

Slide 17: 3D Visualization

Anatomical Context

WebGL-Powered Features:

  • Orbit Controls: Drag to rotate
  • Zoom: Scroll wheel
  • Preset Views: Front, Top, Side
  • Brain Opacity: Adjustable transparency

Source Visualization:

  • Inside Brain: Orange (blob) / Blue (dipole)
  • Outside Brain: Red + "INACTIVE" label
  • Orientation Arrow: Shows moment direction

3D view helps build spatial intuition!


Slide 18: Electrode Montage

Customizable Recording

Per-Electrode Control:

  • Enable/disable any electrode
  • Grayed-out electrodes excluded from:
    • Average reference calculation
    • CMS averaging
    • Export data

Use Cases:

  • Simulate bad electrode connections
  • Model reduced montages (e.g., only frontal)
  • Educational: show effect of removing electrodes

Slide 19: Pan & Zoom

Navigate the Views

Controls:

Action 2D Views 3D View
Zoom In Scroll up / + Scroll up
Zoom Out Scroll down / - Scroll down
Pan Shift + drag Right-click drag
Reset ⟲ button Reset button

Zoom Range: 50% - 300%

Perfect for focusing on specific regions during demos!


Slide 20: Export Capabilities

Data Output

Export Current Frame:

  • Instant snapshot
  • All 21 electrodes
  • CSV format

Export Time Series:

  • Full animation sequence
  • Every time point × every electrode
  • Ready for MATLAB/Python analysis

Output Format:

time,Fp1,Fp2,F7,F3,Fz,F4,F8,T3,C3,Cz,C4,T4,...
0.000,0.12,-0.45,0.78,0.23,...
0.004,0.13,-0.44,0.79,0.24,...

Slide 21: Technical Excellence

Under the Hood

Zero Dependencies Architecture:

  • Pure HTML/CSS/JavaScript
  • Three.js loaded from CDN (only external)
  • No build tools, no npm, no webpack
  • Works offline once loaded

Performance:

  • 60 FPS rendering
  • Real-time physics calculations
  • Efficient Delaunay interpolation

Code Quality:

  • Modular ES6 architecture
  • Comprehensive documentation
  • Easy to extend and modify

Slide 22: Educational Applications

How Teams Use This Tool

Neuroscience Education:

  • Forward vs inverse problem visualization
  • Volume conduction effects
  • Dipole orientation importance

EEG Technician Training:

  • Reference electrode effects
  • Impedance impact demonstration
  • Artifact recognition

Engineering & Research:

  • DRL circuit design validation
  • Custom transfer function testing
  • Montage optimization

Slide 23: Competitive Advantages

Why Our Tool Stands Out

Feature Our Tool Typical Alternatives
Setup Open HTML file Install MATLAB/Python packages
Cost Free Expensive licenses
Platform Any browser OS-specific
3D View Built-in Requires plugins
DRL Sim Full model Not available
Learning Curve Minutes Hours/Days

Democratizing EEG education!


Slide 24: Future Roadmap

What's Coming Next

Planned Features:

  • Realistic head model (BEM forward model)
  • EEG file format import (EDF, BDF)
  • More electrode systems (64, 128, 256)
  • Source localization inverse solver
  • Mobile-optimized interface
  • API for programmatic control

Community Contributions Welcome!

  • Open source (MIT License)
  • GitHub repository
  • Issue tracker for feature requests

Slide 25: Live Demo Agenda

What We'll Show Today

Demo Flow (15 minutes):

  1. Basic Dipole (3 min)

    • Move, rotate, scale
    • Show INACTIVE state
  2. Blob Mode (2 min)

    • Extended sources
    • 3D orientation
  3. Reference Comparison (4 min)

    • Average vs Single vs CMS/DRL
    • Enable mains hum, show rejection
  4. Signal Quality (2 min)

    • Add noise and impedance
  5. Time Series (2 min)

    • Upload CSV, play animation
  6. Q&A (2 min)


Slide 26: Key Takeaways

Remember These Points

  1. The skull distorts everything - 80x less conductive than brain

  2. Orientation matters as much as position - radial vs tangential

  3. Reference choice changes the picture - always document your reference

  4. DRL is a feedback loop - phase margin = stability

  5. Real signals are noisy - impedance and mains hum are everywhere

  6. This tool is free and works anywhere - share with your colleagues!


Slide 27: Getting Started

Try It Yourself!

Access:

Quick Start:

git clone https://github.com/AdityaAsopa/EEG-Forward-Model.git
open index.html

Documentation:

  • README.md - Full documentation
  • TOUR_GUIDE.md - Step-by-step walkthrough
  • PRESENTATION_SLIDES.md - This handout

Slide 28: Questions?

Let's Discuss!

Contact & Resources:

Repository: github.com/AdityaAsopa/EEG-Forward-Model

Issues & Features: Use GitHub Issues

Documentation: See README.md


Appendix A: Keyboard Shortcuts

Key Action
Delete Remove selected source
A Rotate counter-clockwise
D Rotate clockwise
W Increase amplitude
S Decrease amplitude

Appendix B: Physics Equations

Dipole Potential

Single Dipole:

V(r) = (1/4πσ) × (p · R) / |R|³

Regularized (avoid singularity):

V(r) = (p · R) / (|R|³ + ε)

Blob (Gaussian Cluster)

Weight at sample point:

w(r) = exp(-r²/2σ²)

Total contribution:

V = Σ wᵢ × V_dipole(rᵢ)

Appendix C: DRL Transfer Function

Integrator Model

Transfer Function:

H(s) = -G / (1 + sτ)

Where:

  • G = DC gain
  • τ = time constant

Loop Gain with Body:

L(s) = H_DRL(s) × H_body(s) × η

Where:

  • η = injection efficiency
  • H_body = body transfer function

Phase Margin:

PM = 180° - |∠L(jω₀)|

Appendix D: Color Mapping

Diverging Colormap

Blue → White → Red

Value Color
-1.0 Blue (negative)
-0.5 Light blue
0.0 White (neutral)
+0.5 Light red
+1.0 Red (positive)

Auto-scaling normalizes to max absolute value


Appendix E: Interpolation Mathematics

How We Create Smooth Topomaps

Delaunay Triangulation:

Electrode mesh (top view):

    Fp1 ────────── Fp2
     │╲    Fz    ╱│
     │ ╲   ●   ╱  │       Triangles connect
     │  ╲    ╱   │       neighboring electrodes
    F7───F3──F4───F8
     │  ╱ │╲  ╱  │
     │ ╱  │ ╲   │
    T3───C3─Cz─C4───T4

Barycentric Interpolation:

For point P inside triangle ABC:

P = u·A + v·B + w·C    (where u + v + w = 1)

Interpolated value: V_P = u·V_A + v·V_B + w·V_C

Result: Smooth, continuous potential field from 21 discrete measurements


Appendix F: Model Accuracy & Limitations

What This Tool Can and Cannot Do

Model Assumptions vs Reality:

Assumption Reality Error Impact
Homogeneous conductivity Anisotropic tissues ~10-20%
Spherical/ellipsoidal head Complex folded cortex Position errors
Point dipole sources Distributed patches Oversimplification
Static (quasi-static) Dynamic at high freq Valid < 1 kHz

Accuracy Comparison:

Model Type Accuracy Speed Use Case
This tool ~80% Real-time Education
BEM ~95% Seconds Research
FEM ~98% Minutes Clinical

When to Use This Tool:

  • Understanding EEG principles
  • Demonstrating concepts
  • DRL circuit exploration
  • Quick prototyping

When NOT to Use:

  • Clinical source localization
  • Quantitative analysis
  • Individual patient modeling

This is an educational tool - not a clinical diagnostic!


Appendix G: Synchronization Requirements

How Many Neurons Make an EEG Signal?

The Numbers:

Parameter Value Implication
Minimum neurons 10,000 - 50,000 Small patches invisible
Cortical patch 6-10 cm² Need extended activation
Timing window ~10 ms Must be synchronous
Alignment Perpendicular to cortex Random orientations cancel

What This Means:

Single neuron:     ●          → Invisible (~0.00001 μV)

Small patch:       ●●●        → Still invisible
                   ●●●

Synchronized:      ↑↑↑↑↑      → Measurable (~1-100 μV)
large patch:       ↑↑↑↑↑
(>10,000 neurons   ↑↑↑↑↑
 aligned & timed)

EEG is a population measure - individual neurons cannot be detected


Appendix H: Key Constants in Implementation

Numbers Used in the Code

Brain Ellipsoid (Normalized):

Center: (0, 0, -0.05)
Radii:  rx=0.75, ry=0.80, rz=0.70

Conductivity Ratios:

Brain:Skull:Scalp = 1 : 0.013 : 1
(Skull is ~80x more resistive)

Regularization Constant:

ε = 10⁻³ (prevents 1/r³ singularity)

Default DRL Parameters:

Gain: 100
Time constant: 1 ms
Injection efficiency: 0.8

Blob Sampling:

3×3×3 = 27 sample points
Gaussian weighting: w(r) = exp(-r²/2σ²)

End of Presentation Handout

Thank you for your attention!

EEG Dipole Demo v2.0 - Making EEG Forward Modeling Accessible to Everyone