Sleep classification method and system based on time-frequency combination
By employing a sleep staging method that combines time-frequency joint coding and memory-enhanced dynamic attention layers, this approach addresses the issues of insufficient information fusion and low modeling efficiency in existing technologies. It achieves efficient sleep stage identification and classification, making it suitable for real-time applications in clinical and home settings.
Patent Information
- Application Number
- CN202511003857.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-21
- Publication Date
- 2025-11-07
AI Technical Summary
Existing sleep staging methods rely on artificial features, lack sufficient fusion of time and frequency domain information, have low efficiency in modeling long-term time-series dependencies, are difficult to adapt to individual differences, and have high computational complexity and insufficient memory capacity.
A time-frequency joint coding mechanism is adopted, which extracts frequency domain features through learnable wavelet transform and extracts time domain features through deep separable causal convolution. Combined with a memory-enhanced dynamic attention layer and a weighted cross-entropy loss function, the model parameters are optimized to achieve multi-scale information fusion and efficient modeling.
It improves the ability to express multi-scale EEG signal features, enhances the model's ability to model long-term time-dependent information, reduces computational complexity, and significantly improves the ability to identify rare sleep stages, demonstrating good clinical applicability and prospects for widespread application.
Smart Images

Figure CN120899270A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the technical field of biomedical signal processing and artificial intelligence, and particularly relates to a sleep classification method and system based on time-frequency combination. BACKGROUND
[0002] Sleep is a core physiological process for maintaining human physiological functions and mental health. Abnormalities in the quality and structure of sleep are closely related to various diseases such as insomnia, sleep apnea syndrome, and depression. According to the standard formulated by the American Academy of Sleep Medicine (AASM), the sleep process is divided into the following five stages:
[0003] Wake: refers to the state of closing eyes and relaxing, and the electroencephalogram (EEG) is mainly composed of alpha waves (8-13 Hz);
[0004] Non-Rapid Eye Movement (NREM), including three stages:
[0005] N1 stage: shallow sleep state, electroencephalogram mainly composed of theta waves (4-7 Hz), accounting for about 5% of the entire sleep cycle;
[0006] N2 stage: characterized by the appearance of sleep spindles (12-14 Hz) and K-complex waves, which is the main sleep stage, accounting for about 50%;
[0007] N3 stage: deep sleep stage, electroencephalogram mainly composed of delta waves (0.5-4 Hz), accounting for about 20%;
[0008] Rapid Eye Movement (REM): this stage is accompanied by rapid eye movement and dream experience, and the electroencephalogram is similar to the state of wakefulness, and the electromyogram (EMG) activity is significantly inhibited.
[0009] Accurate sleep staging is of great significance for the diagnosis of sleep disorders and the evaluation of treatment effect. The current mainstream staging method relies on manual interpretation of electroencephalogram (EEG), electrooculogram (EOG) and electromyogram (EMG) and other multi-modal physiological signals, and usually takes 1-2 hours to complete a complete analysis, which has the problems of low interpretation efficiency, insufficient inter-expert consistency (only 70%-80%) and difficulty in adapting to individual differences.
[0010] The existing automatic sleep staging model still has the following limitations:
[0011] 1. The model based on traditional convolutional neural network is difficult to effectively extract non-stationary time-frequency joint features in physiological signals;
[0012] 2. Standard attention mechanism has high computational complexity and lacks dynamic screening ability for key features;
[0013] 3. In the process of long sequence modeling, there is a problem of insufficient memory capacity, which leads to insufficient utilization of context information. For example, although the Transformer model can capture global dependencies, its memory overhead grows quadratically with the sequence length, and it is not optimized for the time-frequency characteristics of physiological signals. SUMMARY
[0014] The purpose of the present application is to solve the problems of existing sleep staging methods, such as strong dependence on artificial features, insufficient fusion of time and frequency domain information, and low efficiency of long sequence dependence modeling. A sleep classification method and system with high automation, efficient multi-scale information fusion, and consideration of modeling accuracy and computational efficiency are proposed.
[0015] To achieve the above purpose, the technical solution adopted by the present application is as follows:
[0016] A sleep classification method based on time-frequency joint, comprising the following steps:
[0017] 1) Preprocessing the electroencephalogram signal to obtain preprocessed electroencephalogram signal data and corresponding sleep stage labels;
[0018] 2) Input the preprocessed electroencephalogram signal data into a time-frequency encoder, which performs a learnable wavelet transform through a frequency domain path to extract frequency domain features, and performs a deep separable causal convolution through a time domain path to extract time domain features; and concatenates the frequency domain features and the time domain features in the channel dimension to obtain fused time-frequency features;
[0019] 3) Input the fused time-frequency features into a double-branch convolution feature extractor to extract sleep features through macroscopic and microscopic paths respectively, and concatenate them in the channel dimension to obtain further features;
[0020] 4) Input the further features into a memory-enhanced dynamic attention layer module to generate an enhanced feature map;
[0021] 5) Input the enhanced feature map into a classifier to output the corresponding sleep stage prediction result;
[0022] 6) Use a weighted cross-entropy loss function to supervise the training of the time-frequency encoder, the double-branch convolution feature extractor and the memory-enhanced dynamic attention layer module, and optimize the model parameters.
[0023] Further, the preprocessing in step 1) includes data acquisition, specified channel signal extraction, band-pass filtering, signal segmentation, normalization and data saving operations.
[0024] Further, the sleep stage labels in step 1) include: Wake, N1, N2, N3 and REM.
[0025] Further, the step of extracting frequency domain features in step 2) through the frequency domain path includes:
[0026] Performing a learnable wavelet transform on the electroencephalogram signal, extracting features corresponding to the frequency bands of δ, θ, α, β and γ waves;
[0027] Performing two-dimensional convolution, batch normalization, GELU activation and adaptive average pooling operations on the frequency band features to generate a frequency domain feature map.
[0028] Further, the step of extracting time domain features in step 2) through the time domain path includes:
[0029] Performing a deep separable causal convolution to extract waveform features
[0030] Performing batch normalization, GELU activation and maximum pooling operations on the waveform features to generate a time domain feature map.
[0031] Further, the micro-path in step 3) includes two deep separable convolution modules, each of which is connected in turn with batch normalization, GELU activation, an enhanced channel-spatial attention module and a maximum pooling layer, and the output time dimension is adjusted through adaptive maximum pooling to be consistent with the macro-path.
[0032] Further, the enhanced channel-spatial attention module includes:
[0033] The channel attention module is used to generate channel descriptors based on average pooling and maximum pooling, and after 1D convolution, GELU activation and Sigmoid normalization, channel attention weights are generated and multiplied with input features channel by channel to obtain enhanced channel features;
[0034] The spatial attention module is used to generate time descriptors based on channel average and maximum projection, and after concatenation, spatial attention weights are generated through atrous convolution and multiplied with the feature map channel by channel to obtain enhanced spatial features.
[0035] Further, the processing steps of the memory-enhanced dynamic attention layer module in step 4) include:
[0036] The features extracted by the double branch are mapped through linear mapping to generate dynamic routing scores;
[0037] Performing Softmax normalization on the dynamic routing scores to generate attention activation weights;
[0038] Performing element-wise Boolean operation on the attention activation weights based on a preset threshold to generate a sparse mask;
[0039] Introducing a trainable memory matrix, and generating a memory key vector and a memory value vector based on the fused time-frequency features;
[0040] Splicing the memory key vector with the original key vector, and splicing the memory value vector with the original value vector to form an enhanced key vector and an enhanced value vector respectively;
[0041] Based on the enhanced key vector and the enhanced value vector, attention calculation is performed combined with a sparse mask to output an enhanced feature map.
[0042] Further, the method of step 6) optimizing model parameters includes: using an AdamW optimizer to update parameters, and combining a learning rate adjustment strategy to control the optimization step in the training process; using a K-fold cross-validation strategy to improve the generalization ability of the model; and setting an early stopping mechanism to prevent overfitting.
[0043] A sleep classification system based on time-frequency joint includes:
[0044] An electroencephalogram signal preprocessing module for preprocessing electroencephalogram signals to obtain preprocessed electroencephalogram signal data and corresponding sleep stage labels;
[0045] A time-frequency encoder for processing the preprocessed electroencephalogram signal data, including performing a learnable wavelet transform through a frequency domain path to extract frequency domain features, and performing a deep separable causal convolution through a time domain path to extract time domain features; and splicing the frequency domain features and the time domain features in the channel dimension to generate fused time-frequency features;
[0046] A double-branch convolution feature extractor for extracting sleep features from the fused time-frequency features through a macroscopic path and a microscopic path respectively, and splicing in the channel dimension to generate further features;
[0047] A memory-enhanced dynamic attention layer module for processing the further features to generate an enhanced feature map;
[0048] A classifier for generating a sleep stage prediction result based on the enhanced feature map;
[0049] A training module for using a weighted cross-entropy loss function to supervise the training of the time-frequency encoder, the double-branch convolution feature extractor and the memory-enhanced dynamic attention layer module, and optimizing model parameters.
[0050] The beneficial effects obtained by the present application are as follows:
[0051] 1. The present application realizes the full fusion of frequency domain features and time domain features by introducing a time-frequency joint encoding mechanism, improves the expression ability of multi-scale electroencephalogram signal features, and effectively overcomes the problem of insufficient utilization of frequency domain information in traditional methods.
[0052] 2. The application improves the modeling ability of the model for long-time sequence dependent information by introducing a memory-enhanced dynamic attention mechanism, and introduces a sparse mask and a trainable memory matrix in attention calculation, thereby improving the reasoning efficiency while ensuring modeling accuracy.
[0053] 3. The application adopts a lightweight multi-branch neural network structure, extracts sleep features through macroscopic and microscopic paths, significantly reduces the number of model parameters while maintaining high classification accuracy, improves the reasoning speed of the model, and supports real-time application in clinical and home scenarios.
[0054] 4. The application introduces a weighted cross-entropy loss function and other optimization strategies to address the label class imbalance problem, improving the recognition ability of rare sleep stages (such as N3 stage), and significantly improving the classification performance of the model on the few-sample class.
[0055] 5. The application uses a trainable wavelet transform to realize adaptive decomposition of signal frequency bands, improving the automation level of feature extraction, reducing the dependence on manual intervention and feature engineering, and improving the generality and deployment efficiency of the overall system.
[0056] 6. The application achieves significant improvement in multiple performance indicators, with N3 stage F1 value reaching 96.9%, and overall classification accuracy reaching 88.2%, which has higher precision and robustness than existing methods, and has good clinical applicability and promotion prospects. BRIEF DESCRIPTION OF DRAWINGS
[0057] Figure 1 is a sleep classification method flowchart based on time-frequency joint in an embodiment of the application.
[0058] Figure 2 is a time-frequency encoder schematic diagram based on a double-path structure in an embodiment of the application.
[0059] Figure 3 is a double-branch feature extraction structure diagram in an embodiment of the application.
[0060] Figure 4 is a dynamic sparse routing and memory-enhanced dynamic attention layer structure diagram in an embodiment of the application.
[0061] Figure 5 is an enhanced channel-spatial attention module structure diagram in an embodiment of the application. DETAILED DESCRIPTION
[0062] In order to make the above technical features and advantages or technical effects of the technical solutions of the application more obvious and easy to understand, the following embodiments are described in detail.
[0063] The embodiment of the application provides a sleep classification method based on time-frequency joint, and a processing flow thereof is as shown in the figure Figure 1 Specifically includes the following steps:
[0064] I. Electroencephalogram signal data preprocessing
[0065] This step aims to clean, align and standardize the original sleep data for subsequent feature extraction and model training. Specifically, the following sub-steps are included:
[0066] 1. Original data acquisition:
[0067] This embodiment uses polysomnogram (PSG) data in the Sleep-EDF-20 database, which contains electroencephalogram (EEG), electrooculogram (EOG) and electromyogram (EMG) signals, with a sampling rate of 100 Hz and a duration of 30 seconds for each data. The data is stored in EDF format and accompanied by an XML format sleep stage annotation file.
[0068] 2. Signal extraction and filtering
[0069] The specified EEG channel signal (for example: Fpz-Cz channel) is extracted from the EDF file, and the extracted signal is subjected to baseline drift processing and high-frequency noise suppression. A 5th order Butterworth band-pass filter is used to filter the signal in the 0.5-40Hz frequency band to retain the effective frequency band components such as delta waves and theta waves commonly used in sleep analysis.
[0070] 3. Signal segmentation and label alignment
[0071] The continuous signal is segmented by 30 seconds, so that each segment of the signal corresponds to a sleep stage label (including: Wake, N1, N2, N3, REM). Invalid segments caused by device interference or signal abnormalities are removed to ensure that each signal is strictly aligned with its corresponding label.
[0072] 4. Normalization
[0073] Perform normalization operation on each signal: first subtract the mean of the segment, then scale to [-1, 1] interval based on its maximum absolute value, to avoid the problem of inconsistent dimensions between different signal channels affecting model training.
[0074] 5. Data saving
[0075] The preprocessed signal and corresponding label are saved as a Numpy data file in.npz format, which contains fields including:
[0076] x: signal data;
[0077] y: corresponding label;
[0078] fs: sampling rate information.
[0079] II. Time-frequency encoder
[0080] As shown in Figure 2 , the time-frequency encoder includes two branches of frequency domain path and time domain path, which respectively extracts frequency domain features and time domain waveform modeling of the input electroencephalogram signal, and finally splices the two types of features in the channel dimension to form a joint representation feature.
[0081] Specifically, the following processing steps are included:
[0082] 1. Frequency domain path extraction:
[0083] (1) Learnable CWT
[0084] The input original electroencephalogram signal is decomposed into five typical frequency bands: delta wave (0.5-4Hz), theta wave (4-8Hz), alpha wave (8-13Hz), beta wave (13-30Hz), and gamma wave (30-40Hz) through learnable wavelet transform.
[0085] The frequency band division adopts affine transformation for parameter adaptive adjustment, and the result is represented as:
[0086] X freq = Conv2d(Replicate(CWT(X)), W)
[0087] In this embodiment, the signal X is [128, 1, 3000], 128 is the batch size, 1 is the number of channels, and 3000 is the time step; Replicate represents copying the frequency domain features in the channel dimension; X freq represents the processed frequency domain features, Conv2d represents the convolution operation, and W represents a two-dimensional convolution kernel with a size of 3x3.
[0088] (2) Convolution layer processing
[0089] The frequency domain features after wavelet transform are executed with a two-dimensional convolution operation, using a 3x3 convolution kernel, the input and output channel numbers are both 64, and local frequency domain features are extracted.
[0090] (3) Batch normalization (BatchNorm2d)
[0091] The convolution result is batch normalized to improve the training stability and convergence speed.
[0092] (4) Activation function processing
[0093] The normalized result is activated using a GELU (Gaussian Error Linear Unit) nonlinear activation function to improve the expression ability of the model.
[0094] (5) Adaptive average pooling
[0095] An adaptive average pooling operation is performed on the activated features to compress the feature map to a fixed dimension, thereby reducing the feature dimension and retaining global frequency domain information.
[0096] 2. Time domain path extraction:
[0097] (1) Depthwise separable causal convolution
[0098] A depthwise separable causal convolution is used to extract the time sequence structure in the waveform, ensuring that the model only relies on historical time step information and avoids future information leakage.
[0099] a. A depthwise separable causal convolution f DSConv is used to extract waveform features, ensuring that the model only relies on historical information (avoiding future information leakage). This convolution is divided into a depthwise convolution and a pointwise convolution, reducing the computational complexity:
[0100] X time == f DSConv (X)
[0101] where X time represents the processed time-frequency feature, and X represents the original input signal [128, 1, 3000]; the convolution parameter configuration is (1, 64, 15), indicating that the input channel is 1, the output channel number is 64, and the convolution kernel size is 15.
[0102] (2) Batch normalization (BatchNorm1d)
[0103] The convolution output is processed by one-dimensional batch normalization.
[0104] (3) Activation function processing
[0105] A GELU activation function is used for nonlinear conversion.
[0106] (4) Max pooling
[0107] A max pooling operation is applied for 4 times down-sampling, thereby compressing the feature length and reducing the computational complexity.
[0108] 3. Feature fusion
[0109] The frequency domain features and the time domain features obtained by the two paths are spliced in the channel dimension to form a fused joint feature matrix. The output dimension of the splicing result is [128, 128, 750], wherein 128 is the channel dimension, and 750 is the feature time step number. The output will be used as the input of the subsequent double-branch feature extraction module.
[0110] III. Double-branch feature extraction
[0111] As shown in Figure 3 , the application adopts a double-branch convolution structure to extract sleep features from two scales of macro and micro.
[0112] Among them:
[0113] The left branch (macro path) is used to capture long-time sequence and low-frequency trend features.
[0114] The right branch (micro path) is used to detect short-time transient high-frequency events.
[0115] The two branch structures are symmetrically and independently processed, and finally spliced and fused.
[0116] 1. Input feature
[0117] The input is the fused feature map output by the aforementioned time-frequency encoder, and the dimension is [128, 128, 750], which respectively represents the batch size, the number of channels and the time dimension.
[0118] 2. Macro branch path (left branch)
[0119] Mainly extracts the low-frequency δ wave features with long duration in the deep sleep period (such as N3), and the process is as follows:
[0120] (1) The first layer of depth separable convolution: input / output channel: 128→64; convolution kernel size: 64, step: 8, padding: left padding 63; function: through large step (stride=8) compression of long time window, extract macro rhythm (such as N3 continuous 10 minutes δ wave form). The left padding (padding=63) ensures that the output only depends on historical information.
[0121] (2) BatchNorm+GELU activation: accelerate convergence and enhance nonlinear expression ability.
[0122] (3) Enhanced CBAM attention module (channel number 64): add channel attention and spatial attention to enhance the expression ability of key paths.
[0123] (4) Max pooling layer: pooling kernel size 4, step default, used for downsampling time dimension, enhancing feature robustness.
[0124] (5) Dropout layer: for regularization, to prevent overfitting.
[0125] (6) 2nd layer depthwise separable convolution: input / output channels: 64→128; kernel size 16, stride: unspecified, default 1.
[0126] (7) BatchNorm + GELU activation.
[0127] (8) Enhanced CBAM attention module (channel number 128).
[0128] (9) Max pooling layer + adaptive max pooling layer: pooling kernel size: 4; adaptive pooling unified output time dimension final output feature dimension: [128, 128, 200].
[0129] 3. Microscopic branch path (right branch)
[0130] For detecting short-time events (such as K-complex, spindle), the process is as follows:
[0131] (1) 1st layer depthwise separable convolution: input / output channels: 128→64; kernel size: 32, stride: 4; compared with the macroscopic branch, a smaller receptive field is used, with a small step to capture transient features and retain more transient information (such as the short waveform of K-complex).
[0132] (2) BatchNorm + GELU activation: to accelerate convergence and enhance nonlinear expression ability.
[0133] (3) Enhanced CBAM attention module (channel number 64).
[0134] (4) Max pooling layer: kernel size 4.
[0135] (5) Dropout layer: to prevent overfitting.
[0136] (6) 2nd layer depthwise separable convolution: input / output channels: 64→128; kernel size 32, keep the feature channel consistent.
[0137] (7) BatchNorm + GELU activation.
[0138] (8) Enhanced CBAM attention module (channel number 128).
[0139] (9) Adaptive max pooling layer: unified output time dimension 200; final output feature dimension: [128, 128, 200].
[0140] 4. Branch fusion and normalization
[0141] (1) Channel concatenation: Concatenate two branch outputs in the channel dimension, and the obtained data is [128, 256, 200].
[0142] (2) Residual block: The fusion output passes through a residual structure for information preservation and gradient flow.
[0143] (3) Layer normalization (LayerNorm): Normalize the output feature map as the final classifier output result.
[0144] The above classifier module can simultaneously retain background information with long-range association and key short physiological waveform features during sleep, significantly improving the accuracy and robustness of staging.
[0145] Four, memory-enhanced dynamic attention mechanism
[0146] As shown in Figure 4 , the attention module provided by the embodiment introduces a dynamic routing strategy and a trainable memory mechanism to improve the attention regulation ability of the model in sleep stage switching, feature ambiguity, etc. This module can further enhance the information expression of key time steps after double-branch feature extraction, which includes the following steps:
[0147] 1. Dynamic routing weight generation
[0148] (1) The input feature map is linearly mapped to generate dynamic routing logits, specifically:
[0149] route_logits = Linear(x)
[0150] Where x is the feature map extracted by the fusion of the two branches, the input dimension is [128, 80, d], and the output dimension is [128, 80, 8], i.e. 8 attention heads are assigned to each time step.
[0151] (2) Perform softmax normalization on the above route_logits to generate dynamic routing weights (i.e. the activation probability distribution of the attention head):
[0152] A rout e = Softmax(route_logits)
[0153] (3) The weight tensor A route ∈R B×T×h is transposed from [128, 80, 8] to [128, 8, 80], and a dynamic sparse mask is generated by a lightweight routing network according to the following mask function:
[0154] M sparse = Π(A route>τ), τ = 0.2
[0155] where M sparse denotes the dynamic sparse mask; Π denotes the element-wise Boolean operation (1 if greater than threshold, otherwise 0); A route denotes the dynamic routing weight, which denotes the routing weight of each time step and each head; τ denotes the set threshold.
[0156] 2. Memory expansion mechanism
[0157] A trainable memory encoding matrix M ∈ R m×d is introduced, which is projected by linear mapping respectively as:
[0158] Memory key vector: M k = Linear(M);
[0159] Memory value vector: M v = Linear(M).
[0160] Then it is spliced with the key-value vector of the input feature to enhance the attention learning ability.
[0161] 3. Attention calculation process
[0162] (1) The input feature is respectively mapped to query (Q), key (K) and value (V) vectors by three groups of linear layers, and is grouped according to the multi-head attention structure.
[0163] (2) The key vector is spliced with the memory key vector, and the value vector is spliced with the memory value vector, respectively, to form an enhanced key-value pair.
[0164] (3) Calculate the attention matrix:
[0165] Attn = Softmax(Q[K||M k ] T )·[V||M v ]
[0166] Where Attn denotes attention, Q, K, and V are generated by input features through projection layers, and M k and M v are generated by memory features memory through projection layers.
[0167] The dynamic sparse mask M sparse and the memory mask memory_mask are used in the above calculation to encode, fill and normalize the attention results, so as to control the number of activated heads and inhibit redundant paths.
[0168] 4. Output feature map generation
[0169] (1) Concatenate all attention head outputs into a unified dimensional feature representation.
[0170] (2) Map back to the dimension of the original input feature through a linear layer to form the final enhanced feature map for the subsequent classifier.
[0171] Five, Enhanced CBAM (Enhanced CBAM)
[0172] To further enhance the model's ability to perceive key signal patterns (such as delta waves, K-complexes, sleep spindles, etc.), an enhanced channel-spatial attention module is introduced after each depthwise separable convolution and batch normalization in the double-branch feature extraction. Its structure is shown in Figure 5 , which is composed of a channel attention module and a spatial attention module in series, and specifically includes the following steps:
[0173] a. Channel attention module:
[0174] This module is used to calculate the importance weight of the channel dimension to highlight representative feature channels and suppress redundant or noisy information (such as electroencephalogram / electromyogram interference, etc.).
[0175] 1. Feature compression (pooling): Perform average pooling (AdaptiveAvgPool) and maximum pooling (AdaptiveMaxPool) on the input feature along the time dimension (sequence dimension) respectively to obtain two channel descriptors.
[0176] 2. Channel weight generation:
[0177] The average pooling and maximum pooling results are input into 1D convolution (Conv1d) and GELU activation function respectively;
[0178] The output feature is integrated again through a second 1D convolution layer;
[0179] After adding the two results, the channel attention weight is obtained by normalizing through the Sigmoid function, suppressing noise (such as EMG interference) and reducing parameter quantity. The calculation formula is as follows:
[0180] Channel_Att = Sigmoid(Conv1d(GELU(Conv1d(AvgPool + MaxPool))))
[0181] The output channel attention weight is [128, 64, 1].
[0182] 3. Feature reweighting: Multiply the original input feature and the channel attention weight channel by channel:
[0183] X' = X ⊙ Channel_Att
[0184] where, represents element-wise multiplication, Channel Att R B×C×1 .
[0185] b. Spatial attention module
[0186] This module further extracts the salient regions between different time steps, emphasizing key periods (such as short sleep events within 2-3 seconds):
[0187] 1. Feature compression (channel aggregation): Perform average and maximum operations on features along the channel dimension to obtain two time series descriptors (mean and extreme).
[0188] 2. Feature concatenation: Concatenate the above two time descriptors in the channel dimension to obtain the spatial attention input feature tensor ([B,2,T], for example [128,2,94]).
[0189] 3. Dilation convolution processing: Use a dilated convolution with a dilation rate of 2 to increase the receptive field and extract local temporal attention patterns with long-term temporal dependencies.
[0190] 4. Sigmoid activation: Map the convolution result to the [0,1] interval to form the spatial attention weight:
[0191] Spatial_Att = Sigmoid(spatial_conv(Concat(mean,max)))
[0192] The output spatial attention weight is [128,1,94].
[0193] 5. Feature weighting: Element-wise multiply the channel attention output X' and the spatial attention weight to obtain the final enhanced feature output:
[0194] Output = X' o Spatial_Att
[0195] where, Spatial_Att R B×1×T The final output dimension is consistent with the input.
[0196] Six, model training
[0197] The present application adopts a cross-entropy loss function with class weight for training to alleviate the training bias problem caused by uneven sleep stage distribution (such as N1 and REM periods significantly less than N2 / N3 periods), and combines K-fold cross-validation, early stopping mechanism and other strategies to optimize the generalization ability of the model. The specific training process is as follows:
[0198] 1. Loss function design
[0199] Weighted Cross Entropy Loss was used to assign higher weights to classes with fewer samples (e.g., N1, REM), effectively suppressing the bias caused by class imbalance. The loss function expression is as follows:
[0200]
[0201] where y i represents the true label of the i-th sample; p i represents the predicted probability of the i-th sample; w i represents the loss weight of the corresponding class, which is set according to the class frequency to solve the class imbalance problem; N represents the number of batch samples.
[0202] 2. Evaluation index
[0203] To comprehensively evaluate the model performance, the following two indicators are used:
[0204] Accuracy (ACC):
[0205]
[0206] where TP i represents the number of correct classifications of the i-th class (true positive), M is the total number of all test samples, and K is the total number of classes.
[0207] Macro-F1 (MF1):
[0208]
[0209] where Precision represents precision, and Recall represents recall.
[0210] This index gives equal weight to each class, and can better reflect the performance of the model on minority classes (e.g., N1).
[0211] 3. Optimizer and training parameters
[0212] AdamW optimizer is used for parameter update, with an initial learning rate of 3×10 -4 , and the learning rate is reduced to 1×10 -4 after 10 epochs of training to suppress late shocks and improve stability.
[0213] 4. Training strategy
[0214] K-fold cross-validation: The training data is divided into 20 equal parts (20-fold), and each round selects one fold as the validation set and the rest as the training set. The model is trained for 20 times to ensure its good generalization ability.
[0215] Early Stopping: If the validation set loss does not decrease for 10 consecutive rounds, training is terminated to avoid overfitting.
[0216] 5. Training process
[0217] The training process is an end-to-end model learning that covers the entire SleepFocusNet framework, including time-frequency encoder, dual-branch feature extractor, memory-enhanced dynamic attention layer module, classifier, and other modules. The overall process is as follows:
[0218] Data loading: Read the preprocessed EEG signal data and corresponding labels from the.npz file and load them into the GPU in batches (BatchSize = 128).
[0219] Forward propagation: The input signal is first extracted by the time-frequency encoder to extract multi-scale features, then further extracted by the dual-branch feature extractor, and finally the key time-series context information is mined by the enhanced memory attention mechanism, and the final prediction probability vector is output by the classifier.
[0220] Backpropagation and parameter optimization: Based on the weighted cross-entropy loss function, the loss of all modules is calculated uniformly, and the gradient is backpropagated and the parameters are updated. After each round of training, save the checkpoint file (such as model_best.pth) with the best model performance.
[0221] Validation set evaluation: After each round of training, use the validation set to calculate the ACC and MF1 indicators to evaluate the performance changes.
[0222] Result saving: Save the prediction results (outs) and corresponding true labels (trgs) in Numpy format, and finally output the classification report (Excel format) and confusion matrix graph for result visualization and subsequent analysis.
[0223] Experimental test:
[0224] The experiment is conducted on the Sleep-ED-20 dataset, and 20-fold cross-validation is used to ensure the reliability of the results.
[0225] Data size: Contains data files of 20 subjects.
[0226] Signal type: Single-channel EEG (Fpz-Cz lead), sampling rate 100Hz.
[0227] Sleep stage: annotated according to AASM standard (W, N1, N2, N3, REM).
[0228] Test protocol: input signal length: 30 seconds / segment; evaluation metric: stage-wise F1-score + overall accuracy; baseline comparison: 6 SOTA sleep staging models.
[0229] The test results are shown in Table 1, which gives the F1 scores and overall accuracies of the present method and 6 baseline methods in each sleep stage. The test results are analyzed as follows.
[0230] (1) Breakthrough performance in deep sleep stage (N3):
[0231] 96.9% F1-score: 7 percentage points higher than the best baseline (89.9%).
[0232] The delta wave (0.5-4 Hz) of deep sleep (N3) has low-amplitude slow-varying characteristics, and the present model achieves this by:
[0233] Learnable wavelet transform enhances low-frequency feature extraction; dilated convolution captures minute-level waveform correlation; memory module models cross-segment slow wave patterns.
[0234] (2) Significant improvement in key transition stage (N2):
[0235] 92.2% F1-score: 3.7 percentage points higher than TinySleepNet (88.5%).
[0236] The present model achieves this by dynamically routing attention to the transient characteristics of spindle waves (12-16 Hz) and K-complexes, time-frequency complementary coding, time-domain path capturing spindle wave burstiness, and frequency-domain path analyzing spectral features.
[0237] (3) Overall performance advantage:
[0238] 88.2% accuracy: 3.3 percentage points higher than the best baseline (TinySleepNet 84.9%).
[0239] Table 1 F1 scores and overall accuracies of the present method and 6 baseline methods in each sleep stage
[0240]
[0241]
[0242] References:
[0243] [1] Supratak A, Guo Y. "DeepSleepNet: A Model for Automatic Sleep Stage Scoring Based on Raw Single-Channel EEG," IEEE Transactions on Neural Systems and Rehabilitation Engineering, 2017, 25(11): 1998-2008. DOI: 10.1109 / TNSRE.2017.2721116.
[0244] [2] Sun Y, Wang B, Jin J, Wang X. "Deep Convolutional Network Method for Automatic Sleep Stage Classification Based on Neurophysiological Signals," Proc. of the 2018 11th International Congress on Image and Signal Processing, BioMedical Engineering and Informatics (CISP-BMEI), 2018: 1-5.
[0245] DOI: 10.1109 / CISP-BMEI.2018.8633058.
[0246] [3] Chen L J, Wang L, Sha X Z, Chang S J, Chen Y. "Automatic Sleep Staging Model Based on Multimodal Fusion Strategy and Attention Mechanism," Journal of Biomedical Engineering Research, 2025, 44(1): 24-30 (in Chinese).
[0247] [3] Chen L J, Wang L, Sha X Z, Chang S J, Chen Y. "Automatic Sleep Staging Model Based on Multimodal Fusion Strategy and Attention Mechanism," Journal of Biomedical Engineering Research, 2025, 44(1): 24-30 (in Chinese).
[0248] [4] Wang Z, Zhao R, Li M. Sleep EEG Staging Based on the Residual Shrinkage Network. Computers in Biology and Medicine, 2021, 135: 104558.
[0249] DOI: 10.1016 / j.compbiomed.2021.104558.
[0250] [5] Maiti S, Sharma S K, Bapi R S. Enhancing Healthcare with EOG: A Novel Approach to Sleep Stage Classification. IEEE Access, 2023, 11: 4567-4579. DOI: 10.1109 / ICASSP48485.2024.10446703.
[0251] [6] Eldele E, Chen Z, Liu C, et al. An Attention-Based Deep Learning Approach for Sleep Stage Classification With Single-Channel EEG. IEEE Transactions on Neural Systems and Rehabilitation Engineering, 2021, 29:
[0252] 809-818. DOI: 10.1109 / TNSRE.2021.3076234.
[0253] Although the present application has been disclosed with examples as above, it is not intended to limit the present application, and any appropriate modification or equivalent replacement made by those skilled in the art to the technical solutions of the present application shall be covered within the protection scope of the present application, and the protection scope of the present application shall be subject to the limitations of the claims.
Claims
1. A sleep classification method based on time-frequency joint, characterized in that, The method comprises the following steps: 1) preprocessing the electroencephalogram signal to obtain preprocessed electroencephalogram signal data and corresponding sleep stage labels; 2) inputting the preprocessed electroencephalogram signal data into a time-frequency encoder, the time-frequency encoder performing a learnable wavelet transform through a frequency domain path to extract frequency domain features, and performing a deep separable causal convolution through a time domain path to extract time domain features; and splicing the frequency domain features and the time domain features in the channel dimension to obtain fused time-frequency features; 3) inputting the fused time-frequency features into a double-branch convolution feature extractor, extracting sleep features through a macroscopic path and a microscopic path respectively, and splicing in the channel dimension to obtain further features; 4) inputting the further features into a memory-enhanced dynamic attention layer module to generate an enhanced feature map; 5) inputting the enhanced feature map into a classifier to output corresponding sleep stage prediction results; 6) using a weighted cross-entropy loss function to supervise the training of the time-frequency encoder, the double-branch convolution feature extractor and the memory-enhanced dynamic attention layer module, and optimizing the model parameters.
2. The sleep classification method of claim 1, wherein, The preprocessing in step 1) includes data acquisition, specified channel signal extraction, band-pass filtering, signal segmentation, normalization and data saving operations.
3. The sleep classification method of claim 1, wherein, The sleep stage labels in step 1) include wakefulness, N1 period, N2 period, N3 period and rapid eye movement period.
4. The sleep classification method of claim 1, wherein, The steps of extracting frequency domain features through the frequency domain path in step 2) include: performing a learnable wavelet transform on the electroencephalogram signal to extract delta wave, theta wave, alpha wave, beta wave and gamma wave corresponding frequency band features; performing two-dimensional convolution, batch normalization, GELU activation and adaptive average pooling operations on the frequency band features to generate a frequency domain feature map.
5. The sleep classification method of claim 1, wherein, The steps of extracting time domain features through the time domain path in step 2) include: performing a deep separable causal convolution to extract waveform features performing batch normalization, GELU activation and maximum pooling operations on the waveform features to generate a time domain feature map.
6. The sleep classification method of claim 1, wherein, The microscopic path in step 3) includes two deep separable convolution modules, each of which is connected in turn with batch normalization, GELU activation, an enhanced channel-space attention module and a maximum pooling layer, and the output time dimension is adjusted through adaptive maximum pooling to be consistent with the macroscopic path.
7. The sleep classification method of claim 6, wherein, The enhanced channel-space attention module includes: a channel attention module for generating a channel descriptor based on average pooling and maximum pooling, generating channel attention weights after 1D convolution, GELU activation and Sigmoid normalization, and multiplying the input features by the channel attention weights to obtain enhanced channel features; a spatial attention module for generating a time descriptor based on channel average and maximum projection, generating spatial attention weights after concatenation and dilated convolution, and multiplying the feature map by the spatial attention weights to obtain enhanced spatial features.
8. The sleep classification method of claim 1, wherein, The processing steps of the memory-enhanced dynamic attention layer module in step 4) include: generating a dynamic routing score by linearly mapping the features extracted by the double branch; performing Softmax normalization on the dynamic routing score to generate an attention activation weight; performing an element-wise Boolean operation on the attention activation weight based on a preset threshold to generate a sparse mask; A trainable memory matrix is introduced, and a memory key vector and a memory value vector are generated based on the fused time-frequency features; The memory key vector and the original key vector are spliced, and the memory value vector and the original value vector are spliced to form an enhanced key vector and an enhanced value vector, respectively; Based on the enhanced key vector and the enhanced value vector, attention calculation is performed combined with a sparse mask to output an enhanced feature map.
9. The sleep classification method of claim 1, wherein, The method for optimizing the model parameters includes: using an AdamW optimizer to update the parameters, and combining a learning rate adjustment strategy to control the optimization step length in the training process; using a K-fold cross-validation strategy to improve the generalization ability of the model; and setting an early stopping mechanism to prevent overfitting.
10. A time-frequency joint based sleep classification system, characterized in that, The method comprises the following steps: An electroencephalogram signal preprocessing module is configured to preprocess electroencephalogram signals to obtain preprocessed electroencephalogram signal data and corresponding sleep stage labels; A time-frequency encoder is configured to process the preprocessed electroencephalogram signal data, including performing a learnable wavelet transform through a frequency domain path to extract frequency domain features, and performing a deep separable causal convolution through a time domain path to extract time domain features; and splicing the frequency domain features and the time domain features in the channel dimension to generate fused time-frequency features; A double-branch convolution feature extractor is configured to extract sleep features from the fused time-frequency features through a macroscopic path and a microscopic path, respectively, and splice the sleep features in the channel dimension to generate further features; A memory-enhanced dynamic attention layer module is configured to process the further features to generate an enhanced feature map; A classifier is configured to generate a sleep stage prediction result based on the enhanced feature map; A training module is configured to use a weighted cross-entropy loss function to supervise the training of the time-frequency encoder, the double-branch convolution feature extractor, and the memory-enhanced dynamic attention layer module, and optimize the model parameters.
Citation Information
Cited By
Brain-computer interface data acquisition and analysis method, system and sensing device
CN121622059A
A method, system and sensing device for brain-computer interface data acquisition and analysis
CN121622059B
Lightweight single-channel electroencephalogram sleep staging method and system based on multistage fusion
CN121795931A