## 5 Methods
### Application of CNN-LSTM for Artifact Removal
#### 5.1.4 Proposed CNN-LSTM Structure and Training  
The proposed CNN-LSTM architecture is presented in Table 2. The network architecture was selected based on a series of ablation experiments, in which we tested different numbers of filters (32, 64, 128, 256, and 512) in the Conv2D, Conv1D, and LSTM layers. The primary selection criterion was the validation error (MSE), but it was not the only one. During model selection, we also assessed the quality of the cleaned EEG signals--both visually and in the frequency domain. Particular attention was paid to segments of the signal that did not contain artifacts, as it was essential that the network did not introduce distortions where no noise was present. Additionally, we considered various architectural variants, including models based solely on CNN layers, only on LSTM layers, and their combinations. The final model was chosen based on its ability to effectively remove artifacts while preserving the structure of the original signal. Figure 6: Generated EEG and EMG signals for training a CNN-LSTM. A matrix of 256 samples by 6 channels is fed into the network input. This corresponds to 1 s of data for the EEG channel that we aim to clean of artifacts, along with 5 additional channels capturing muscle activity (Fp1, HEOG, neck, cheek, nape, and jaw). The next layer is a two-dimensional convolutional layer (Conv2D). Its primary role is to analyze the relationships between the EEG and EMG samples. This layer uses filters with dimensions of 1 \(\times\) 6. Such filters represent a linear combination of samples at the same point in time across the different channels, analogous to operations like Laplacian spatial filters, common average reference (CAR) filters, or common spatial pattern filters. By doing so, the network can capture shared signal features from multiple channels, which may indicate the presence of artifacts. ReLU activation (rectified linear unit) introduces nonlinearity and helps the network learn complex relationships in the data while accelerating the training process by mitigating the vanishing gradient problem. Another important part of the network is the one-dimensional convolutional layer (Conv1D), which operates on the data processed by the Conv2D layer. The main goal of this layer is to amplify and extract samples in the EEG signal at the individual time-point level. Using the ReLU activation function here as well further enhances modeling performance and speeds up training. The output of this layer provides more detailed information on local changes in the EEG signal. After the Conv1D layer, the data is passed to a Reshape layer, which transforms the data into a format suitable for temporal analysis in the LSTM layer. The Reshape layer flattens the spatial dimensions while retaining the time information, a crucial step for subsequent analysis. The proposed approach allows spatial dependencies between channels to be encoded at the level of the first convolutional layer, which processes all channels simultaneously. These dependencies are not further processed in their original spatial form but are instead transformed into feature representations that are passed to the LSTM layer as temporal input. Although the explicit spatial structure is no longer preserved after the Reshape operation, we assume that relevant inter-channel patterns are captured during the early stages of processing and remain available in the subsequent layers of the network. A key component of the network is the LSTM (long short-term memory) layer, which analyzes temporal dependencies in the EEG data. LSTM is a specialized form of recurrent neural network that retains information about previous samples and incorporates that