Paper The following article is Open access

Optimization of phase prediction for brain-state dependent stimulation: a grid-search approach

, , and

Published 31 January 2023 © 2023 The Author(s). Published by IOP Publishing Ltd
, , Citation Claudia Bigoni et al 2023 J. Neural Eng. 20 016039 DOI 10.1088/1741-2552/acb1d8

1741-2552/20/1/016039

Abstract

Objective. Sources of heterogeneity in non-invasive brain stimulation literature can be numerous, with underlying brain states and protocol differences at the top of the list. Yet, incoherent results from brain-state-dependent stimulation experiments suggest that there are further factors adding to the variance. Hypothesizing that different signal processing pipelines might be partly responsible for heterogeneity; we investigated their effects on brain-state forecasting approaches. Approach. A grid-search was used to determine the fastest and most-accurate combination of preprocessing parameters and phase-forecasting algorithms. The grid-search was applied on a synthetic dataset and validated on electroencephalographic (EEG) data from a healthy (n = 18) and stroke (n = 31) cohort. Main results. Differences in processing pipelines led to different results; the grid-search chosen pipelines significantly increased the accuracy of published forecasting methods. The accuracy achieved in healthy was comparably high in stroke patients. Significance. This systematic offline analysis highlights the importance of the specific EEG processing and forecasting pipelines used for online state-dependent setups where precision in phase prediction is critical. Moreover, successful results in the stroke cohort pave the way to test state-dependent interventional treatment approaches.

Export citation and abstract BibTeX RIS

Original content from this work may be used under the terms of the Creative Commons Attribution 4.0 license. Any further distribution of this work must maintain attribution to the author(s) and the title of the work, journal citation and DOI.

1. Introduction

Most experiments with non-invasive brain stimulation (NIBS) techniques, such as transcranial magnetic stimulation (TMS), aim at demonstrating the methodology's validity, understanding different stimulation parameters by comparing responses in different populations, and eventually suggesting new clinical applications. Yet, these investigations are treating the brain as a black box and do not consider the role of underlying brain activation, or state, variability. The resulting literature shows relevant heterogeneity, both intra- and inter-subject, which has triggered a shift in concept towards protocols, where the brain can no longer be considered as a black-box [14], but its ongoing activity, state, and oscillatory properties must be taken into account as they might strongly impact the response to TMS at the cortico-spinal (e.g. motor-evoked potentials, MEPs [57]) and cortical level (cortical-evoked potentials) [810]. Several studies have begun to include the brain state to reduce heterogeneity, especially when looking at MEPs peak-to-peak amplitudes. The research has followed two lines of approaches: offline and online. In the former, acquired data is post-hoc sorted according to oscillations-based biomarkers such as the power spectral density (PSD) [1116], the phase of the wave [17] or both [7, 1823]. The second approach, which has been applied only more recently, uses the same biomarkers to choose when to trigger the TMS pulse in real-time [5, 6, 16, 2428]. In this methodology, to integrate endogenous brain oscillations, the instantaneous brain state in terms of phase and power at the stimulation time must be extracted and predicted from the last acquired information. To estimate power at the stimulation time, the latest acquired data can be used given the relatively low frequency resolution of power [29]. However, to stimulate at a specific phase of an oscillatory period, future prediction is required as the last samples acquired will already be in the past.

Only a few research groups have so far applied such an approach within TMS experiments targeting the motor cortex, however, notwithstanding a brain-state-dependent protocol, initial publications reported controversial results [5, 6, 16, 30]. Although the protocol, intended here as the general experimental design, is an important factor for explaining outcome differences, we believe that the processing pipelines (i.e. signal preprocessing and phase prediction) to forecast the brain state are also important determinants. So far, different research groups have applied different pipelines in terms of filtering procedures and phase forecasting methods. The preprocessing role has already proven essential in functional magnetic resonance imaging analyses [31], and great attention is invested as well in the electroencephalography (EEG) community [32, 33]. For different types of EEG analyses, standardized pipelines have begun to be proposed [20, 34] and analyses studying the effects of choices at different steps of those pipelines are being published [32]. With the goal of creating a standard pipeline for online brain-state-dependent stimulation setups, we analyzed if a specific combination of preprocessing parameters and forecasting algorithms would be outperforming the others in terms of accuracy in phase prediction and computational cost.

2. Methods

To evaluate if a specific combination of preprocessing parameters was more accurate than others, we used a grid-search approach: for each parameter of interest (e.g. filter type, order, etc), a set of values were chosen based on previous knowledge (table 1); then, all possible combinations of values and parameters were created. Each combination was tested on the same dataset. All the filters used were applied in a zero-phase manner to reduce errors deriving from filters phase shifts.

Table 1. Preprocessing hyperparameters tested with grid-search. The chosen ranges for each parameter cover values that can be commonly found in EEG studies. In filter bandwidth, for IIR filter we have added stop-band ripple (used for both elliptic and Chebyshev type 1) and pass-band ripple (used for both elliptic filter and Chebyshev type II filters). For the other filters the bandwidth is only based on the two cut-off frequencies. All filters are applied in a zero-phase manner. IIR = infinite impulse response; FIR = finite impulse response.

Design parameter# parametersBounds/values
Sampling frequency (Hz)3500, 1000, 5000
Filter name6IIR: Bessel, Butterworth, Chebyshev type I, Chebyshev type II, elliptic FIR: Hanning window
Filter order  
 IIR52–5
 FIR20.22%–0.33% of window length
Filter bandwidth  
 IIR41–4
    Stop-band ripple220, 40
    Pass-band ripple20.1, 1
 FIR41–4
Window duration (s)110.3–0.75
Padding pre-filtering2Yes/no
Cutting edge of window post-filter30–0.3 (% of window duration)

The grid-search was applied on a synthetic dataset and the combinations leading to the most-accurate results were verified on another synthetic dataset. Subsequently, the same combinations were validated on real resting-state EEG data. A similar grid-search was also applied directly to the real dataset to analyze the importance of subject-specifics. The code was run on Python 3.8 and the full scripts can be found at www.github.com/clovbig/grid_search_phase.

2.1. Synthetic dataset

A synthetic dataset was used to have a real ground truth and was considered comparable to EEG [35]. We generated a sinusoid at 10 Hz, to focus on alpha oscillations, on which we added pink noise, i.e. proportional to 1/f. The raw signal for each time point t was given by:

where the amplitude k of the underlying signal is related to the signal-to-noise ratio (SNR).

Different trials from the same signal were used for verification. For this step, we also increased the complexity of the raw signal by adding sinusoids near the 10 Hz frequency.

2.2. Real dataset

The real dataset included 3 min resting-state EEG with eyes open and eyes closed from 18 young healthy right-handed subjects and 31 stroke patients; the latter were evaluated longitudinally at four time points: within one week (T1), three weeks (T2), three months (T3) and one year (T4) after the ictal event—demographics of the included subjects can be retrieved from supplementary table 1. Resting-state data were acquired before and after TMS stimulation blocks, making the dataset comparable to the online EEG that could be read in a real-time brain-state-dependent TMS study. All subjects signed a written informed consent and the study was approved by the ethics committee of the Canton of Vaud, Switzerland (No. 2018-01355). The protocol of the study can be found at [36].

During the experiment subjects were sitting and a fixation cross was placed in front of them. EEG signal was acquired from 64 Ag/AgCl TMS-compatible electrodes in a 10–20 system (EEG BrainCap-MR BrainVision LLC, North Carolina, USA); sampling rate was 5 kHz, with a high cut-off of 1 kHz. The EEG signal was not further pre-processed. Spatial filters were not applied; for this analysis we chose C3, C4, Fz, Cz, and Oz channels so to cover the sensorimotor, frontal, and occipital areas. Specifically, both hemispheres were checked for the motor cortices as stroke patients may have one or the other hemisphere lesioned.

2.3. Phase-forecasting algorithms

Two main types of phase-forecasting algorithms have been proposed in the literature: signal forecasting (SF) and time-point forecasting (PF). The former predicts the full signal in a window in the future and thus can compute the phase for all the points [5, 3739]; the second one simplifies the approach and instead of predicting the signal, it only forecasts the future time point where the phase of interest will be met [40, 41]. Although the prediction follows different methods, the overall approach to estimate a desired phase in the future is similar: (a) take the last available window of data, (b) filter it in the frequency band of interest, (c) predict the next time point when the wanted condition is met (supplementary figure 1).

We evaluated two SF and two PF methods. The former differed in the signal prediction approach. In one case, an autoregressive model was used on the filtered signal [5] (SF-AR); in the other, the EEG signal was approximated as a sine wave with frequency and phase given by the fast Fourier transform (FFT) (SF-FFT) [37]. An example of PF comes from Tomasevic and Siebner [40], who proposed to find the last peak and trough of the given filtered window and use their distance to define the period of the main frequency. The period is then added to the last peak to predict the next one (PF-PT). We also tested a variation of this method where only the last peak is searched and the period is obtained from the main frequency of the FFT (PF-FFT).

2.4. Performance evaluation

Algorithms were compared based on their performance in terms of accurate phase detection and computational time. In particular, the processing time of each algorithm was considered while making the prediction to ensure that the forecasted point was still in the future.

Accuracy was defined as the mean plus standard deviation of the phase error along trials for the different conditions. For each condition 50 trials were used. The phase error was computed as the difference between the actual phase expected during a peak (i.e. 90° for a sine wave) and the phase of the signal at the predicted time point. If for a trial, no peak could be forecasted (e.g. the filter or the AR did not converge), the phase error was set to the maximum of 180°.

For real data, the ground truth was computed on the full resting state dataset using the same preprocessing as the one used for the phase estimation.

2.5. Statistics

We used a linear mixed effect model (LMM) to study the effect of each individual factor and their combinations on the overall performance in phase forecasting. We used a random intercept for each subject. When studying categorical variables (i.e. resting state eye condition, channel of readout and approach used) we used as dependent variable the mean + standard deviation of the phase errors of all the trials per subject per condition. Individual data points (i.e. each trial independently) were used when the PSD, a numerical variable, was added to the fixed factors. PSD was computed with the Welch method over the window predefined by the grid-search parameter and with four different bandwidths (1–4 Hz); the value of PSD per trial was equal to the integrated area under the curve of the power spectra in the frequency band of interest. Post-hoc analyses were carried out with estimated marginal means with a Bonferroni correction. Comparison between the original published methods [5, 35, 37, 40] and the newly found preprocessing was done with a paired Wilcoxon signed-rank test, with alpha = 0.05. Statistical analyses were run in R, version 4.1.1 among the packages used are stats, emmeans and lmerTest.

3. Results

The examination of preprocessing hyperparameters for different forecasting algorithms through a grid-search revealed that many combinations can lead to accurate results, with a preference for padding the signal before filtering and then cut the original window to avoid edge effects. Regarding the original window duration, longer ones (i.e. 0.7, 0.75 s) seemed to provide better results. Algorithms-wise, PF-PT [40] and SF-AR [5] worked best, whereas the SF-FFT [37] performed poorly, no matter the preprocessing. Supplementary tables 2(A) and (B) reports the ten best combinations for PF-PT and SF-AR and supplementary figure 2 the effect of each parameter of the grid-search while keeping the other constants. For most forecasting methods, the accuracy increased with the SNR (Spearman's corr = −0.56, p < 0.0001); above an SNR of 0.5 results were not significantly different (figure 1(a)). The verification on synthetic signal showed that addition of near-by sinusoids did not jeopardize the results. Computational cost wise, the SF-AR was the most demanding, taking up to 100 ms, whereas the other approaches were in the units of few milliseconds (figure 1(b)).

Figure 1.

Figure 1. Performance of phase-forecasting approaches on synthetic data. (a) Verification of the ten best combinations found with the grid-search on the synthetic signal according to different signal-to-noise ratios (SNRs). Here each point corresponds to error of each of the 50 trials tested in the ten different combinations, meaning that there are 500 points per boxplot. (b) Computational cost of each forecasting algorithm. Each block is made by 50 × 10 points, each corresponding to the error of each trial according to the ten different combinations used. For all the boxplots in this figure, the horizontal lines represent the interquartile range and the median; outliers are defined as such if they are smaller (or bigger) than 1.5 times the interquartile range than the first (third) quartile. Abbreviations of algorithms are: PF-PT = point forecasting with peak and trough [40], PF-FFT = point forecasting with FFT, SF-AR = signal forecasting with autoregressive model [35], SF-FFT = signal forecasting with FFT [37].

Standard image High-resolution image

3.1. Validation on real dataset

The ten-best combinations per algorithm (see supplementary tables 2(A) and (B) for examples) were first validated on healthy resting-state EEG. Phase errors increased for all methods compared to the synthetic dataset and the best approach for the latter was not necessarily the most performant on real data. For subsequent validation, we chose the new best combination and run it on both cohorts. Results are shown in figure 2; the preprocessing parameters chosen are reported in table 2. Due to its poor performance, SF-FFT was not considered for the following analyses.

Figure 2.

Figure 2. Performance of preprocessing pipelines chosen with a grid-search approach. Validation of the best combination found after an initial validation on a healthy dataset on both the healthy and the stroke cohort. Performance is divided according to the eye condition of the resting state (eyes open—RS_EO, eyes closed—RS_EC) and the channel used. An effect of channel, algorithm, and eye condition was observed (supplementary tables 3(A)–(D)). For all the boxplots in this figure, the horizontal lines represent the interquartile range and the median; outliers are defined as such if they are smaller (or bigger) than 1.5 times the interquartile range than the first (third) quartile.

Standard image High-resolution image

Table 2. Combination of preprocessing performing at best for each forecasting algorithm after verification on synthetic data and initial validation on healthy resting state EEG. Abbreviations used: PF-PT = point-forecasting peak-trough, PF-FFT = point-forecasting using FFT, SF-AR = signal-forecasting with autoregressive model, SF-FFT = signal-forecasting using FFT; RS = stop-band ripple, RP = pass-band ripple (these parameters are necessary only for Chebyshev and elliptic filters).

AlgorithmFilter nameFilter orderBandwidth (Hz)Edge cut (%)PaddingRSRPFSWindow (s)
PF-PT [40]Bessel210.31nana50000.75
PF-FFTButter420.11nana50000.75
SF-AR [5]Butter320.11nana50000.75
SF-FFT [37]Bessel2201nana50000.75

The LMM on the healthy data looking at categorical variables only, reported a significant main effect of channel, algorithm, and eye condition, but of no interaction (supplementary table 3(A)). Regarding the former, Fz was the worst performant (supplementary table 3(C), p < 0.001 for all pair-wise comparisons), whereas other channels did not differ significantly. When looking at differences due to forecasting algorithms, PF-FFT was statistically worse than the other approaches (p < 0.001 for all pair-wise comparisons); moreover, there was a trend of PF-PT being more accurate than SF-AR (EMM = 3.3° or 0.06 radians, p = 0.041, supplementary table 3(D)). When subjects have their eyes closed, the accuracy also seems to increase, but with a negligible effect size (from supplementary table 3(B) we can observe that the EMM is of around 2.3° or 0.04 radians, p = 0.037). Because according to eye condition and channel, a variable that is expected to change is the PSD in alpha (e.g. higher alpha PSD is expected in occipital areas during eyes closed), and because PSD is an important factor when filtering data, we have added to the equation the relative PSD in alpha (i.e. the area under the curve of the power spectra in alpha over the area under the curve in the 1–50 Hz band) and the bandwidth size. Indeed, the relative power in the frequency of interest is a significant factor that may lower the error in phase prediction, as reported by the results of the LMM (p < 0.001, supplementary table 4). In general, it seems that the inverse relation of PSD and phase error holds true independently of the categorical factors studied (i.e. channel, eye condition, algorithm, and bandwidth used for computing the PSD) as can be extrapolated for supplementary figure 3. This point becomes even more evident when taking as factor the absolute alpha PSD divided into quartiles per subject. By taking as an example PF-PT on young healthy subjects, we observe that if only very high PSD trials are considered (i.e. only PSD above the 75th percentile for the different subjects), the interquartile difference is decreased to less than 45°, compared to almost 90° when all trials are considered (supplementary figure 4(b)). Nonetheless, some outliers are still present, probably due to the subject, channel, and eye condition variabilities. Similar effects were seen in the stroke dataset (supplementary tables 5–9) and the two populations had overall similar accuracies when the same approach was applied in the same conditions (figure 2).

Figure 3.

Figure 3. (a) Comparison of original and optimized preprocessing for the same forecasting algorithm. Performance of the published forecasting algorithms with their original preprocessing and the one found with the grid-search. Results are divided according to data type (synthetic, healthy and stroke); in real data, the error comes from the different channels and eye conditions. If the desired phase (e.g. peak) could not be found in the future (e.g. the filter did not converge), a maximum error of π (i.e. 180°) was used. In the boxplots, the horizontal lines represent the interquartile range and the median; outliers are defined as such if they are smaller (or bigger) than 1.5 times the interquartile range than the first (third) quartile. Points, here thick areas are the outliers. Stars represent the value of significance after a paired Wilcoxon test. * = p < 0.05, ** = p < 0.01, *** = p < 0.001, **** = p < 0.0001. (b) Steps of peak forecasting using the original (red colors) or optimized (blue colors) preprocessing for the three algorithms. The input trial is noisy synthetic data with SNR = 0.5. Abbreviations of algorithms are: PF-PT = point forecasting with peak and trough [40], PF-FFT = point forecasting with FFT, SF-AR = signal forecasting with autoregressive mode [35], SF-FFT = signal forecasting with FFT [37].

Standard image High-resolution image

3.2. Grid-search on real data

To confirm that the chosen combinations were not biased by their training on a synthetic dataset, we ran the same grid-search on trials from ten randomly picked healthy subjects. Preferred filter choices remained consistent, but the window duration shortened (supplementary tables 2(C) and (D)). Nonetheless, when running the best combination from the synthetic grid-search with shorter window durations on the healthy dataset, larger errors were obtained compared to the longer windows.

In the comparison of the parameters from the individual and synthetic grid-search on a validating set of healthy subjects, no significant difference in accuracy was found.

3.3. Comparison with original algorithms' preprocessing

When the forecasting algorithms were tested with their original preprocessing, we found a significantly better performance for the optimized PF-PT and SF-AR on all data and conditions (figure 3(a)). Figure 3(b) shows on the actual signal how the optimized preprocessing differs from the original, suggesting why we are obtaining so different results. Notwithstanding the better performance of optimized approaches, the accuracy interquartile is still in the range of 45°–135°; similar plots to figure 3(a) where trials are labeled according to their PSD, we can see that accuracy can be improved with very high PSD (i.e. only PSD above the 75th percentile for the different subjects) with an interquartile range up to 45° (supplementary figure 4). This highlights again the relevance of high PSD already reported by the results of the LMM (supplementary table 4 and figure 3).

4. Discussion

Protocol differences, such as stimulation parameters and other experimental design choices, are often held responsible for heterogeneity in brain-state-dependent experiments' results. The present work highlights the relevance of signal processing, often arbitrarily decided by the researcher. Indeed, different choices in EEG filtering can lead to importantly diverse results in phase-forecasting accuracy (supplementary figure 5). Two main points should be emphasized: (a) outcome comparisons with different processing pipelines must be analyzed with care as applied functions on the raw signal can change its look at a very early stage of the data analysis; (b) no matter the forecasting method chosen, optimization of preprocessing is critical and can significantly improve precision (figure 3(a)).

Our grid-search approach for finding a suited preprocessing combined background knowledge and empirical data. All the combinations were valid, but tests on synthetic and real data rejected some while keeping others. In particular, this work highlighted important steps that should be followed in the EEG preprocessing: padding the signal before filtering is probably the most important step to perform at the beginning to avoid most of the edge effects that will be introduced by the filter itself. Regarding the latter, infinite impulse response filters with low-order are to be preferred; bandwidth-wise narrower bands were suggested by the grid-search, although wider ones may still be tested on real data. In terms of sampling frequency, this work suggests one between 1 and 5 kHz. Finally, algorithm-wise FFT-based ones (both point and signal forecasting) had the lowest performance, which may be due to the intrinsic stationarity of FFT, from which minimal discrepancies from the ground-truth can lead to large errors when moving away from the initial window. Rejection of tested combinations was based on accuracy, but also on computation cost given that time is a main constrain in online set-ups. Except for the SF-AR, forecasting approaches took less than 5 ms, a good value that accounts for only a 25th of cycle in the alpha band (and maximum a 6th of cycle in the highest beta band). The present analyses did not aim at optimizing the speed of processing, but rather looked at the cost of the different pipelines when the same level of code optimization is used. Regarding phase-forecasting precision, results from this grid-search showed that newly found preprocessing combinations significantly increased the accuracy of some of the published forecasting methods in both the healthy and the stroke cohort data. Outcomes from the latter were indeed very positive: to our knowledge this is the first time that phase-forecasting algorithms have been tested on such a large dataset of stroke patients in different time points after the ictal accident. The achieved accuracy, comparable to that of healthy subjects, implies that these algorithms can be applied even in situations with impaired brain functions, such as after a stroke. Moreover, we have observed that personalizing a grid-search for single subjects does not significantly improve the performance. Suggesting that the optimized method found works similarly on different subjects. Altogether, this provides an important step forward using state-dependent TMS-approaches as interventional tools to e.g. enhance the effects of neurorehabilitation.

In addition to highlight some important aspects and effects of EEG preprocessing, the goal of this study was to find optimized parameters for phase forecasting. The synthetic grid-search returned similar filters for different prediction algorithms that were also confirmed and strengthen by the individual grid-search on real data. Another relevant outcome of the analysis is the importance of the PSD, which can be read on two levels: firstly, for a filter and subsequently for a forecasting algorithm to perform well, a relatively strong signal (and SNR) is required (supplementary figures 2 and 3); secondly, the PSD strength can help defining if a neural oscillation is actually present. In this study PSD was only analyzed as a factor on accuracy as our aim was to determine the performance of the respective approaches with unbiased/unselected real data. However, given the strong effect PSD has on accuracy, we believe that in future steps towards online experiments, PSD may be used to define if a trial is eligible, as suggested by [42].

Finally, we acknowledge that other parameters and forecasting approaches (e.g. machine-learning based [43]) could have been added to the grid-search, but were beyond the scope of the present study. The grid-search approach as an optimization tool is one of several others available. We believe it is a good starting point due to its simplicity and when most of the parameters studied are categorical, rather than continuous, and are based on theoretical knowledge.

As future perspective, we believe that original and optimized approaches should be applied on the same TMS-EEG-EMG dataset and evaluate the actual effect of pre-processing and thus phase labeling on outcomes such as the MEP amplitude.

5. Conclusion

The present grid-search results underline the key role of EEG preprocessing steps and demonstrate that this methodology can be a tool for optimizing signal processing pipelines crucially important for brain-state-dependent or closed-loop NIBS approaches. Although the analyses focused on phase forecasting for brain-state-dependent stimulation experiments, the experience from it can be extended to other EEG analytical approaches. Finally, brain-state-dependent approaches were successfully tested on resting-state EEG data from patients after a stroke, paving the way to being able to determine critical factors relevant for brain-state-dependent novel interventional approaches even in patients with brain lesions.

Acknowledgments

We acknowledge access to the facilities and expertise of the Neuromodulation facilities of the Human Neuroscience Platform of the Fondation Campus Biotech Geneva.

Data availability statement

The scripts used for these analyses are publicly available and can be found at www.github.com/clovbig/grid_search_phase. The synthetic dataset can be regenerated from the scripts; while the real dataset used for this manuscript can be provided upon reasonable request.

Funding

The research was partially funded by the Wyss Center for Bio and Neuroengineering (AVANCER WCP030; Genève, Switzerland) to FCH; the Strategic Focus Area 'Personalized Health and Related Technologies (PHRT, #2017-205)' of the ETH Domain (CH) to FCH; the Defitech Foundation (Morges, CH) to FCH.

Author's contributions

C B conceptualized the method, wrote the scripts for the grid-search and different EEG preprocessing and performed the statistical analysis. A C M and T M acquired the data. F C H and T M supervised the work. All authors read and the approved the final manuscript.

Conflict of interest

The authors declare that they have no competing interests.

Ethics approval and consent to participate

All subjects from whom the data was acquired signed a written informed consent and the study was approved by the ethics committee of the Canton of Vaud, Switzerland (No. 2018-01355).

Please wait… references are loading.

Supplementary data (2.9 MB PDF)