Overview
Intracranial electroencephalography (iEEG) is a direct neurophysiological recording modality used during pre-surgical evaluation of individuals diagnosed with medically refractory 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 local 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. Data Source Selection: Use the Data Stream Source dropdown to toggle between Synthetic Seizure Dynamics and Real Patient iEEG (NeuroVista I004). When the real clinical dataset is selected, an asynchronous JavaScript loader retrieves and parses the $2.5\text{ MB}$ raw recording directly into local browser memory, populating $40,000$ samples across $16$ channels.
2. Primary Action Controls: Located at the top of the workspace:
- Start Demo: Initiates an automated 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 Options: Enable the Y-Axis Autoscale toggle to dynamically frame the signal trace with a $15\%$ margin. This automatically prevents clipping during intense, high-amplitude seizure phases while maintaining clear visibility of lower-amplitude activity across quieter interictal 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.
4. Quantitative Performance Metrics
Filtration quality is evaluated in real-time by comparing the pre-filtered signal $x_{\text{orig}}[n]$ to the wavelet-denoised signal $x_{\text{clean}}[n]$:
$$\text{SNR (dB)} = 10 \log_{10} \left( \frac{\sum_{n=0}^{N-1} x_{\text{orig}}[n]^2}{\sum_{n=0}^{N-1} (x_{\text{orig}}[n] - x_{\text{clean}}[n])^2} \right)$$
$$\text{MSE} = \frac{1}{N} \sum_{n=0}^{N-1} (x_{\text{orig}}[n] - x_{\text{clean}}[n])^2$$
Future Directions
Future development phases for this analytical workspace focus on integrating WebAssembly (WASM) modules compiled from C++ C23 code. This will enable real-time computation of high-order Undecimated Wavelet Transforms (UWT / stationary wavelets) and Continuous Wavelet Transforms (CWT) directly within the browser thread. Additionally, we plan to implement automated machine learning classification algorithms (such as lightweight Support Vector Machines or Convolutional Neural Networks running via WebGPU) to provide real-time seizure onset detection and automated focal channel mapping.
Related Diagnostics Platforms
Explore BioniChaos's suite of interactive neurological and electrophysiological visualization applications: