## 2 Preprocessing
### Discrete Wavelet Transform  
The discrete wavelet transform (DWT) is a powerful signal processing technique often used for analyzing non-stationary signals, such as electroencephalogram (EEG) data. EEG signals capture electrical activity in the brain, and due to their complex nature, traditional Fourier analysis may not be sufficient to fully characterize their time-frequency features. DWT provides a multi-resolution analysis, making it particularly suitable for EEG signal processing. Here is a description of how DWT is applied to EEG signals: Overview of the discrete wavelet transform wavelet basics: Unlike the Fourier Transform, which uses sine and cosine functions, DWT uses wavelets--short, oscillatory, localized functions that can represent both frequency and time characteristics of a signal. Wavelets can be designed to possess different shapes and properties, allowing for adaptability to various types of signals. The DWT decomposes a signal \(x[p]\) using a pair of filters:  
* Low-pass filter \(h[p]\): extracts approximations (low-frequency components).  
* High-pass filter \(g[p]\): extracts details (high-frequency components).  
Decomposition Equations  
\[a_{i}[k] =\sum_{p}x[p]\cdot h[2k-p]\] \[d_{i}[k] =\sum_{p}x[p]\cdot g[2k-p]\]  
such that  
* \(a_{i}[k]\): approximation coefficients at level \(i\).
* \(d_{i}[k]\): detail coefficients at level \(i\).
* \(2k\): represents downsampling by 2.  
Multi-resolution analysis: DWT decomposes a signal into different frequency components by breaking it down into approximations (low-frequency) and details (high-frequency). The decomposition is performed recursively, producing multiple levels of resolution corresponding to different frequency bands. Decomposition process: The original EEG signal is passed through a series of filters: a low-pass filter (to extract approximation coefficients) and a high-pass filter (to extract detailed coefficients). This process is repeated on the approximation coefficients to yield additional levels of detail, creating a tree-like structure of coefficients. Each level recursively decomposes the approximation coefficients \(a_{j}\):  
\[x[n]\xrightarrow{\text{DWT}}\{a_{j}[n],d_{j}[n],d_{j-1}[n],\dots,d_{1}[n]\}\]  
Coefficients interpretation: The resulting coefficients provide insight into both the coarse (low-frequency) and fine (high-frequency) aspects of the EEG signal. The approximation coefficients are associated with slower brain wave activities (like delta and theta waves), while detailed coefficients tend to correspond to faster activities (like alpha and beta waves).  
In our Python 3.13.5 function apply_dwt, we initially employed the Daubechies 4 ('db4') wavelet with a fixed decomposition level of 5. The db4 wavelet is widely used due to its orthogonality, compact support, and its ability to provide a balanced representation in both time and frequency domains, making it suitable for diverse signal types.  
However, we recognize that the choice of wavelet should be guided by the specific characteristics of the signal under analysis. For example, the Haar wavelet is more effective for signals with abrupt changes, while smoother signals--such as those often found in biomedical applications--are better handled with Symlets or Coiflets.  
Moreover, we improved the adaptability of our approach by avoiding a fixed number of decomposition levels. Instead, the appropriate level is now determined dynamically based on the signal length and the filter length of the chosen wavelet. This is achieved using the PyWavelets function:  
\[\text{level}=\text{pywt.dwt\_max\_level(\text{len(signal)},\text{pywt.Wavelet (wavelet).dec\_len)}} \tag{1}\]  
This ensures that the decomposition captures relevant time-frequency features without unnecessary over-decomposition.  
To clarify the process, we have provided an example: Figure 1 displays the original EEG signal, while Figure 2 shows the reconstructed signal using DWT. The aim of this work is to regularize highly irregular EEG signals.