## 2 Materials and Methods
### Signal Processing Applied to the Classification of Relaxation State
As a result, a new vector \(\mathbf{S}^{{}^{\prime}}\) is generated, which includes the corrected signals and corresponds to the following:  
\[\mathbf{S}^{{}^{\prime}}= \begin{bmatrix}\text{S}^{\prime}[0]\\ \text{S}^{\prime}[1]\\ \text{S}^{\prime}[2]\\ \vdots\\ \text{S}^{\prime}[249]\end{bmatrix} = \begin{bmatrix}\text{S}[0]-\overline{ \text{S}}\\ \text{S}[1]-\overline{\text{S}}\\ \text{S}[2]-\overline{\text{S}}\\ \vdots\\ \vdots\\ \text{S}[249]-\overline{\text{S}}\end{bmatrix}  \tag{5}\]  
The process repeats every second with a new set of samples, ensuring that each interval is free from biases and centered around zero. Signal segmentation: Once the system accurately captures the signal, it is imperative to segment it into well-defined sample segments corresponding to specific time intervals. This methodology enables the application of various processing algorithms to each packet, optimizing response time and facilitating real-time processing. Consequently, the signal \(x[n]\) was divided into multiple segments or windows of size \(N\). Each segment represents \(x_{k}[n]\), where \(k\) indicates the segment number:  
\[x_{k}[n]=x[n+kM],\ \ \ \text{with}\ n=0,\ 1,\ 2,\ \ldots,\ N-1 \tag{6}\]  
* \(N\) is the size of each segment (window). * \(M\) is the shift between windows, which can be equal to \(N\) (non-overlapping windows) or less (overlapping windows). This project uses windows of 250 samples, equivalent to one second, with a shift of 25 samples, corresponding to 100 ms. Noise reduction using wavelets: Implementing a noise reduction technique in this phase aims to attenuate unwanted noise in the EEG signal while preserving its original characteristics. The Discrete Wavelet Transform (DWT) decomposes the signal into different frequency components, allowing for the elimination or attenuation of undesired frequencies. The DWT of a signal \(f(x)\) represents the sum of approximation and detail coefficients across various decomposition levels [26]:  
\[f(x)=\frac{1}{\sqrt{N}}\left[T_{\varphi}(0,0)\varphi(x)+\sum_{j=0}^{J-1}\sum_{ k=0}^{2j-1}T_{\psi}(j,k)\psi_{j,k}(x)\right] \tag{7}\]  
In this context, the terms are defined as follows:  
\[T_{\varphi}(0,0)=\left\langle f(x),\varphi_{0,0}(x)\right\rangle=\left\langle f (x),\varphi(x)\right\rangle=\frac{1}{\sqrt{N}}\sum_{x=0}^{N-1}f(x)\varphi^{*}(x) \tag{8}\]  
\[T_{\psi}(j,k)=\left\langle f(x),\psi_{j,k}(x)\right\rangle=\frac{1}{\sqrt{N}} \sum_{x=0}^{N-1}f(x)\psi_{j,k}^{*}(x) \tag{9}\]  
\(N\) is a power of 2 (for example, \(N=2\)), where \(j=0,\ 1,\ \ldots,\ J-1\) and \(k=0,\ 1,\ \ldots,\ 2^{i}\ -1\). The scaling function is \(\varphi(x)\), and \(\psi_{j,k}(x)\) represents the mother wavelet. The equations \(T_{\varphi}(0,0)\) and \(T_{\psi}(j,k)\) represent the transformation coefficients, known as approximation and detail coefficients. In the signal processing, the Daubechies wavelet of order four was used, and a level 2 decomposition was performed, applying a soft threshold to the obtained coefficients. For the reduction, only the detail coefficients from both decomposition levels were considered, generally represented as \(cD_{i,k}\), where \(i\) indicates the decomposition level and \(k\) represents the multiple coefficients within each level. A threshold was applied for each set of coefficients at every level, which required estimating the noise for each decomposition level:  
\[R_{i}=\frac{Median(cD_{i,k})}{0.6745} \tag{10}\]  
Subsequently, the threshold \(\lambda_{i}\) was calculated using the following formula:  
\[\lambda_{i}=R_{i}\cdot\sqrt{2\cdot\log(N)} \tag{11}\]  
Then, soft thresholding was applied to the coefficients \(cD_{i,k}\), obtaining the new coefficients \(cD_{i,k}^{soft}\):  
\[cD_{i,k}^{soft}= \begin{cases}0&\text{si}|cD_{i,k}|\leq\lambda_{i}\\ cD_{i,k}-\lambda_{i}&\text{sic}D_{i,k}>\lambda_{i}\\ cD_{i,k}+\lambda_{i}&\text{sic}D_{i,k}<-\lambda_{i}\end{cases}  \tag{12}\]  
After attenuating the detail coefficients, the signal is reconstructed using the Inverse Discrete Wavelet Transform (IDWT).