Cortical oscillations, electrophysiological activity patterns, associated
with cognitive functions and impaired in many psychiatric disorders can be
observed in intracranial electroencephalography (iEEG). Direct cortical
stimulation (DCS) may directly target these oscillations and may serve as
therapeutic approaches to restore functional impairments. However, the presence
of electrical stimulation artifacts in neurophysiological data limits the
analysis of the effects of stimulation. Currently available methods suffer in
performance in the presence of nonstationarity inherent in biological data. Our
algorithm, Shape Adaptive Nonlocal Artifact Removal (SANAR) is based on
unsupervised manifold learning. By estimating the Euclidean median of k nearest
neighbors of each artifact in a nonlocal fashion, we obtain a faithful
representation of the artifact which is then subtracted. This approach
overcomes the challenges presented by nonstationarity. SANAR is effective in
removing stimulation artifacts in the time domain while preserving the spectral
content of the endogenous neurophysiological signal. We demonstrate the
performance in a simulated dataset as well as in human iEEG data. Using two
quantitative measures, that capture how much of information from endogenous
activity is retained, we demonstrate that SANAR's performance exceeds that of
one of the widely used approaches, independent component analysis, in the time
domain as well as the frequency domain. This approach allows for the analysis
of iEEG data, single channel or multiple channels, during DCS, a crucial step
in advancing our understanding of the effects of periodic stimulation and
developing new therapies