Signal processing in BCIs: An GAM-based Approach to EEG/ERP Analysis using Python

— The goal of this research is to use non-linear linkages to analyze event-related potentials (ERP) in a regression framework (using splines, and General Additive Models - GAMs). The addition of extra information (such as data at the single-trial, - and even single-channel - level), as well as the computation of marginal means and contrasts, provide for a flexible and powerful manner of analyzing differences between circumstances when combined with the use of mixed models.


I. INTRODUCTION
For patients suffering from neurological diseases, the Brain Computer Interface provides a non-muscular communication pathway. The extraction of informative and discriminative features is required for the creation of an accurate and trustworthy BCI system. It is a system which takes a bio signal measured from a person and predicts some abstract aspect of the person's cognitive state. To control the machine using a brain interface we need to first get the information through brain activity. Electroencephalography is one option (EEG). Neuronal activity generates electric field potentials that can be measured with scalp electrodes. Although it becomes a little difficult, this EEG data can be filtered, processed, and used as a control signal for computers and robotic equipment, resulting in a brain-computer interface (BCI) or brainmachine interface (BMI). Signal processing, translation algorithms, and user training must all improve in order to achieve increased speed and accuracy. Event-Related Potentials (ERP) use electrodes linked to the scalp, similar to EEG. The main difference is that a stimulus (for example, a picture or sound) is delivered to the participant, and the researcher searches for activity connected to that stimulus. However, because ERPs are difficult to distinguish from background EEG data, the stimulus is shown several times (typically hundreds) and an average response is graphed. This 'averaging' method eliminates any superfluous brain activity, allowing the specific reaction to the stimulus to shine out.

A. Invasive or Non-Invasive
Both EEG and ERP have the advantage of being noninvasive procedures. EEG and ERP, unlike other scanning procedures like Positron Emission Tomography (PET), do not use radiation or need the insertion of devices into the brain, making them virtually risk-free. Furthermore, as compared to fMRI scanning, EEG and ERP are far less expensive and hence more widely available. As a result, more patients/participants should be able to participate in EEG/ERP studies, which could help psychologists collect more data on the working human brain and, as a result, improve our understanding of many psychological phenomena such as sleeping and illnesses such as Alzheimer's.

B. Spatial Resolution
EEG/ERP, on the other hand, has a low spatial resolution, which is one of its drawbacks. The smallest feature (or measurement) that a scanner can detect is referred to as spatial resolution, and it is an important element of brain scanning techniques. Greater spatial resolution helps psychologists to more precisely distinguish between distinct brain areas. EEGs/ERPs can only detect activity in the brain's surface areas. As a result, EEGs and ERPs are limited in compared to fMRI, which has a spatial resolution of 1-2mm and can provide information on what is happening in deeper parts of the brain (such as the hypothalamus).

C. Temporal Resolution
The EEG/ERP approach has a high temporal resolution: it collects readings every millisecond, allowing it to capture the brain's activity in real time rather than staring at a still brain. When doing a specified task, this results in a precise measurement of electrical activity.

D. Electrical Resolution
Another concern with EEG is that it frequently detects electrical activity in multiple areas of the brain at the same time. As a result, pinpointing the particular area/region of activity might be challenging, making it difficult for researchers to make reliable findings.
ERPs, on the other hand, allow researchers to see how a given experimental modification affects processing. ERP is a more experimentally robust method since it can remove extraneous neutral activity, which other scanning techniques (including EEG) may struggle to do.

III. PROCEDURE
The point of this study is to investigate the attainability of breaking down occasion related possibilities (ERP) under a relapse system, through the utilization of non-direct connections (utilizing splines, and General Additive Models -GAMs). Joined with the utilization of blended models, hypothetical advantages incorporate the consolidation of more data (like information at the single-preliminary, -and, surprisingly, single-channel -level), as well as the calculation of minimal means and differentiations, taking into consideration an adaptable and strong approach to dissecting contrasts between conditions. We will start by visualizing the "simple" grand average of all epochs as thick lines, as well as all epochs as thin lines. This will serve us as a baseline to check if our regression approach is on track.

B. Spline Regression
Spline relapse is a non-direct relapse which is utilized to attempt to defeat the hardships of straight and polynomial relapse calculations. In direct relapse, the whole dataset is considered on the double. However, in spline relapse, the dataset is partitioned into receptacles. Each canister of the information is then made to fit with independent models.

C. General Additive Model (GAM)
GAMs (Hastie and Tibshirani 1986,1990) are semiparametric expansions of GLMs, just making suspicion that the capacities are added substance and the parts are smooth. GAMs can manage exceptionally non-direct and nonmonotonic connections between the reaction and logical factors 1) How GAMs treat your information?
• Separate every indicator into hitches, k (segments) • Fitting of information in each part freely utilizing low request polynomial or then again spline capacities • Adds elements, everything being equal, to foresee the connection work (smoothing): that is why it is classified "added substance" model • Smoothing of bunches is finished by capacities in "loess" and "splines" contingent upon R bundle utilized • Model fitting depends on probability (for example AIC scores)

Fig 5: -Smoothening using GAM
As we can see, though it gives decent results, it seems like the default smoothing is a bit too strong. This is an issue as our process of interest (event-related potentials) are known to be of very high frequency with sharp changes. It is important to note that all the channels contribute in the same way to these differences, and taking into account the variability of this data could reinforce our model. We will add use the data from all the channels of the cluster by adding them as a random factor in the model (random slopes are added for the condition factor).

Conclusion
GAMs are a versatile and powerful tool for modelling ERPs. Furthermore, these models can be expanded to include more covariates, resulting in a higher signal-to-noise ratio.