Overview
Intracranial electroencephalography (iEEG) stands as a foundational clinical method for mapped localization of epileptogenic zones in individuals with pharmacoresistant focal epilepsy. Unlike standard non-invasive scalp EEG systems, which undergo spatial low-pass filtering and attenuation through the skull, cerebrospinal fluid, and tissues, intracranial electrodes (including stereotactic depth electrodes and subdural grids) capture localized field potentials directly from cortical structures. This provides high spatial and temporal resolution, measuring synchronized electrical fields generated by pyramidal neurons within a small localized radius.
A primary challenge in interpreting raw time-domain iEEG streams is isolating sub-microvolt electrophysiological biomarkers of epilepsy—such as high-frequency oscillations ($HFOs$, occurring in the ripple band of $80\text{--}250\text{ Hz}$ and fast ripple band of $250\text{--}500\text{ Hz}$) and interictal epileptiform discharges—from surrounding ambient noise, electromagnetic interference ($60\text{ Hz}$ power line noise), and biomechanical artifacts. Standard bandpass filters often introduce phase distortion or fail to isolate non-stationary, transient signal structures, making localized spectral representation necessary.
The 2D frequency spectrogram provides a three-dimensional representation mapping time on the horizontal axis, frequency on the vertical axis, and local spectral power intensity via a high-contrast chromatic scale. This visualization tool maps the temporal progression and spectral distribution of local neural fields during the transition from the interictal state (between seizures), to the pre-ictal period, the ictal onset phase, and the subsequent post-ictal suppression period. During focal seizure propagation, local neural structures experience a loss of normal chaotic complexity and transition into structured, highly synchronized, hypersynchronous high-amplitude oscillations. This electrographic transition is characterized on the spectrogram by a sudden, intense peak in the beta ($13\text{--}30\text{ Hz}$) and low gamma bands ($30\text{--}80\text{ Hz}$), which subsequently degrades into rhythmic, harmonically dense spike-and-wave patterns in the theta ($4\text{--}8\text{ Hz}$) and delta ($0.5\text{--}4\text{ Hz}$) bands during the clonic phase.
How To Use
This dynamic virtual workstation simulates a 16-channel intracranial recording environment running at a sampling frequency ($f_s$) of $400\text{ Hz}$. It allows the user to compare simulated textbook models with real patient data. Follow these steps to navigate the neural interface and observe localized epilepsy dynamics:
1. Dataset Selection: Use the Data Stream Source dropdown to toggle between *Synthetic Seizure Dynamics* and *Real Patient iEEG (NeuroVista I004)*. Selecting the Real Patient stream triggers an asynchronous, serverless load of the 2.5 MB text file directly into local client memory, parsing 40,000 samples across 16 channels in milliseconds. Once parsed, toggling between the two modes is instantaneous.
2. Initiating the Interactive Display: Click the Start Demo button at the top of the controls panel. This starts a temporal playback loop that scrolls through the 100-second timeline. You will observe background, interictal, and active tonic-clonic epileptic discharge phases. Clicking any slider, selection dropdown, or structural toggle immediately stops the Demo playback and returns navigation to your manual control.
3. Dynamic Scaling (Autoscale): Toggle the Y-Axis Autoscale switch. When enabled, this algorithm dynamically scales the voltage trace vertically according to the peak-to-peak amplitude present within the visible temporal window. This prevents off-scale clipping of high-amplitude epileptic spikes while maintaining resolution on low-voltage background intervals.
4. Navigating the Epileptic Event: Use the Timeline Scroller to move through the recording. Set the slider to $0\text{--}30\text{ seconds}$ to inspect interictal background activity. Advance the timeline to $35\text{--}45\text{ seconds}$ to observe the sub-clinical pre-ictal high-frequency beta-buzz. Move the scroller to $45\text{--}75\text{ seconds}$ to visualize the massive, synchronous seizure discharge. Observe post-ictal depression by scrolling to $75\text{--}90\text{ seconds}$.
5. Channel Selection and Automapping: Toggle the Auto-Channel Selection switch. When active, the system automatically parses all 16 channels in the background and switches to the channel containing the largest absolute signal amplitude within the current time window. During the seizure (sec $45\text{--}75$), this system automatically locks onto Channel 7, mapping the epicenter of the epileptogenic focus. You can disable Auto-Channel Selection to manually select and trace surrounding channels ($0\text{--}15$).
6. Tuning Denoising Parameters: Toggle the Wavelet Denoise switch to process the signal and spectrogram. Expand the Advanced Diagnostics panel to select between the Haar or Daubechies 4 discrete wavelet families. Adjust the Wavelet Decomposition Levels slider (1 to 10) to set the frequency partitioning depth, and tune the Threshold Multiplier ($\lambda$) to scale noise elimination limits. Notice the instant changes on the output panels for Signal-to-Noise Ratio (SNR) and Mean Square Error (MSE).
7. Acoustic Sonification: Click the Sound ON button to map the currently viewed raw signal and spectral profile to an audio carrier wave. As a seizure propagates and frequencies shift from chaotic background noise into high-amplitude periodic patterns, the sonification model shifts from a low-frequency hum to a louder, pure modulated frequency sweep.
8. Baseline Restoration: Click the Reset Baseline button at any point to instantly clear all manual settings, silence the synthesizer, and restore the workspace to its default parameters.
Technical Details
This application implements an advanced signal processing pipeline entirely client-side using JavaScript, optimizing high-performance canvas rendering and real-time processing within the browser window. The primary steps are outlined below:
Discrete Wavelet Transform & Denoising
When Wavelet Denoising is active, the raw signal $x[n]$ is decomposed into approximation and detail coefficients across $J$ levels. We implement both Haar and orthogonal Daubechies 4 (4-tap) filter banks. At each level $j$, the signal is convolved with high-pass ($g[k]$) and low-pass ($h[k]$) filters and decimated by a factor of 2:
$$a_j[n] = \sum_{k} a_{j-1}[k] h[2n - k], \quad d_j[n] = \sum_{k} a_{j-1}[k] g[2n - k]$$
Once the multi-resolution coefficients are calculated, noise reduction is performed using the Universal Threshold rule:
$$\lambda = m \cdot \hat{\sigma} \sqrt{2 \ln N}$$
where $N$ is the segment length, $m$ is the user-defined multiplier, and the noise level $\hat{\sigma}$ is estimated via the Median Absolute Deviation (MAD) of the first-level detail coefficients $d_1$, normalized for normal distributions:
$$\hat{\sigma} = \frac{\text{median}(|d_1[n]|)}{0.6745}$$
We apply soft thresholding to the detail coefficients $d_j[n]$ at each level, preserving structural approximation coefficients:
$$\eta_{\text{soft}}(d, \lambda) = \text{sgn}(d) \max(0, |d| - \lambda)$$
The denoised time-domain trace is reconstructed by applying synthesis filters recursively through the Inverse Discrete Wavelet Transform (IDWT).
Short-Time Fourier Transform (STFT) Spectrogram
The 2D spectrogram heatmap is computed using the Short-Time Fourier Transform of the windowed signal. The active segment is split into overlapping frames. For each frame, we apply a Hanning window $w[n]$ to minimize spectral leakage:
$$w[n] = 0.5 \left(1 - \cos\left(\frac{2\pi n}{M-1}\right)\right)$$
where $M$ is the frame size (set to 256 samples to balance temporal and spectral resolution). The windowed signal is processed via a Radix-2 Cooley-Tukey Fast Fourier Transform (FFT) algorithm to compute the discrete spectrum:
$$X(m, \omega) = \sum_{n=0}^{M-1} x[n + mS] w[n] e^{-j \omega n}$$
The squared magnitude $|X(m, \omega)|^2$ represents the power spectral density. This matrix is mapped to the Spectrogram Canvas. By default, the rendering displays the clinically crucial frequency band of $0\text{--}50\text{ Hz}$ which maps Delta, Theta, Alpha, and Beta wave structures over the full height of the display canvas. If Whole Spectrum is toggled, the vertical axis expands to the full $0\text{--}200\text{ Hz}$ Nyquist frequency.
Future Directions
To support advanced clinical diagnostic needs, future iterations of this platform will aim to integrate deep learning models directly within the client-side pipeline. By utilizing WebAssembly or TensorFlow.js, we plan to implement real-time automated seizure prediction and localization. These neural networks would scan multi-channel iEEG data to identify pre-ictal phase shifts before clinical symptoms appear. Additionally, we plan to implement Independent Component Analysis (ICA) for automated ocular and myogenic artifact rejection, alongside a multi-wavelet packet transform tool for higher resolution at high frequencies.
Related Diagnostics Platforms
Explore BioniChaos's suite of interactive neurological and electrophysiological visualization applications: