Investigation of automatic spindle detection in sleep EEG signals contaminated with noise and artifact sources

Electroencephalography (EEG) serves as the gold standard for noninvasive diagnosis of different types of sleep disorders such as sleep apnea, insomnia, narcolepsy, restless leg syndrome, and parasomnias. In this study, a novel automated cascade filter is introduced as a preprocessing tool for suppressing all noise and artifact interferences from sleep EEG signals before detecting sleep spindles. The multi-stage filter employs the Multi-Kernel Normalized Least Mean Square with Coherence-based Sparsification (MKNLMS-CS) algorithm in the first step to remove all artifact interferences while applying the 1-D patch-based Non-Local Means (NLM) algorithm in the subsequent step to remove all noise components. Three state-of-the-art automated spindle detection algorithms, namely Mc-Sleep, Spinky, and Spindler, are examined in EEG signals contaminated with noise and artifact components individually and concurrently. The spindle detection performance is investigated with real EEG data taken from the well-known DREAMS database, and the experimental results demonstrate the importance of the proposed multi-stage filter in enhancing the performance of spindle detection using the three spindle detection algorithms. This elucidates the robustness of the suggested multi-stage filter in providing high-resolution sleep EEG data from noisy EEG recordings. Also, experimental results reveal that Spinky algorithm outperforms Mc-Sleep and Spindler methods in detecting spindles for filtered EEG signals using several evaluation metrics, including accuracy (94.8% versus 92.0% and 94.6%), precision (53.4% versus 36.4% and 47.5%), specificity (97.3% versus 93.9% and 96.1%) and F1-score (58.2% versus 41.3% and 50.9%), respectively. This shows that combining the proposed multi-stage filter with Spinky algorithm outperforms the other two methods in detecting spindles in EEG signals, and it represents an efficient automated spindle detection system that achieves high diagnosis performance in terms of accuracy (94.8%), specificity (97.3%), and F1-score (58.2%).


Introduction
Electroencephalogram (EEG) is defined as a technique of recording the brain electrical activity through the scalp. EEG signals have crucial role in wide range of medical applications (Gloor 2015). One of the widely addressed applications is studying the behavior related characteristics of the EEG signal in sleep state, which helps in further understanding of many neuropsychiatric diseases and different cerebral conditions. Sleep analysis is one of the most addressed topics within the EEG signal processing research area. Sleep stages when first classified, were divided into five stages according to the Rechtschaffen and Kales (R & K) standard. The first four stages were the Non-Rapid Eye Movement (NREM) sleep stages (S1, S2, S3, and S4) and the fifth was the Rapid Eye Movement (REM) stage. Recently, a new approach by the American Academy of Sleep Medicine (AASM) suggested merging stages S3 and S4 to eventually have only 4 stages (N1, N2, N3, and R) (Taran et al. 2020;Diykh et al. 2020). The features of each stage define a certain brain activity and span a particular frequency range. Evidently, the proportions of these stages in the EEG signal alter over the human life span according to the neural changes (Weiner and Dang-Vu 2016).

3
In the second sleep stage, known as NREM2, the principle existing features are K-complexes and sleep spindles. A K-complex, a slow wave activity, is known to be a wave-pattern with a distinctive shape that can be a spontaneous event or a result of evoking (Weiner and Dang-Vu 2016). On the other hand, sleep spindles are bursts of coherent brain activity that prevail an EEG signal in one or more scalp areas, with a relatively higher frequency span from 11 to 17 Hz, and duration from 0.5 to 2 s. Sleep spindles are sinusoidallike signals that correlate to the neural oscillations due to transit of rhythmic bursts to the thalamus which is primarily responsible of the cognitive human profile (Lacourse et al. 2019;Huupponen et al. 2007). As any characterized feature in the sleep stages, sleep spindles confront a dramatic change along different age period. Other related spindles' parameters such as period, magnitude, or rate of occurrence remain stable for each individual person but rather differ within various individuals. Being related to the prefrontal cortex, it was widely reported that spindle activity compromises the neurocognitive performance and memory consolidation (Weiner and Dang-Vu 2016;Fogel and Smith 2011;O'Reilly et al. 2017;LaRocco et al. 2018;Fernandez et al. 2020). Also, some studies suggested that the presence of spindles can be categorized into two types. The first spindle type has a low frequency range at roughly 12 Hz, and it occurs mainly in the frontal brain activity area. The second high frequency type at over 14 Hz, which is often processed and detected, is present over the central and parietal areas (Gennaro and Ferrara 2003). It was reported that sleep spindles contribute to sleep studies implementations and medical diagnosis for multiple clinical disorders such as schizophrenia Manoach et al. 2016), autism (Farmer et al. 2017), epilepsy (Bruder et al. 2017), Parkinson's disease ), Alzheimer's (Huupponen et al. 2007;Kam et al. 2019), REM sleep behavior disorder (O'Reilly et al. 2015;Sunwoo et al. 2021), Attention Deficit Hyperactivity Disorder (ADHD) (Dea et al. 2019), and mental retardation .
Sleep spindles are clinically important because changes in spindle properties (e.g., density, frequency, morphology, spatial distribution) can distinguish several sleep disorders, such as sleep apnea, insomnia, narcolepsy, restless leg syndrome, and parasomnias. Sleep spindle characteristics were studied in the EEG signals of children with sleep disordered breathing (Brockmann et al. 2018(Brockmann et al. , 2020, and adults with idiopathic narcolepsy (Christensen et al. 2017), hypersomnia (DelRosso et al. 2014, and restless leg syndrome (Cha et al. 2020). Several studies showed that insomnia complaints are caused by a reduction in the spindle density (Cote et al. 2000;Dang-Vu et al. 2010). In DelRosso et al. (2021), properties of sleep spindles in children with Restless Sleep Disorder (RSD), restless leg syndrome, and normal controls were investigated, and the results showed that children with RSD had longer frontal spindles duration in the N2 stage than normal children. Several studies reported that the sleep spindle density of individuals with narcolepsy differs significantly from paired control cases, revealing that sleep spindle density could be a sign of a weakened mechanism of awakening (Christensen et al. 2017;DelRosso et al. 2014). In O'Reilly et al. (2015), characteristics of sleep spindles, including amplitude, duration, density, and frequency were compared between patients with REM sleep behaviour disorder and healthy groups. Results showed that lower spindle densities were obtained for REM sleep behaviour disorder patients than for paired control individuals, revealing its importance as a probable sign of future neurodegeneration in these patients. Some studies showed major dissimilarities in sleep spindle features between participants with and without Obstructive Sleep Apnea Syndrome (OSAS) during all NREM stages , while other studies revealed considerable variations in spindle features between the two groups in REM sleep (Appleton et al. 2019). In Mohammadi et al. (2021), the density and duration of sleep spindles were studied during N2 and N3 stages among adults diagnosed with OSAS and healthy controls. Results reveal that OSAS is accompanied by a considerably lower spindle density during the N3 stage and a shorter spindle duration during the N2 stage.
Before the use of automated methods, detection of sleep spindles was carried by visual inspection, which is though being one of the most accurate methods, and thus called the gold standard for the sleep spindle detection. However, visual inspection is boring and error-prone due to tiredness beside having some differences between experts' decisions (Warby et al. 2014). On the other hand, automated techniques offered more reliability and objectivity to the spindle detection process and proved to have an increasing accuracy along the past few years (Weiner and Dang-Vu 2016). One of the earliest methods used was the band-pass filtering and amplitude threshold, often combined with spectral analysis (Schimicek et al. 1994). A modification of this filtering technique was to use a wavelet transformation, allowing the detection of signal power changes along the time-frequency domain and thus providing more efficiency and accuracy (Adamczyk et al. 2015;Sitnikova et al. 2007). A further modification of considering the spindle shape characteristics is performed by setting two threshold values, one for detecting the activity spike in the frequency range and the other for considering the spindle duration (Ferrarelli et al. 2007). Another approach that also depends on spindle shape characteristics was employed by applying feature extraction followed by automatic spindle classification method using Short Time Fourier Transform (STFT) (Devuyst et al. 2011;Weiner and Dang-Vu 2016). Other sleep spindle detection algorithms were also proposed such as Sequential Discounted Auto-Regressive (SDAR) modeling that works on capturing statistical changes in spindles' frequency band (Uygun et al. 2013), and Signal Envelope Modeling (SEM) that basically depends on the filtering criteria using a time varying threshold (Uygun et al. 2019). Some new studies also considered emulating the experts' spindle detection process through using a correlation filter between the raw EEG signal and the signal after being filtered in the sigma band, where the spindles occurrence is explicit (Lacourse et al. 2019).
Sleep spindle detection methods can be categorized into two main classes. The first category contains the unsupervised algorithms, where parameters of the algorithm are fixed such as Continuous Wavelet Transform (CWT) (Tsanas and Clifford 2015) or SEM (Uygun et al. 2019). The other class of the spindle detectors includes the algorithms where the parameters are set accordingly to find the optimum value for giving best performance compared to the gold standards of the experts' annotations. Examples of this category include a toolbox for spindle and k-complex (Spinky) that is based on Q-tunable wavelet estimation filter (Lajnef et al. 2015(Lajnef et al. , 2017) and a multi-channel sleep spindle detection method (Mc-Sleep) that is based on sparse low rank optimization (Parekh et al. 2017). Another novel approach, Spindler framework, suggested a different criterion where the parameters are set, not to find best match for expert's annotations, but rather find a stable point in a parameter grid that would grant stability for spindle property surfaces (LaRocco et al. 2018).
One of the main obstacles that affect the precision of EEG recording operation, and hence the accuracy of their relative clinical interpretations such as sleep spindle detection process, is the presence of different noise sources such as Additive White Gaussian Noise (AWGN) caused by the recording stage and various unwanted non-cerebral potentials coming from biological or external sources called artifacts. The artifacts contaminated with EEG signals include Electrooculography (EOG) which is produced by eye movements (Noorbasha and Sudha 2021), ElectroMyoGraphy (EMG) which is caused by muscle activities (Chen et al. 2021), and Electrocardiogram (ECG) which is excited by heart beats. Such artifacts and noise sources greatly corrupt EEG recording and lead to significant changes in the accuracy of sleep spindle detection. Therefore, it is very essential to examine the capability of different automated sleep spindle detection techniques when artifact and noise sources are present or not present in EEG signals. Note that some studies reported spindle detection results after eliminating all noises and artifacts manually which prevents their implementations in any automated diagnosis systems. For totally automated system, the sleep spindle detection technique must be assessed on unprocessed data.
The aim of this study is to introduce a new automated multi-stage filter as a preprocessing tool for suppressing all noise and artifact interferences from sleep EEG signals before detecting sleep spindles and to investigate the performance of different automated sleep spindle detection techniques. The performance of the spindle detection is assessed before and after eliminating noise and artifact interferences from the EEG signal. A novel automatic multi-stage filter that integrates the Multi-Kernel Normalized Least Mean Square with Coherence-based Sparsification (MKNLMS-CS) technique with the Non-Local Means (NLM) method, is employed before the sleep spindle detection process, and its efficiency in improving the diagnosis performance is studied along with a simultaneously held comparison between three state-of-the-art spindle detection techniques, namely Mc-Sleep, Spinky, and Spindler. The remainder of this paper is structured as follows. In section II, the Mc-Sleep, Spinky, and Spindler algorithms are presented. Then, the suggested preprocessing multi-stage filter is explained. Section III explains the experimental results of the sleep spindle detection using real EEG data. Then, the performance of the three sleep spindle detectors (Mc-Sleep, Spinky, and Spindler) is compared before and after removing the noise and artifact components. The experimental results are discussed in section IV and the conclusions are provided in section V.

Methodology
In this work, three state-of-the-art spindle detection algorithms, namely Mc-Sleep, Spinky, and Spindler, are investigated using sleep EEG signals contaminated with noise and artifact sources. The performance of each spindle detection algorithm is assessed before and after suppressing noise and artifact interferences using a new multi-stage filter that employs the MKNLMS-CS method in the first phase to remove all artifact sources and utilizes the NLM algorithm in the subsequent phase to eliminate noise sources (Eltrass and Ghanem 2021). The three spindle detection algorithms are examined on the public DREAMS sleep EEG database which was obtained in a sleep laboratory of a Belgium hospital utilizing a digital 32-channel polygraph (Devuyst 2005).

Mc-Sleep algorithm
In Mc-Sleep algorithm, the EEG signal is assumed to be composed of both a transient part and an oscillatory part. The algorithm runs in three main stages. It starts with first estimating a model for the EEG signal that is composed of three components, transient component, oscillatory component, and AWGN. Then, a multi-channel separation algorithm is utilized in the EEG signal decomposition process. Once the EEG signal is derived into its transient and oscillating parts, the oscillatory part is band-pass filtered, then the spindles are detected using an estimated expedient envelope (Parekh et al. 2017).
The algorithm's characteristic privilege is that instead of using a single channel in the detection process, it uses multiple channels at a time, taking into consideration that sleep events can be noticed in a certain channel more vividly than another. It is the same concept sleep experts use when annotating sleep spindles by using either channels (F4, C4, and O2) or (Fz,Cz,and C4) in the visual inspection. The use of multiple channels in the detection process can also contribute towards achieving a reduced computational time since the spindle threshold is no longer tuned for every single EEG channel when analyzing the global spindle activity but it is calculated once using an approach that is independent of the number of EEG signal channels (Parekh et al. 2017).
In this work, vectors and matrices are denoted by lowerand upper-case letters, respectively. Define ℝ as the group of all real numbers and consider k × n dimensional input matrix Y ∈ ℝ k×n . For a matrix Y , the l 1 norm ‖Y‖ 1 and the l 2 norm ‖Y‖ 2 2 are defined as follow (Parekh et al. 2017): Another useful norm for a matrix Y is the nuclear norm ‖Y‖ * which is defined as the sum of all singular values of the matrix Y. It can be expressed as: where tr(.) represents the trace of matrix, Y T is the matrix transpose of matrix Y , and o i (Y) means the i-th singular value of Y.
First, a nonlinear signal model Y for the EEG multi-channel recording with k channels, is created in the form: where Z denotes the transient part, S represents the oscillatory part, and W denotes the AWGN. In this approach, it is considered that the transient part Z is sparse and piece-wise constant, while blocks extracted later from the oscillatory part and potentially tested for spindle occurrence are concluded to be low-rank approximations. This concept will be explained while presenting the low rank operator.
The second step is separating oscillatory and transient components. The block low rank operator is used to perform a sparse optimization on the input EEG signal and to separate the oscillatory component. To further understand the block low rank operator, consider a segment of multi-channel EEG signal from the DREAMS sleep database as shown in Fig. 1, where only the highlighted block 2 is annotated as a spindle by experts. When calculating the singular values for each block as shown in Fig. 2, it is explicit that block 2 has the highest value that specifically corresponds to channel Fp1-A1 in Fig. 1a, where the spindle is most visually obvious. When applying low rank approximation on the three blocks shown in Fig. 1 and substituting their value with their rank-one approximation, it will be anticipated that block 2 will still expose the spindle like oscillation. Therefore, to extract the spindles, it is essential to first get the low rank  optimization for the EEG signal once the piece-wise constant transient component is eliminated.
Consider a multi-channel signal Z ∈ R k×n with k channels where: Before proceeding the separating process, the block low-rank operator used to get the oscillatory component from the EEG signal is explained. Define an operator ψ ∶ R k×n → R k×l×m which extracts m blocks, each of lengthl , from the channel input signal as follows: Now define the adjoint operator ψ T ∶ R k×l×m R k×n which constructs the k-channel signal by adding the m blocks in an overlap-add way. This means that the m blocks, each of sizek × l , are overlapped and added to restore a signal of sizek × n . When the added blocks are distinct (no overlap between blocks), the operator becomes orthogonal ( ψ T ψ = I ), leading to perfect reconstruction of the signal. In this work, the operator ψ with 50% overlap of block size 1 sec is used to obtain perfect reconstruction. This means that in case of a signal with 200 Hz sampling frequency, it is recommended to use a block length of l = 200 samples. After successively applying the operator ψ and performing the overlap-add operation, the resultant signal, in case of overlapped samples, contains within it the overlapped samples repeated twice. Consequently, appropriately weighting the samples can result in perfect reconstruction. A diagonal matrix G ∈ R n×n is formed to define weights for signal samples to recover the signal Z fromψ(Z) . To explain this operation, consider the single-channel signalZ = z 1 , z 2 , z 3 , when applying the operator ψ of block length 2 samples with 50% overlap, it results in: Reconstructing the signal by the overlap-add operator V(.) with predefined percentage of overlap we obtain: Applying this to a multi-channel signal with individual blocks of size k × l, the result from the constructed signal would be of size k × n. To get a perfect reconstruction ( ψ T (ψ(Z)) = Z ), we use a weight matrix G ∈ ℝ 3×3 defined as: The weight matrix G accompanied by the operator ψ of 50% overlap is formed according to the input signal length and the block length assigned by user and recommended as previously to be 1 s. For an input signal Z ∈ R k×n , n > 3 , the diagonal weight matrix can be expressed as: The oscillatory component is estimated using an optimization problem formulated as follows (Parekh et al. 2017): , o i ∈ R k×l , and thereforeO * ∈ R k×l×m . The term ‖o i ‖ * is the nuclear norm of the multi-channel oscillatory signal. The regularization parameter > 0 has an impact on the sparsity and it will be explained later. The blocks o i are estimated by solving the optimization problem in (11), and they are used to calculate the oscillatory com-ponentS , whereS = ψ T (O * ).
The spindles are detected by first approximating the transient and the oscillatory parts in the signal model of (3) using the recorded multi-channel EEG. This can be performed by employing a sparse optimization structure to resolve the next objective function: where H = ψ T and Z = z 1 , … , z k .z i ∈ R n represents the transient component blocks. The regularization parameters i ≥ 0 affect the sparsity for each component associated with it in (12), respectively. This means that large value of 0 , relative to 1 and 2 , imposes the transient part Z to be sparse with zero rank. Also, the higher the value of 2 compared to 0 and 1 , the lower the rank optimized for the oscillatory component. Reaching the suitable high value of 2 assures rank-one approximation. D is the first order difference matrix, where D ∈ R (n−1)×n . The given objective function in (12) targets the optimal sparse piece-wise transient represents the l 2 norm aiming to minimize the AWGN component. The term ‖z i ‖ 1 corresponds to the l 1 norm of the transient component, and similarly ‖Dz i ‖ 1 corresponds to the l 1 norm of the differential signal of the transient component. The unconstrained function combines a two-penalties term called 'fused-lasso' by combining the l 1 norm of Z which suppresses the nonsparse solutions and the l 1 norm of Dz i to suppress the nonpiece-wise constant solutions. It targets penalizing the part where block low rank quality is absent. Using the solution O * from (12), the oscillatory part is estimated by applying the operator H = ψ T such as S = ψ T (O * ) . The estimate of S will be then used in the sleep spindle detection.
The optimization function in (12) is solved by applying first Douglas-Rachford proximal splitting and Alternating Direction Method of Multipliers (ADMM) method followed by using Lagrangian minimization. This results in a problem of three sub-problems that can be solved using a fast iterative procedure to obtain solutions for Z * and O * .
First, the optimization problem in (12) can be rewritten using variable splitting as follows: such that N = Z and P = O , where N ∈ R k×n and P ∈ R k×l×m . Using Lagrangian minimization method, minimizing (13) leads to three sub-problems as follows: where ≥ 0 is the Lagrangian step-size parameter. D 1 ∈ R k×n and D 2 ∈ R k×1×m are the Lagrange multipliers.
The second sub-problem in (15) can be reformed after replacing the first term with the energy over the channels N, P and D 1 , followed by writing it over each z i along with applying the fused-lasso technique to each channel of the corresponding signal. The solution for each z * i is given by: andd (1,j) , for i = 1, … , k are the i th channel ofN, Z , and D , respectively. The term tvd(.) denotes the solution of the 1-D total variation denoising technique (Rudin et al. 1992) and soft(.) refers to soft-thresholding function.
Using the same approach, a similar estimation for the third sub-problem in (16) can be obtained with the Singular Value Thresholding (SVT) technique. This allows calculating the singular values of the input matrix and the thresholds using soft-thresholding function. The solution can be expressed as: where o i ∈ R k×1 and svd(.) corresponds to the singular value decomposition. Lastly, the first sub-problem in (14) can be resolved utilizing a convenient substitution using the least squares technique.
The approximated multi-channel oscillatory part is used to find the sleep spindles. To eliminate non-spindle like signals extracted by the oscillatory part, the estimated oscillatory part is exposed to a 4th order Butterworth band pass filter BPF(S) , where S is the oscillatory component. The bandwidth is set according to the input multi-channel EEG signal and the non-spindle like component present in the oscillatory signal. Followed by the filter, the Teager operator T(.) is applied to the average of the multi-channel band-pass filtered oscillatory part ( BPF(S) ) to estimate an envelope of the oscillatory waveform and to identify the spindle events activity. With the use of a constant threshold c , a binary signal b spindle (t) can be defined as where 1 indicates a spindle detected while 0 means no spindle activity detected (Parekh et al. 2017). The structure of Mc-Sleep algorithm is illustrated in Fig. 3.

Spinky
Spinky is an algorithm utilized for simultaneously detecting spindles and k-complex presence (Lajnef et al. 2017). It is an applied framework based on combining the Tunable (Selesnick 2011). The algorithm assumes that the EEG signal is composed of two elementary components, the oscillatory component that contains the spindles' events and the transient component that contains the K-complex waveforms. The TQWT generates a sparse representation of the EEG signal segments and the MCA is then used in the decomposition process. Combing both TQWT and MCA methods enhances the performance of detecting spindles (Selesnick 2011). After that, the Continuous Wavelet Transform (CWT) is applied to the oscillatory part to detect the spindle events. Note that the morphological structure of sleep spindles and k-complex differs because spindles have an oscillatory property while k-complex is a transient event.
Both TQWT and MCA algorithms are used to efficiently separate the two components.
TQWT is an advanced form of DWT in which the Q-factor is tunable to make the filter compatible with the input signal. This allows a more efficient separation of the oscillatory and the transient signals (Weiner and Dang-Vu 2016). TQWT, like DWT, contains two-channel filter bank, where the low-pass output of each filter bank is the input to the next filter bank. A sub-band is then defined as the output signal of each high-pass filter. If the number of filter banks is J , then the number of sub-bands equals J + 1 . At each filter bank, there are two sub-bands, a lowpass sub-band L j [n] that utilizes a low-pass filter H j 0 (w) followed by a low-pass scaling A and likewise a high-pass band G j [n] that uses a high-pass filter H j 1 (w) followed by a high-pass scaling B . Both low-pass and high-pass filters are described as follows (Lajnef et al. 2015): and There are three main parameters to set in the TQWT algorithm (Selesnick 2011): It specifies the oscillatory attitude of the wavelet filter. By adjusting the Q-factor, the oscillatory behavior of the output result is accordingly varied. It can be modified to match the lowest count of cycles in a spindle burst to efficiently extract the oscillatory component (spindle events). The value of the Q-factor is set to be 5.5 for efficient spindle detection. II. Redundancy parameter (r) : It masters the excessive ringing to localize the wavelet in time, while preserving its shape. This assures filtering the signal efficiently without distorting the time domain characteristics. This parameter is calculated from the formular = B∕(1 − A) , where the value r = 3 is proven to provide the best performance in biomedical signal processing applications (Lacourse et al. 2019). III. Maximum number of levels (J max ) : The parameter J determines the number of filter stages and its maximum value is set based on the input signal length ( N ) and the scaling parameters ( A and B ), where After applying the TQWT method, the MCA is employed to decompose the signal into oscillatory and transient parts. If the result of TQWT sparse transformation is a signal y , then the MCA is employed to decompose y into an According to the MCA implementation, the sparse wavelets coefficients associated with the oscillatory and transient components, annotated by w 1 and w 2 respectively, can be approximated by solving the minimization problem of the next function (Lajnef et al. 2015): where Ψ 1 and Ψ 2 are two matrices that contain parameters of the TQWT algorithm: Q 1 , r 1 , J 1 and (Q 2 , r 2 , J 2 ) , respectively. w 1 and w 2 are vectors that contain the transformation sub-band outputs concatenated, while Λ 1,j and Λ 2,j are the regularization parameters of lengths J 1 + 1 and J 2 + 1 , respectively, associated with the two filtering processes. By solving the objective function in (23), the two components can be estimated by y 1 = Ψ * 1 w 1 and y 2 = Ψ * 2 w 2 , where Ψ * 1 and Ψ * 2 are the inverse TQWT matrices. Sleep spindles are detected using the resultant oscillatory part from the EEG decomposition operation explained above. Since the spindles' waveforms do not have certain amplitude range but rather a distinguish waveform in time that reveals an established range of frequencies in spectrum. A simple threshold cannot be applied directly to this signal, and instead the CWT algorithm is utilized to inspect the existence of sleep spindles. The wavelet function selection is optimized by calculating the cross-correlation between spindle waveforms present in the training dataset and multiple wavelet functions (Teolis 2017). It was proven that complex frequency B-spline wavelets (Fbsp) achieves the highest median cross-correlation with spindle waveforms (Lajnef et al. 2015). It is defined as: where m ≥ 1 is an integer parameter that controls the time-frequency resolution, fb is the bandwidth parameter, and f c is the wavelet center frequency. Both fb and f c are set so that the Fbsp wavelet transform is compatible with the spindles' frequency range (11-17 Hz).
After creating a time-frequency map of the oscillatory part using the Fbsp transform, a sliding window is used across the 2-D time-frequency space to inspect all local maximum values that surpass the eight neighboring points in the 2-D time-frequency space. Then, a threshold is applied to the resultant maxima in the time-frequency map. Eventually, the threshold is estimated in the calibration stage by making a plot for the Sensitivity ( Se ) change along with the (23) .e j2 f c t � False Detection Rate (FDR) after creating a mathematical model that contains a wide range of potential thresholds. These curves are like Receiver Operating Characteristics (ROC) plots and they are created by measuring the change of Se and FDRs with multiple threshold parameters values while using experts' annotations as a ground truth. The optimal threshold is chosen based on maximizing the difference between Se and FDR of the spindle detection (Lajnef et al. 2015). Figure 4 shows the structure of Spinky algorithm.

Spindler
Unlike other spindle detection algorithms which select the parameters to optimize the performance based on expert labels, Spindler considers creating spindle's property surfaces and selecting a stable set of parameters that accommodates it. The main purpose of Spindler strategy is not selecting optimal values for parameters to match expert ratings but rather specifying a central point on the parameters grid thus any slight change in parameters' values would result in the minimal change in the spindles' property values (LaRocco et al. 2018). This allows a stable and reliable decision process for spindle detection. The Spindler algorithm runs in three consecutive stages. The first stage is the signal decomposition utilizing Matching Pursuit (MP) with Gabor atoms. In the second step, a parameter grid surface is created for the spindles' parameters, and spindle properties are evaluated. The last stage is the parameter selection evidentiary process which depends on the geometry of the spindle property surfaces. Spindle properties rely mainly on two parameters: N s (number of Gabor atoms/sec utilized for signal representation) and T b (a threshold applied to the reconstructed signal to determine the existence of a spindle). Consider a single-channel EEG data Z(t) (channel C z in the current study). First, Spindler filters the EEG signal Z(t) within the spindle frequency range (11 to 17 Hz), then the signal is decomposed using MP as a weighted summation of Gabor atoms as follows: where N is the total count of atoms utilized in the signal representation or the product of N s with the signal length in sec. The Gabor atoms, g , are characterized by four pre-specified parameters as follows: where f is the allowed atom oscillation frequency in the spindle frequency range (11 to 17 Hz) with a step of 0.5 Hz, h is the half width of the atom's Gaussian envelope (0.0625, 0.125 or 0.25), τ represents the allowed atoms replacement centered at every time instant, and } is the Gabor atom sinusoidal phase (assumed to be 0). Spindler employs an effective greedy design to project candidate atoms on the signal and successively prevent the contribution of the atom whose projection has the highest absolute value. The MP representation is calculated once the algorithm reaches a specified maximum number of atom rate N s such that the overall reconstruction of the signal with a larger count of atoms for each atom rate value is assured to be a superset of representations with smaller number of atoms. This means that the MP representation should be calculated once to produce the signal on a parameter grid of N s . For best performance, the values of a, f , h, , } should be kept for each atom added to the representation between the current value of N s on the parameter grid and the next. The signal reconstruction for each chosen N s can be speedily recalculated. N s is tuned in the range of 0.01 to 0.4 with a step of 0.01 because spindle rate diverges for N s values above 0.3 for all cases under investigation.
In the second step, the existence of a spindle in a reconstructed signal at (N s , T b ) is detected by taking the absolute value of the reconstructed signal and then dividing by the 95th percentile of these values and scaling any value greater than 95th percentile to 1 to eliminate the excessive values in the reconstructed signal. This limits the value of the threshold T b to be between 0 and 1, which enables creating a parameter grid adequate for different EEG datasets. Following that a mask is formed over all the datasets that exceeds the value of the specified threshold T b . Spindler then joins adjacent pieces based on the minimum spindle separation to the mask, and it suppresses spurious pieces according to the minimum and maximum spindle length criteria. Spindles are found as regions of sequential ones in the mask, resulting in a roster of spindle events for every (N s , T b ) on the parameter grid (see Fig. 5).
After creating a vector for the spindle events detected for each point on the parameter grid, three spindle parameters are calculated for each point and three property surfaces are formed for those parameters (see Fig. 5). Figures 5a, b, c show, respectively, the spindle rate, the fraction time spindling, and the average spindle length against the atom rate N s for fixed values of threshold T b extending from 0 (dark blue) to 1 (red) with the ultimate values T b = 0 and T b = 1 highlighted using thick dashed and dotted teal lines, respectively. The centered parameter value is calculated by averaging the respective parameter value at T b = 1 and T b = 0 for each value of N s , marked by thick solid teal line. Thick gray horizontal line illustrates the range of N s values that provide a threshold-insensitive estimation of spindle rate. The objective of these property surfaces is to find the parameters' values at which any change of its value causes the least change in the spindle property value, resulting in a reliable spindle detection system so that different datasets can be analyzed consistently. The structure of Spindler algorithm is shown in Fig. 6.
It can be noted from Fig. 5a that for small values of N s , the spindle rate curves overlap for any threshold value, while spindle rate values differ for large values of N s . This is because the greedy MP strategy allows detecting spindles with high energy level (relatively long) using limited Fig. 4 Structure of the Spinky algorithm count of atoms representing the signal. On the other hand, representing the signal with large number of atoms increases the accuracy of spindle detection, allowing for higher resolution of spindle rate indication which enables the detection of spindles with lower energy levels. Spindle rate saturation is achieved for a given threshold when an increase in the atom rate value does not lead to the detection of any more spindles. Since there are multiple saturation points for each threshold value as shown in Fig. 5, the restricted range for N s is chosen to be less than the first saturation point. The N s range is also determined such that the standard deviation of the spindle rate marked by the darker gray curve is larger than 0 which authenticates that spindle rate is not fully independent of the threshold. The thick gray horizontal line shown in Fig. 5 marks the resulting eligible range of N s . To obtain the specific values of the threshold and the atom rate, a central curve is obtained by averaging the spindle fraction curves at T b = 0 and T b = 1 . From the fraction time spindling property surface, the desired threshold T b * is affiliated with the closest curve to the resultant central curve in the entitled range of N s and marked by the thick black line which illustrates the curve relevant to the chosen value for T b * . Finally, using the spindle length curve for T b * , Spindler chooses the value of N s * that corresponds to the minimum spindle length in the allowed range of N s which is marked by the gold vertical line. As mentioned before, unlike other spindle detection algorithms, Spindler framework does not assure optimum performance in the sense of agreement with experts' annotations as ground truth but rather provides reliable and stable system by selecting a central point on the parameter grid so that minor variations in parameter values do not lead to major variations in spindle property values.

Proposed multi-stage filter
In this work, the capability of sleep spindle detection is evaluated before and after eliminating all noise and artifact interferences from the sleep EEG signal. A novel automated multi-stage filter that combines the advantages of MKNLMS-CS and NLM methods is employed by suppressing artifact components in the first step using the MKNLMS-CS technique and eliminating the white/ colored noises in the second step using the NLM method. Figure 7 shows the block diagram of the multi-stage filter. Parameters of the MKNLMS-CS, namely kernel parameters ( ζ 1 and ζ 2 ), coherence threshold ( δ ), step size ( η ), and regularization parameter (ρ) are roughly tunned to provide the highest accuracy as shown in Table 1. Parameters of the NLM method, including bandwidth parameter B , the patch size L Δ , the size of neighborhood search N(s) , are optimized to acquire superior results (see Table 1). The spindle detection performance in sleep EEG signals is assessed before and after removing the noise and artifact sources using three state-of-the-art spindle detection algorithms, namely Mc-Sleep, Spinky, and Spindler.

Results
To examine the effectiveness of the three spindle detection methods, sleep EEG datasets from the public DREAMS database (Devuyst 2005) are investigated. The database was developed in a sleep laboratory of a Belgium hospital for the sake of spindle detection evaluation. The 32-channel EEG data were measured from eight excerpts and collected from 8 different patients with simultaneous recording of two EOG channels (P8-A1, P18-A1), three EEG channels (CZ-A1 or C3-A1, FP1-A1, and O1-A1), and one submental EMG channel. Note that sleep EEG recordings of DREAMS database include distinct cases of patient gender (4 men and 4 women), age (31 to 53 years old with a standard deviation of 8 years), and sleep pathologies (dyssomnia, restless legs syndrome, insomnia, and apnea/hypopnea syndrome). The recordings have sampling frequency of 200 Hz for excerpts 2 and 4-8, 100 Hz for excerpt 1, and 50 Hz for excerpt 3. A night record of 30 min from the central EEG channel (C3-A1 or Cz-A1) was visually inspected by two independent experts and annotated for the presence of sleep spindles. These resultant annotations are used in this study as a reference for assessing the interpretation of the three sleep spindle detection techniques. The second expert annotated only the first six excerpts so that only those six excerpts were examined in the current study.
To effectively evaluate the performance of the three sleep spindle detection methods in clean, noisy, and filtered EEG signal, three steps are performed. In the first step, three datasets are created as follows: clean EEG recordings, noisy EEG signals interfered with ECG artifact, and filtered EEG signals utilizing the MKNLMS-CS algorithm (Yukawa 2012). In the second step, we create another three datasets that contain clean EEG recordings, noisy EEG signals interfered with AWGN, and filtered EEG signals after employing the NLM algorithm (Ghanem et al. 2018;Tracey and Miller 2012). Third step is to create the last three datasets that contain clean EEG recordings, noisy EEG signals interfered with concurrent AWGN and ECG, and filtered EEG signals utilizing the suggested cascade filter of both MKNLMS-CS and NLM techniques. In the three cases, spindles are detected in the clean, noisy, and filtered EEG signal using Mc-Sleep, Spinky, and Spindler algorithms. The resultant  MKNLMS-CS ζ 1 = 0.5 , ζ 2 = 1.5 , δ = 0.5 , η = 0.3, ρ = 3.5 × 10 −2 NLM L Δ = 21 , N(s) = 10001 , B = 0.5 , where σ is the noise standard deviation spindles, and their corresponding locations in each case, are compared to the visually annotated spindles' sequence by the two experts as a ground truth. Note that the combined union of the two experts' annotations is used in the current study as recommended in LaRocco et al. (2018). There are four principal parameters that formulate the main assessment metrics in the current study. The count of spindles detected in each signal segment that corresponds to the same annotations by experts is labeled by True Positives (TP). False Negatives (FN) represent the count of spindles that were annotated by experts but missed by the detection algorithm. True Negatives (TN) are the count of segments where both the experts' annotations and the spindle detection algorithm noted the absence of spindles. False Positives (FP) are counted when the algorithm points a spindle presence that is not annotated by the experts. Main metrics that are derived from these four main parameters include Accuracy ( Acc), Sensitivity ( Se ), Precision ( Pr ), Specificity ( Sp ), F1-score, Negative Predictive Value ( NPV ), and False Discovery Rate ( FDR ). Acc represents an assessment for the matching between the resultant indications by the algorithm and the true indications by experts. Se measures the effectiveness of the algorithm in predicting the true spindles, while Sp measures the performance of predicting the true negatives. Pr measures the ratio of the true spindles detected with respect to the overall spindles detected by the algorithm. FDR is the ratio between the false spindle predictions annotated by the algorithm and all the spindle annotations. The value of NPV is the ratio of true negative predictions with respect to all negative predictions indicated by the algorithm. F1-score is a more generalized metric to evaluate the spindle detection performance by conveying the balance between Pr and Se. F1-score ranges from zero to 1. When F1-score = 1, it indicates the highest performance in spindle detection, while the value of zero points to the lowest probable performance. All these metrics are given by (Warby et al. 2014;Deivasigamani et al. 2021

Spindle detection with artifact effect
To investigate the performance of the three spindle detection algorithms, an artifact component is added to clean EEG signal, then the MKNLMS-CS technique is used to suppress the artifact. Results reveal that the MKNLMS-CS technique succeeds not only to eliminate all artifact interferences, but also to preserve the essential characteristics of the clean EEG signal as explained in (Eltrass and Ghanem 2021). It is very critical to examine the performance of the three spindle detection algorithms for concurrent artifacts. For example, the ECG is one of the most often interfering signals while recording the EEG signal, which degrades the accuracy of EEG sleep stages classification, and subsequently the sleep spindle detection process (Eltrass and Ghanem 2021;Jiang et al. 2019). A case study is examined, where the ECG signal representing the heart electrical activity was originally recorded simultaneously with the sleep EEG data. A comparison is performed to assess the sleep spindle detection procedure when applied on clean EEG signal, noisy EEG signal interfered with ECG, and filtered EEG signal utilizing the MKNLMS-CS technique. The comparison is held in terms of the assessment metrics explained earlier ( Acc, Se , Sp , Pr , F1-score, NPV , and FDR).
Parameters of the three spindle detection algorithms (Mc-Sleep, Spinky, and Spindler) are tuned to provide the highest performance. Parameters of the Mc-Sleep algorithm are set based on two factors. First, the algorithm related parameters that include the regularization parameters 0 , 1 , 2 , and the Lagrangian step size . The two regularization parameters 0 and 1 are fixed such as 0 = 0.3 and 1 = 6.5 for the DREAMS data excerpts with sampling frequency of 200 Hz as recommended in Parekh et al. (2017) and they are scaled relatively for excerpts with different sampling frequencies, namely excerpts 1 and 3 of sampling frequencies 100 Hz, and 50 Hz, respectively. The value of the step size is also fixed at the value of 0.5 to conserve the convergence of the algorithm. The regularization parameter 3 is tuned for achieving the best performance. In the current study, 3 = 34 is found to be the optimum value for achieving the highest value of F1-score. Second, the task related parameters which include the block length l and the threshold c . As discussed in section II, l is set to be 1 s with 50% overlap. On the other hand, the value of the threshold c is tuned to provide the highest classification performance. In this work, c = 1.2 is found to be the optimum threshold that provides the highest F1-score. The frequency range of the spindles is chosen to be between 10 to 17 Hz (Warby et al. 2014). For the Spinky algorithm, parameters to be set are the redundancy parameter r and the Q-factor. The Q-factor is set to be 5.5 to draw the TQWT towards spindles detection and r is fixed at the value of 3 which is recommended in Selesnick (2011). In the Spindler algorithm, parameters that control the spindle detection operation are the number of Gabor atoms rate (N s ) which is tuned in the range from 0.01 to 0.4 with step of 0.01 and the threshold applied on the signal after decomposition and reconstruction ( T b ) which is tuned in the range of 0 to 1 with the same step value. Both parameters are tuned, and the algorithm parameter grid is drawn in each case as to ensure selecting a parameter point where the spindle properties are relatively most stable. Table 2 summarizes the performance of the three spindle detection algorithms when applied on clean, noisy, and filtered EEG signal. The spindle detection evaluation metrics ( Acc , Pr , F1-score, NPV , and FDR ) for the six excerpts are averaged using the three spindle detection algorithms. The parameter F1-score, as mentioned earlier, points generally to the performance of the detection process, representing the harmonic mean of Se and Pr where the higher its value, the better the performance of spindle detection process. The impact on the spindle detection process can also be perceived in the value of Acc as well, that also decreases when spindle detection is employed on the noisy EEG data but increases when detection is implemented after utilizing the suggested MKNLMS-CS algorithm. For the value of FDR parameter, it gets higher for noisy EEG signal which refers to higher value of error in predicting similarities between the spindles detected by the algorithm and the ones annotated by the experts. The improvements in the parameters' values for the filtered EEG data indicate the efficiency of the MKNLMS-CS technique in enhancing the spindle detection procedure (see Table 2). For the three spindle detection algorithms, it can be noted that the spindle detection performance in the noisy EEG signal is degraded in comparing to the clean EEG signal. Also, Table 2 demonstrates that the spindle detection performance in the filtered EEG data is better than the paired noisy EEG data. Table 2 reveals that the classification capability of the three spindle detection algorithms is sensitive to artifact contamination which can lead to degradation in the detection process of sleep spindles. However, it can be noted that spindle detection results using Spinky algorithm are less affected by artifact contamination in comparing to Mc-Sleep and Spindler methods (see Table 2

Spindle detection with noise effect
To examine the robustness of the three spindle detection algorithms in detecting spindles within noisy EEG signal, the original sleep EEG signal is added to AWGN of SNR = 5 dB and then the NLM technique is utilized to eliminate all noise sources. The reason to use NLM algorithm is its superior performance over other techniques in removing various white and colored noises from the EEG signal as explained in (Eltrass and Ghanem 2021;Ghanem et al. 2018). The NLM technique managed to suppress the AWGN noise and accurately track the EEG signal without changing its essential characteristics. A comparison between clean, noisy, and filtered EEG signals is held by comparing the detected spindles in each case with visual annotations of the two experts (ground truth) using the three spindle detection algorithms (Mc-Sleep, Spinky, and Spindler) as shown in Table 3. The same parameters of Mc-Sleep, Spinky, and Spindler algorithms previously used are also applied. Table 3 shows the performance of the three spindle detection algorithms (Mc-Sleep, Spinky, and Spindler) when applied on clean, noisy, and filtered EEG data. To summarize the performance evaluation of the spindle detection before and after using NLM algorithm, we average all spindle evaluation metrics over the six excerpts using the three spindle detection algorithms (see Table 3). The evaluation metrics of the spindle detection witnessed improvement after eliminating the AWGN from the noisy EEG signal using the three spindle detection algorithms. For the three spindle detection algorithms, the classification performance is reduced for the noisy EEG signal compared to the clean EEG signal, while comparable performance is achieved when comparing clean and filtered EEG signals. This reveals the sensitivity of the three spindle detection algorithms to the noise contamination which can lead to degradation in the detection of sleep spindles. However, Spinky algorithm are less affected by noise contamination than Mc-Sleep and Spindler algorithms (see Table 3

Spindle detection with noise and artifact contamination
The multi-stage filter shown in Fig. 7 was tested on several EEG signals under various simultaneously recorded artifacts and noise sources, and the results revealed superior performance in EEG denoising and artifacts suppression (Eltrass and Ghanem 2021). To investigate the usefulness of the three spindle detection algorithms in detecting spindles within EEG signal contaminated with both noise and artifact sources, AWGN of SNR = 5 dB and ECG artifact are both added to each of the six excerpts in the DREAMS database, and then the multi-stage filter shown in Fig. 7 is employed to remove noise and artifact components. Figure 8a-d show, respectively, the clean EEG signal, the ECG artifact, the EEG signal interfered with both AWGN and ECG, and the filtered EEG signal after suppressing both noise and artifact sources. Comparing Fig. 8c, d, the ECG artifact component is eliminated completely from the noisy EEG signal as shown in red arrows. Also, the importance of the multi-stage filter in removing the AWGN noise can be noticed by comparing Fig. 8a, c, d. This demonstrates that the suggested cascade filter manages not only to eliminate efficiently the ECG interference and suppress the AWGN noise, but also to preserve the essential characteristics of the clean EEG signal. Table 4 summarizes the performance of the three spindle detection algorithms (Mc-Sleep, Spinky, and Spindler) when applied on clean, noisy, and filtered EEG signal by averaging all spindle evaluation metrics over the six excerpts. For the three spindle detection algorithms, it can be noted that adding both noise and artifact interferences to the EEG signal leads to more degradation in the spindle detection performance than the case of having EEG signal interfered with only noise or artifact components separately (see Tables 2, 3, and 4). This reveals that interferences coming from both artifact and noise sources can cause significant degradation in sleep spindle detection performance and may lead to wrong clinical diagnosis for sleep disorders. Although the spindle detection results are degraded for the three spindle detection algorithms when comparing the clean and the noisy EEG signals, Spinky algorithm remains the most robust technique due its less sensitivity to noise and artifacts components than Mc-Sleep and Spindler algorithms (see Table 4). Spinky outperforms Mc-Sleep and Spindler methods in detecting spindles within noisy EEG signal in terms of all evaluation metrics, including F1-score (52.2% versus 29.6% and 41.5%), FDR (51.2% versus 77.6% and 57.7%), Acc (94.0% versus 80.3% and 93.6%), Pr (48.7% versus 22.4% and 42.2%), Sp (96.4% versus 90.8% and 95.3%), and NPV (97.9% versus 97.2% and 97.2%), respectively. This reveals the low insensitivity of Spinky algorithm to noise and artifact sources in comparing with other methods. Evaluation metrics of the spindle detection show a remarkable enhancement after suppressing all noise and artifact components using the three spindle detection algorithms.

Performance analysis
To demonstrate graphically the performance of the three spindle detection methods and to determine the technique with the highest performance, the F1-score metric is chosen Fig. 8 a Clean sleep EEG signal; b ECG interference; c noisy EEG signal interfered with ECG and AWGN noise of SNR = 5 dB; d filtered EEG signal utilizing the cascade filter to be the main assessment method. This is because the F1 -score represents a general assessment for spindle detection performance by conveying the balance between Pr and Se. Figure 9 shows the comparison between the three spindle detection methods applied on the six excerpts of the DREAMS database. Figure 9a shows the spindle detection results of the original EEG signal using the three methods. It can be noted that the F1-score values of the Spinky technique are slightly higher than the Spindler technique (68.3% versus 64.1%) and much higher than the Mc-Sleep technique (68.3% versus 54.9%), revealing the superior performance of Spinky algorithm. Figure 9a shows also that the Mc-Sleep technique has the lowest spindle detection performance in comparing to Spinky and Spindler algorithms. The same can be observed from Fig. 9b, where the spindle detection is applied on EEG signal contaminated with concurrent AWGN and ECG artifact, showing better performance of Spinky technique than the other two methods. After applying the multi-stage filter on the noisy EEG signal, it can be noted that there is an enhancement in the F1-score values for the three spindle detection methods (see Fig. 9b, c). Figure 10 shows the average F1-score values over the six excerpts for the clean EEG signal, the noisy EEG signal interfered with both AWGN and ECG, and the filtered EEG signal using the three spindle detection techniques. It can be noted that Spinky achieves superior F1-score over the other two spindle detection techniques, followed by Spindler and lastly Mc-Sleep has the lowest performance (58.2% versus 50.9% and 41.3%, respectively).
To provide statistical significance for the presented spindle detection results, parametric and non-parametric tests are employed. Friedman test is a non-parametric statistical test that can be utilized to identify variations in treatments across numerous test attempts (Friedman 1937). In this work, the Friedman test is applied on the F1-score values to find the significant difference between the three spindle detection algorithms (Spinky, Spindler, and MC-Sleep). The Friedman test is implemented on the 6 excerpts of the three datasets (clean, noisy, and filtered EEG signals utilizing the suggested cascade filter) with degree of freedom equals 2 and critical p value or significance level of 0.05 . The sample size of each algorithm is 18 (6 excerpts for clean, noisy, and filtered signals) which is sufficient to approximate the probability distribution of the test-statistic Q by a chi-squared distribution. Results show that the test-statistic Q is 59.23 and the corresponding two-tail p value is 8.3 × 10 −7 . Since this p value is less than the 0.05 significance level, the null hypothesis can be rejected. This reveals that there is a significant difference between the spindle detection results of the three algorithms (Spinky, Spindler, and MC-Sleep).
A paired t test is employed to compare two sample means when observations in one sample can be paired with observations in the other sample (Hsu and Lachenbruch 2014). A paired t test is typically used to test the means of a population before and after some treatment which allows its applications in the spindle detection results of the current study for two cases: (1) clean and noisy EEG observations, and (2) noisy and filtered EEG observations. The impact of noise and artifact interferences on EEG spindle detection process is assessed by applying a paired t-test on two datasets, the first contains the observations from the three spindle detection algorithms when applied on the clean EEG data and the other consists of the observations when applied on the noisy EEG data interfered with both AWGN and ECG artifact. For a significance level of 0.05 , results show that the calculated t-value or t-statistic is 5.77 and the corresponding two-tail p value is 2.27 × 10 −5 . Since this p-value is obviously lower than the 0.05 significance level, the null hypothesis can be rejected. This reveals that there is a significant difference in the means of each sample, indicating a significant impact of noise and artifact interferences on the EEG spindle detection process. Similarly, the effectiveness of the suggested multi-stage filter on the spindle detection process is evaluated by applying a paired t test on two datasets, the observations from the three spindle detection algorithms when applied on the clean EEG data and the observations when applied on the filtered EEG data. Results show that the calculated t value is − 5.12 and the corresponding two-tail p value is 8.49 × 10 −5 which is less than the 0.05 significance level, revealing the rejection of null hypothesis. This demonstrates the significant influence of the suggested cascade filter on enhancing the EEG spindle detection process. The consumed time of the three sleep spindle detection algorithms is examined to compare their computational efficiency. The time taken by each spindle detector to process a 200 s EEG signal is recorded and averaged over the six excerpts of the DREAMS database. Results show that Spinky algorithm has the highest execution time of 5.51 min while Spindler and Mc-Sleep algorithms have remarkably lower consumed time of 1.19 min and 0.16 min, respectively. The computational time of each algorithm is measured on a personal laptop (Intel core i7-4510 M CPU, 2.00 GHz, 8 GB RAM, and 64-bit windows 8 operating system) using MATLAB software. Despite the superior robustness of the Spinky algorithm against all interferences contaminating with EEG signals, it requires slightly higher consumed time than Spindler and Mc-Sleep algorithms. Results reveal that Spinky is the most powerful method for spindle detection, especially when dealing with EEG data under low SNR conditions or EEG signals contaminated with artifacts or EEG datasets obtained across several centers using distinct EEG acquisition systems and settings. This comes for sure at the expense of more computational burden, revealing the trade-off between the computational efficiency and the classification accuracy of spindle detection among the three algorithms. Fig.9 Comparison between the F1-score of the six excerpts in the DREAMS database using the three sleep spindle detection methods

Fig. 10
Average F1-score values over the six excerpts for the three spindle detection techniques applied on clean EEG signal, noisy EEG signal interfered with both AWGN and ECG artifact, and filtered EEG signal

Results discussions
In this work, three state-of-the-art spindle detection algorithms, namely Mc-Sleep, Spinky, and Spindler, are investigated for EEG signals contaminated with noise and artifact components individually and concurrently. The performance of each spindle detection algorithm is assessed before and after eliminating the interfering noise and artifacts using a new multi-stage filter that employs the MKNLMS-CS method in the first step to remove all artifacts and utilizes the NLM technique in the subsequent step to eliminate all noises (Eltrass and Ghanem 2021). The three spindle detection algorithms are tested on the DREAMS sleep spindle database (Devuyst 2005). The first sleep spindle detection algorithm, MC-Sleep, depends on using multi-channel EEG recordings to assure detecting spindles that often can be more vivid in a certain channel than in other channels. Despite the complexity of multi-channel EEG recordings, MC-Sleep has a privilege of having lower computational time (0.16 min) than Spindler and Spinky (1.19 min and 5.51 min, respectively). This is because the spindle threshold in MC-Sleep algorithm is calculated only once without depending on of the number of EEG signal channels. The second spindle detection technique is Spinky which combines both TQWT and MCA techniques. Results reveal that Spinky algorithm achieves better performance than Mc-Sleep and Spindler algorithms for filtered EEG signals in terms of all assessment metrics, including Acc (94.8% versus 92.0% and 94.6%), Pr (53.4% versus 36.4% and 47.5%), Sp (97.3% versus 93.9% and 96.1%), NPV (98.2% versus 97.8% and 97.6%), and F1-score (58.2% versus 41.3% and 50.9%), respectively. Unlike Spinky and MC-Sleep algorithms which set their parameters to optimize the best performance with respect to the experts' labels, Spindler decides the parameters that specify a central point on the parameters grid where any change in the parameters' values do not largely cause changes in spindle property values. Spindler achieves reasonably good performance ( Acc = 94.6%, Sp = 96.1%, and F1-score = 50.9%) with a fair computational time (1.19 min).
In practical settings, one of the main obstacles that affect the precision of EEG recording, and hence the accuracy of their relative clinical interpretations concluded from EEG signals such as sleep stages classification, is the presence of different noise and artifact sources. Sleep spindle detection is one of the most addressed topics in EEG sleep analysis which contributes to many brain disorders. Therefore, there is a critical need for accurate spindle detection results. EEG denoising and artifact removal using visual inspection is boring, time-consuming, and error-prone due to tiredness, which does not allow its implementation in automated spindle detection systems. This work proposes a multi-stage filter of MKNLMS-CS and NLM techniques that can eliminate all noise and artifact components automatically without any visual inspection. The efficiency of the suggested multi-stage filter in removing white and colored noise and various types of simultaneous artifacts without affecting the essential features of EEG signals was proved extensively in (Eltrass and Ghanem 2021). Experimental results reveal the significance of the suggested cascade filter in enhancing the capability of spindle detection in terms of all assessment metrics ( F1 -score, Acc , FDR, Se , Sp , Pr , and NPV ), while keeping the automation of the whole system.
The capability of NLM approach in suppressing white/ colored noises from EEG signals is compared with several denoising algorithms, including wavelet-based techniques (Unser and Aldroubi 1996), Empirical Mode Decomposition (EMD) (Wang et al. 2013), and kernel adaptive filtering methods like Kernel Recursive Least Squares (KRLS) (Engel et al. 2004;Ghanem et al. 2018). The comparison is performed utilizing several assessment metrics, including the output SNR, Mean Square Error (MSE) between the clean and the filtered signal, and Cross Correlation (CC) between the clean and the filtered signal. To acquire authenticated results, the comparison is repeated over 108 EEG segments from the DREAMS dataset at SNR = 5 dB, and the average of all evaluation metrics is computed for all techniques under comparison as shown in Table 5. Results demonstrate that the NLM algorithm provides the highest output SNR and CC and achieves the lowest MSE compared to DWT, EMD, and KRLS techniques, demonstrating the outstanding capability of NLM technique in suppressing AWGN, while keeping the essential characteristics of the EEG signal. In Hadiyoso and Wijayanto (2019), EMD was investigated to remove the low frequency noise interference from the EEG signal. Note that the low frequency noise is caused by temporal dynamics of the electrode placed on the scalp and it can be modeled as a brown noise source (Eltrass and Ghanem 2021). The capability of NLM method in eliminating this type of noise from EEG signals is compared with EMD algorithm, and the results reveal that the NLM outperforms EMD in terms of root MSE (0.0179 mV versus 0.0295 mV).
The performance of MKNLMS-CS technique in suppressing artifact sources from EEG signals is compared with several techniques, including Ensemble Empirical  (Huang et al. 2018), and Singular Spectrum Analysis (SSA) (Mohammadi et al. 2016). A clean EEG segment is added to EMG artifact of input SNR = 5 dB, and all algorithms under comparison are employed to suppress the EMG interference. The comparison is performed using two assessment metrics, the output SNR and CC between the clean and the filtered signal. The comparison is repeated over 108 EEG segments, and the average of all evaluation metrics is computed as shown in Table 6. Results demonstrate the outstanding capability of the MKNLMS-CS over other state-of-the-artmethods under comparison in terms of output SNR and CC (see Table 6). The same outstanding performance of MKN-LMS-CS is also acquired for suppressing other artifacts from the noisy EEG signal. This elucidates the effectiveness of MKNLMS-CS algorithm over other techniques in removing various artifacts from the EEG signal. In Mohammadpour and Rahmani (2017), a method based on Hidden Markov Model (HMM) was proposed for suppressing EOG artifacts from EEG signals, and its performance was compared with the Independent Component Analysis (ICA) method (Vázquez et al. 2012 When the EEG recordings are exposed to AWGN or/and artifact sources, the spindle detection performance of the three algorithms is degraded, revealing their sensitivity to contamination sources present in EEG signals. However, spindle detection results using Spinky algorithm are less affected by artifact and/or noise contamination in comparing to Mc-Sleep and Spindler methods (see Tables 2, 3, and  4). This reveals the low sensitivity of Spinky algorithm to noise and artifact sources in comparing with other methods for detecting spindles in EEG signals. It can be deduced that most of sleep spindle detection algorithms are sensitive to artifact and noise sources, which may cause significant degradation in the sleep spindle detection when dealing with noisy or raw EEG data. Note that some studies reported spindle detection results after removing all artifact and noise components manually by visual inspection, preventing their implementations in any automated diagnosis system. Such spindle detection results after manual inspection may cause misleading clinical interpretation for realistic diagnosis systems. For fully automated spindle detection system, either artifact and noise sources should be suppressed using an automated method like the proposed multi-stage filter or the spindle detection algorithm should be assessed on unprocessed (raw) EEG data.
Further insight requires investigating the proposed spindle detection system, including the multi-stage filter followed by the Spinky algorithm, in computer aided detection systems to improve the diagnosis of several sleep disorders such as sleep apnea, insomnia, narcolepsy, restless leg syndrome, and parasomnias. Recent studies showed that spindle properties constitute a biomarker of various sleep disorders (O'Reilly et al. 2015;Christensen et al. 2017;DelRosso et al. 2014DelRosso et al. , 2021Cote et al. 2000;Dang-Vu et al. 2010;Mohammadi et al. 2021). In Dang-Vu et al. (2010), it was proven that insomnia complaints are accompanied by reduced spindle density, which allows understanding the neural mechanisms governing the development of insomnia sleep disorders and providing a biomarker for the identification of patients at risk for future sleep disruption. Some studies showed that sleep spindle density constitutes a biomarker of narcolepsy sleep disorder (Christensen et al. 2017;DelRosso et al. 2014), showing the importance of studying the sleep spindle activity. In O'Reilly et al. 2015, it was found that lower overall spindle densities were obtained for REM sleep behavior disorder patients than for paired control individuals. This reveals the importance of distinguishing fast and slow spindles. In Mohammadi et al. (2021), it was reported that an increasing OSA severity is accompanied by lower spindle density during the N3 stage and a shorter spindle duration during the N2 stage. This shows the importance of investigating spindle characteristics during both N2 and N3 stages in the upcoming studies. All previous research points will be explored in the near future to investigate the sleep-protection role of sleep spindles during sleep and their link to homeostatic processes. A goal for future investigation is to examine the capability of proposed spindle detection system in diagnosing various sleep disorders. Although the three sleep spindle detection techniques demonstrated in this work have been proven to be promising automatic methods for detecting spindles with reasonable computational time in comparing with the time and complexity required by visual inspection of spindles, they have few limitations that should be addressed in the future. First, although Spinky algorithm achieves high performance in sleep spindle detection using only single-channel EEG signal, it can be modified to process multi-channel EEG signals which would enhance its efficiency remarkably but might cost more computational complexity. Second, for Spindler algorithm, instead of only searching for an optimum point to ensure spindle's property stability with Spindler's parameters, an optimization technique could be employed to find a certain point that accommodates both, parameters' stability, and high performance with respect to expert's annotations. Third, combining two sleep spindle detection methods can also be investigated, where the spindles detected in both techniques either matched to find joint spindles' annotations which would increase TN values or the spindles can be combined from both annotations which would raise the value of TP . Furthermore, although the DREAMS database used in the current study contains many excerpts covering different cases of gender, age, and sleep pathologies, testing the three spindle detection algorithms on larger EEG datasets with many more patients accompanied with experts' annotations remains a serious goal for future examination. Finally, the computational complexity of the three spindle detection techniques can be enhanced using advanced hardware specifications which may permit real-time processing and diagnosis. The hardware implementation of real-time sleep spindle detection is a serious target for the translation into clinical applications. These points represent challenges that will be addressed in the near feature.

Conclusions
This work proposes a new practical implementation of sleep spindle detection system including a new automated multi-stage filter as a preprocessing tool before detecting spindles in sleep EEG signals. In the proposed filter, the MKNLMS-CS method is used in the first step to remove artifact interferences, while the NLM technique is utilized in the subsequent step to suppress all noise sources. Three state-of-the-art spindle detection algorithms, namely Mc-Sleep, Spinky, and Spindler, are examined using EEG signals contaminated with noise or/and simultaneous artifact interferences. To examine the effectiveness of the three spindle detection algorithms, sleep EEG datasets from the DREAMS database covering distinct cases of patient gender, age, and sleep pathologies are investigated. A comparison between clean, noisy, and filtered EEG signals is held using the three spindle detection algorithms. The capability of each spindle detection algorithm is assessed in terms of several metrics, including Acc, Se , Sp , Pr , F1-score, NPV , FDR , and computational time. Experimental results show a remarkable degradation in the spindle detection performance using the three methods, revealing their sensitivity to noise and/or artifact sources present in EEG signals. However, spindle detection results using Spinky algorithm are less affected by artifact and/or noise contamination with EEG signals compared to Mc-Sleep and Spindler methods. Furthermore, Spinky algorithm achieves superior F1-score over Mc-Sleep and Spindler algorithms in detecting spindles for clean (68.3% versus 54.9% and 64.1%), noisy (52.2% versus 29.6% and 41.5%), and filtered EEG signal (58.2% versus 41.3% and 50.9%), respectively. On the other hand, results prove the efficiency of the suggested cascade filter in enhancing the spindle detection performance for the three algorithms. However, the performance improvement of Spinky algorithm still outperforms both Mc-Sleep and Spindler methods. The proposed spindle detection system, including the multi-stage filter followed by the Spinky algorithm, manages not only to eliminate all artifact and noise components from noisy EEG signals, but also to achieve very accurate sleep spindle detection in terms of Acc 94.8%, Sp 97.3%, Pr 53.4%, NPV 98.2%, and F1-score 58.2%.
Funding Open access funding provided by The Science, Technology & Innovation Funding Authority (STDF) in cooperation with The Egyptian Knowledge Bank (EKB).
Open Access This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons licence, and indicate if changes were made. The images or other third party material in this article are included in the article's Creative Commons licence, unless indicated otherwise in a credit line to the material. If material is not included in the article's Creative Commons licence and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this licence, visit http://creativecommons.org/licenses/by/4.0/.