## 2 Materials and Methods  
### Signal Processing Applied to the Classification of Relaxation State  
The detection process consists of two main phases: the training phase and the real-time evaluation. During both phases, the system performs the following steps:  
* Capture of signals from channels P7, O1, O2, and P8. * EEG signal summation. * Baseline correction. * Signal segmentation. * Noise reduction using wavelets. * Filtering signals with a Butterworth filter (8-13 Hz). * Application of the Fast Fourier Transform (FFT). * Numerical integration using the trapezoidal rule. * Thresholding. Capture of signals from channels P7, O1, O2, and P8: The signals were captured using OpenBCf(r) equipment (Brooklyn, NY, USA). Specifically, the 8-channel Cyton(r) biosensor board was connected to the Ultracortex Mark IV(r) headset for signal acquisition. This headset features electrodes positioned according to the international 10-20 system, ensuring correct placement and accuracy in signal capture. The electrode placement includes positions Fp1, Fp2, C3, C4, P7, P8, O1, and O2, along with two additional electrodes on the ears. These extra electrodes provide a precise and stable signal reference, helping to minimize interference and improve the quality of EEG signal capture. Only the signals from positions P7, O1, O2, and P8 were used to detect alpha waves. EEG signal summation: Combining signals from the four electrodes involves summating the first samples from each electrode to generate the first data point. Similarly, the summation of the second samples from each electrode yields the second data point, and so forth. This process creates a unified vector that denotes the electrical activity of the various EEG signals. The mathematical expression for the total summation of all signals at a specific sample period k can be stated as follows:  
\[\text{S}[\text{k}]=\sum_{\text{i=0}}^{\text{M}-1}\text{s}_{\text{i}}[\text{k }]\text{ where k takes the values }0,1,2,\ \ldots,\text{N}-1. \tag{1}\]  
The following are given:  
* \(\text{S}[\text{k}]\) represents the sum of all signals at the k sample. * \(\text{s}_{\text{i}}[\text{k}]\) denotes the value of the i-th signal at the k sample, for i = 0, 1, 2 and 3. * M is the total number of signals. * N is the total number of samples. As a result, the vector \(\mathbf{S}\) is obtained, which is detailed below:  
\[\mathbf{S}= \begin{bmatrix}\text{S}[0]\\ \text{S}[1]\\ \text{S}[2]\\ \vdots\\ \text{S}[\text{k}]\\ \vdots\end{bmatrix} _{\text{k}\rightarrow\text{N}-1}= \begin{bmatrix}\text{s}_{ 0}[0]+\text{s}_{1}[0]+\text{s}_{2}[0]+\text{s}_{3}[0]\\ \text{s}_{0}[1]+\text{s}_{1}[1]+\text{s}_{2}[1]+\text{s}_{3}[1]\\ \text{s}_{0}[2]+\text{s}_{1}[2]+\text{s}_{2}[2]+\text{s}_{3}[2]\\ \vdots\\ \vdots\end{bmatrix} _{\text{k}\rightarrow\text{N}-1} \tag{2}\]  
Baseline correction: The baseline in an EEG signal refers to the reference level around which brain signals fluctuate. EEG signals often exhibit a baseline shift caused by various external factors, such as electrode fluctuations, direct current interference, or noise. This shift makes the signal move vertically, placing brain activity oscillations at a biased level instead of a neutral one. A baseline correction is implemented to rectify this issue and enhance data quality by eliminating the undesired shift from the signal. Correcting the baseline of the EEG signal involves calculating the average over one second, corresponding to 250 samples. This average, denoted as \(\overline{\text{S}}\), is obtained from the data interval \(\mathbf{S}\):  
\[\overline{\text{S}}=\frac{1}{250}\sum_{\text{k}=0}^{249}\text{S}[\text{k}] \tag{3}\]  
Then, this value is subtracted from each sample in the interval to center the signal:  
\[\text{S}^{\prime}[\text{k}]=\text{S}[\text{k}]-\overline{\text{S}} \tag{4}\]  
The corrected signal sample \(\text{S}^{\prime}[\text{k}]\) is obtained for \(\text{k}=0,\ 1,\ 2\ldots 249\).