Overview
Intracranial electroencephalography (iEEG) stands as a foundational clinical method for mapped localization of epileptogenic zones in individuals with pharmacoresistant focal epilepsy. By placing stereotactic depth electrodes or subdural grid arrays directly on cortical structures, clinicians bypass the low-pass spatial filtering and high electrical impedance of the skull, scalp, and tissues. The resulting signals represent localized field potentials ($LFPs$), providing temporal resolution in the millisecond domain and spatial resolution at the millimeter scale.
Analysis of iEEG signals requires processing in both the time domain and the frequency domain. In time-domain traces, raw voltage fluctuations often suffer from baseline wander, high-frequency muscular noise, and electromagnetic interference ($60\text{ Hz}$ power line hum). Transforming these non-stationary signals into the frequency domain reveals spectral power distributions across classical brainwave frequency bands: Delta ($0.5\text{--}4\text{ Hz}$), Theta ($4\text{--}8\text{ Hz}$), Alpha ($8\text{--}13\text{ Hz}$), and Beta ($13\text{--}30\text{ Hz}$). During the onset of focal seizures, cortical networks undergo a breakdown of normal asynchronous chaos, transitioning into hypersynchronous, high-amplitude oscillatory discharges. This state shift appears in the frequency spectrum as a massive shift in power spectral density toward specific frequency bands, accompanied by high-frequency bursts ($HFOs$) above $80\text{ Hz}$.
This interactive workstation integrates multi-resolution discrete wavelet denoising, linear detrending, and Welch periodogram spectral decomposition. It enables clinicians, researchers, and students to evaluate noise filtration performance through quantitative metrics—Signal-to-Noise Ratio (SNR) and Mean Square Error (MSE)—while comparing synthetic mathematical seizure models against real clinical iEEG recordings from the NeuroVista trial database.
How To Use
This virtual laboratory operates as a serverless single-page workstation. The interface controls are arranged sequentially in the right-hand control panel to streamline signal analysis:
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. Primary Action Controls: Located at the top of the workspace:
- Start Demo: Initiates a silky-smooth $60\text{ FPS}$ continuous timeline scroll across $100\text{ seconds}$, displaying interictal, pre-ictal, ictal, and post-ictal phases. Interacting with any control automatically halts the demo.
- Reset Baseline: Instantly resets all sliders, toggles, and data channels back to default parameters.
- Sound ON/OFF: Activates Web Audio sonification, mapping signal amplitude and dominant frequency to a frequency-modulated synthesis tone.
3. Signal Processing Toggles: Enable or disable Wavelet Denoise to observe signal cleanup in real-time. Toggle Detrending to remove baseline low-frequency drift, and toggle Whole Spectrum Overlay to display unfiltered power spectral density outside the primary bands ($<0.5\text{ Hz}$ and $>30\text{ Hz}$).
4. 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.
5. Spatial Channel Mapping: Select specific channels ($0\text{--}7$ for the left hemisphere, $8\text{--}15$ for the right hemisphere). Enabling Auto-Channel Selection allows the system to monitor all $16$ channels in the background and automatically lock onto the channel exhibiting the highest absolute amplitude within the current window frame.
6. Multi-Resolution Diagnostics: Expand the Advanced Diagnostics panel to select the discrete wavelet family (Haar or Daubechies 4), set the decomposition level ($1\text{--}10$), adjust the threshold multiplier ($\lambda$), change the bandpass filter order ($1\text{--}5$), and toggle between linear and logarithmic frequency scaling.
Technical Details
The processing architecture runs entirely client-side in vanilla JavaScript to guarantee high interaction performance without backend network latencies. The underlying mathematical operations are detailed below:
1. Linear Detrending
To eliminate baseline offset and slow linear drift caused by electrode polarization, the active time window $x[n]$ of length $N$ is detrended by computing the linear least-squares regression line $y[n] = m \cdot n + c$, where:
$$m = \frac{N \sum n x[n] - \sum n \sum x[n]}{N \sum n^2 - (\sum n)^2}, \quad c = \frac{\sum x[n] - m \sum n}{N}$$
The detrended signal $x_{\text{detrend}}[n] = x[n] - y[n]$ ensures a zero-mean baseline centered on the horizontal axis.
2. Discrete Wavelet Denoising (DWT / IDWT)
Multi-resolution signal decomposition uses discrete wavelet filter banks. The signal $x[n]$ is convolved with low-pass scaling filter $h[k]$ and high-pass wavelet filter $g[k]$, then downsampled by 2 at each level $j$:
$$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]$$
To eliminate uncorrelated Gaussian noise while preserving sharp epileptiform spikes, soft thresholding is applied to detail coefficients $d_j[n]$ using the Universal Threshold rule:
$$\lambda = m \cdot \hat{\sigma} \sqrt{2 \ln N}$$
where $m$ is the user-defined multiplier, $N$ is the sample size, and $\hat{\sigma}$ is estimated via the Median Absolute Deviation (MAD) of the finest scale detail coefficients $d_1[n]$:
$$\hat{\sigma} = \frac{\text{median}(|d_1[n]|)}{0.6745}$$
Detail coefficients are modified via soft shrinkage $\eta_{\text{soft}}(d, \lambda) = \text{sgn}(d) \max(0, |d| - \lambda)$, and the cleaned time-domain signal is reconstructed using synthesis filters through the Inverse Discrete Wavelet Transform (IDWT).
3. Spectral Power Density Estimation
Frequency analysis uses Welch's periodogram method. The windowed signal is divided into overlapping segments, multiplied by a Hanning window $w[n] = 0.5 \left(1 - \cos\left(\frac{2\pi n}{M-1}\right)\right)$, and transformed using a Radix-2 Cooley-Tukey Fast Fourier Transform (FFT):
$$X[k] = \sum_{n=0}^{M-1} x[n] w[n] e^{-j 2\pi k n / M}$$
The power spectral density $P[k] = \frac{1}{M U} |X[k]|^2$ (where $U = \frac{1}{M}\sum w^2[n]$ is the window power normalization factor) is partitioned into functional frequency bands:
- Delta Band ($0.5\text{--}4\text{ Hz}$): Deep slow-wave oscillations.
- Theta Band ($4\text{--}8\text{ Hz}$): Drowsiness and focal slowing.
- Alpha Band ($8\text{--}13\text{ Hz}$): Resting posterior rhythms.
- Beta Band ($13\text{--}30\text{ Hz}$): Active cognition and tonic seizure onset bursts.
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: