Method and system for decoding and classifying motor imagery electroencephalogram signals

The decoding classification model through spatiotemporal feature embedding and local window attention mechanism solves the problem of low classification accuracy of convolutional neural network in EEG signal decoding, achieves higher classification accuracy, and is suitable for patients with movement disorders and stroke. Intention recognition.

CN118820931APending Publication Date: 2024-10-22BEIJING NORMAL UNIVERSITY
View PDF 0 Cites 5 Cited by

Patent Information

Application Number
CN202410717035.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-04
Publication Date
2024-10-22

AI Technical Summary

Technical Problem

In the existing technology, motor imagery EEG signal decoding and classification models based on convolutional neural networks have limited ability to handle long-term context dependencies, resulting in low classification accuracy and difficulty in effectively decoding EEG signals.

Method used

A decoding classification model based on spatio-temporal feature embedding and two local window attention mechanisms is used to extract spatio-temporal features through convolution kernels, and the local window attention mechanism is used to redistribute information weight, capture long-distance information, and combine the feature fusion module to adapt to the EEG The non-stationarity of graph data improves the expressive ability of the model.

Benefits of technology

It improves the decoding and classification accuracy of motor imagery EEG signals, can quickly and accurately predict the categories of EEG signals, expands the application prospects of intention recognition for patients with movement disorders and stroke patients, and provides convenience for rehabilitation treatment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118820931A_ABST
    Figure CN118820931A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of brain-computer interfaces, in particular to a method and system for decoding and classifying motor imagery electroencephalogram signals, and the method comprises the following steps: S1, obtaining and preprocessing the motor imagery electroencephalogram signals to obtain electroencephalogram data expressed in a two-dimensional matrix form, and dividing the electroencephalogram data into a training set and a test set; s2, electroencephalogram data training samples in the training set are used, a decoding classification model is trained, and the decoding classification model is based on spatio-temporal feature embedding and twice application of a local window attention mechanism; and S3, decoding and classifying the motor imagery electroencephalogram signals to be decoded and classified by using the trained decoding and classifying model. According to the method, the motor imagery electroencephalogram signals can be effectively decoded and classified.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of brain-computer interface technology, and in particular to a method and system for decoding and classifying motor imagery electroencephalogram signals. Background Art

[0002] Motor imagery (MI) is a typical paradigm in brain-computer interface (BCI) technology, in which the subject only needs to imagine the body movement in his mind without actually executing it. Decoding the EEG signals of motor imagery can help patients with movement disorders establish non-muscle controlled information exchange channels and achieve communication with the external environment, which is of great significance in the application of neurorehabilitation therapy. Among various neuroimaging methods, electroencephalogram (EEG) data collected by electrode caps is a non-invasive method and is widely used in the study of motor imagery decoding due to its comfort, convenience, and high temporal resolution. In subsequent applications, the decoded information can be used to convert the individual's movement intention into output instructions, thereby establishing an organic information connection between the movement intention and the interface device.

[0003] With the development of artificial intelligence, deep learning has been widely used in the motor imagery decoding task of EEG signals. For example, the classification model in deep learning can be used to decode and classify the original motor imagery EEG data of the target subject to predict the task type corresponding to the motor imagery EEG data. In the prior art, a classification model based on a convolutional neural network is usually used. However, since the performance of the convolutional neural network is limited by its ability to process long-term contextual dependencies, the classification accuracy is low when processing sequence data such as EEG signals. Therefore, there is an urgent need for a method to effectively decode and classify motor imagery EEG signals. Summary of the invention

[0004] The present invention provides a method and system for decoding and classifying motor imagery EEG signals, which are used to decode and classify motor imagery EEG signals. The technical solution is as follows:

[0005] On the one hand, a method for decoding and classifying motor imagery electroencephalogram signals is provided, the method comprising:

[0006] S1, acquiring and preprocessing motor imagery EEG signals to obtain EEG data represented in a two-dimensional matrix form, and dividing the EEG data into a training set and a test set;

[0007] S2. Using the EEG data training samples in the training set, training a decoding classification model, wherein the decoding classification model is based on spatiotemporal feature embedding and twice applying a local window attention mechanism;

[0008] S3. Use the trained decoding and classification model to decode and classify the motor imagery EEG signals to be decoded and classified.

[0009] Optionally, the S1 specifically includes:

[0010] S11, obtaining motor imagery EEG signals, using a notch filter to remove the power frequency noise of the motor imagery EEG signals, using a bandpass filter to filter the motor imagery EEG signals, intercepting the EEG signals of the subjects' actual motor imagery of a fixed time length in the middle for subsequent training and classification, and obtaining a number of original EEG data represented in the form of a two-dimensional matrix, wherein the rows of the two-dimensional matrix represent the electrode channels of the spatial dimension, and the columns of the two-dimensional matrix represent the sampling points of the time dimension, and the EEG data are divided into a training set and a test set, wherein each training sample in the training set belongs to a classification label of a different motor imagery category;

[0011] S12, normalizing the distribution of the original EEG data training samples in the training set to a specific distribution;

[0012] S13. Use the segmentation and reconstruction strategy to perform data enhancement on the standardized training samples, including:

[0013] A preset number of samples to be synthesized of each classification label are randomly selected from the training set, each sample to be synthesized is evenly divided into a preset number of parts in chronological order, a section of all samples to be synthesized is selected in sequence, and finally merged together to form a new sample, which is trained together with the original training samples.

[0014] Optionally, the decoding classification model consists of an EEG data input module, a spatiotemporal feature embedding module, a first local window attention module, a feature fusion module, a second local window attention module, and a classifier output module;

[0015] The EEG data input module is used to input the EEG data training samples;

[0016] The spatiotemporal feature embedding module is used to perform convolution operation on the input EEG data training sample through a series of convolution kernels, each convolution kernel can learn a specific feature pattern to obtain a first low-dimensional feature matrix, the convolution kernel is a shallow convolution, which preliminarily extracts the shallow spatiotemporal feature representation, and then uses two local window attention mechanisms for deep learning;

[0017] The first local window attention module is used to redistribute the local information of the first low-dimensional feature matrix based on the local window attention mechanism for the first time, assign different weights to different information, so that the model focuses on the information related to motor imagery, and helps the model better capture and utilize long-distance information, thereby obtaining a second low-dimensional feature matrix;

[0018] The feature fusion module is used to fuse the features of the second low-dimensional feature matrix to obtain a third low-dimensional feature matrix;

[0019] The second local window attention module is used to redistribute the local information of the third low-dimensional feature matrix again based on the local window attention mechanism, and assign different weights to different information again, so that the model can further focus on the information related to motor imagery, and further help the model to better capture and utilize long-distance information, thereby obtaining a fourth low-dimensional feature matrix;

[0020] The classifier output module is used to further reduce the dimension of the fourth low-dimensional feature matrix and output the predicted probabilities of different motor imagery categories.

[0021] Optionally, the spatiotemporal feature embedding module performs shallow convolution on the time dimension and the spatial dimension of the EEG data training sample respectively, including a two-dimensional convolution layer, a batch normalization layer, a two-dimensional deep convolution layer, a batch normalization layer, an average pooling layer and a position encoding layer connected in sequence;

[0022] The two-dimensional convolution layer is used as a temporal filter to generate outputs containing features of different frequency bands. For the EEG data training sample with a shape of 1×22×1000, a two-dimensional convolution layer with an output channel of 16 and a convolution kernel size of 1×63 is used, and the shape of the time dimension is kept unchanged by adding padding, resulting in a feature matrix with a shape of 16×22×1000. Here, the size of the convolution kernel is set to 1 / 4 of the sampling rate.

[0023] Then, a two-dimensional deep convolution layer with an output channel of 32 and a convolution kernel size of 22×1 is used to convolve each feature channel separately, and the 22 electrode channels are fused into one channel to promote the spatial feature expression across electrodes. The shape of the feature matrix is ​​32×1×1000. Here, deep convolution is used to learn a spatial filter for each temporal filter, thereby effectively extracting the spatial features of a specific frequency band.

[0024] Batch normalization is added after the above two convolutional layers to accelerate model convergence. Next, an average pooling layer with a convolution kernel size of 1×125 and a step size of 1×25 is used in the time dimension for feature dimensionality reduction. The shape of the feature matrix is ​​32×36, where 32 represents the number of feature channels and 36 represents the length of the time series. Finally, parameter-learnable absolute position encoding is added to the features, so that the model can effectively utilize the sequence position information from the markers.

[0025] Optionally, the first local window attention module divides the feature matrix of shape 32×36 into 6 non-overlapping windows of width 6 according to the length of the time series, obtains 6 feature matrices of size 32×6, applies the local window attention mechanism within each window, and maps the input feature matrix to the query vector , the key vector Sum value vector , then the query vector and the transpose of the key vector Perform a dot product and divide by the window width Then use The function generates the attention score, and then uses the generated attention score pair value vector Re-weighting is performed and the calculation is as follows:

[0026]

[0027] Use multi-head attention to extract multi-dimensional features from different subspaces to improve the model's fitting ability and perform parallel computing. The feature mapping of the query vector, key vector and value vector is obtained The shape of the feature matrix after merging these feature matrices is 32×6. ×32×6, and then the output with shape of 32×6 is obtained through feature mapping, which is calculated as follows:

[0028]

[0029]

[0030] in , is the number of attention heads used, They are all parameter matrices of feature mapping layers;

[0031] The first local window attention module completes the calculation process of one window division:

[0032] First, the input feature matrix Perform layer normalization, then calculate the weighted feature matrix of the multi-head attention, and then compare it with the input feature matrix The residual connection is added to obtain the intermediate feature matrix , and then through layer normalization and multi-layer perceptron, and with the intermediate feature matrix The residual connection is added to obtain the output feature matrix , which can be expressed as follows:

[0033]

[0034]

[0035] in Representative layer standardization, stands for Multilayer Perceptron;

[0036] The feature matrices of the shape of 32×6 calculated in the six windows are merged again to obtain a feature matrix of the shape of 32×36 that is consistent with the shape before the windows are divided;

[0037] Next, the first local window attention module shifts the window backward by half the window width and merges the first and last two windows together, also obtaining 6 windows of size 32×6. The local window attention mechanism is applied again inside the new window to realize cross-window information interaction to supplement local information.

[0038] Optionally, the feature fusion module enables the model to obtain a gradually increasing receptive field for the EEG data through feature fusion, thereby solving the limitation brought by the fixed window size, and includes:

[0039] The 32×36 feature matrix obtained by the first application of the local window attention mechanism is regarded as a feature sequence of length 36. Each group of adjacent features in the sequence is concatenated 32×1 to obtain a 64×18 feature matrix, which is then processed through layer normalization and feature mapping layers. The layer normalization improves the model training speed, and the feature mapping layer captures higher-level abstract features and enhances the expressiveness of the network by learning weight parameters and performing linear and nonlinear transformations.

[0040] Optionally, the second local window attention module divides the feature matrix with a shape of 64×18 into three non-overlapping windows of width 6 according to the length of the time series, and obtains three feature matrices of size 64×6, and applies the local window attention mechanism again within each window to redistribute the local information of the feature matrix with a shape of 64×18 to obtain a new feature matrix with a shape of 64×18.

[0041] Next, the second local window attention module shifts the window backward by half the window width and merges the first and last two windows together to obtain three windows of size 64×6. The local window attention mechanism is applied again inside the new window to realize cross-window information interaction to supplement local information.

[0042] On the other hand, a system for decoding and classifying motor imagery electroencephalogram signals is provided, the system comprising:

[0043] An acquisition preprocessing module is used to acquire and preprocess the motor imagery EEG signal to obtain EEG data represented in a two-dimensional matrix form, and divide the EEG data into a training set and a test set;

[0044] A training module, for training a decoding classification model using the EEG data training samples in the training set, wherein the decoding classification model is based on spatiotemporal feature embedding and twice applying a local window attention mechanism;

[0045] The decoding and classification module is used to use the trained decoding and classification model to decode and classify the motor imagery EEG signals to be decoded and classified.

[0046] On the other hand, an electronic device is provided, comprising a processor and a memory, wherein the memory stores at least one instruction, and the at least one instruction is loaded and executed by the processor to implement the above-mentioned method for decoding and classifying motor imagery EEG signals.

[0047] On the other hand, a computer-readable storage medium is provided, wherein at least one instruction is stored in the storage medium, and the at least one instruction is loaded and executed by a processor to implement the above-mentioned method for decoding and classifying motor imagery EEG signals.

[0048] Compared with the prior art, the above technical solution has at least the following beneficial effects:

[0049] The present invention converts EEG data into a low-dimensional feature matrix that is convenient for subsequent processing and preliminarily extracts shallow spatiotemporal features through the spatiotemporal feature embedding module of the decoding classification model. The local window attention module specifically processes local information in the EEG signal, so that the model focuses on information related to motor imagery, while helping the model to better capture and utilize long-distance information. The feature fusion module adapts to the non-stationarity and randomness of the EEG data. The classification output module obtains the predicted probability of different motor imagery categories, which can quickly and accurately predict the category of motor imagery EEG signals, help improve the accuracy of motor imagery decoding, and further expand the application prospects of motor imagery decoding in various application fields. For example, the intentions of patients with movement disorders or stroke patients can be more accurately known, thereby facilitating the interaction of patients with movement disorders and the rehabilitation treatment of stroke patients. BRIEF DESCRIPTION OF THE DRAWINGS

[0050] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0051] Figure 1 A flow chart of a method for decoding and classifying motor imagery EEG signals provided by an embodiment of the present invention;

[0052] Figure 2 A schematic diagram of performing data enhancement on training samples provided by an embodiment of the present invention;

[0053] Figure 3 A schematic diagram of the decoding classification model structure provided by an embodiment of the present invention;

[0054] Figure 4 A schematic diagram of the structure of a spatiotemporal feature embedding module provided in an embodiment of the present invention;

[0055] Figure 5 A schematic diagram of a local window attention mechanism provided by an embodiment of the present invention;

[0056] Figure 6 A schematic diagram of window redivision provided by an embodiment of the present invention;

[0057] Figure 7 It is a schematic diagram of feature splicing performed by a feature fusion module provided in an embodiment of the present invention;

[0058] Figure 8 It is a system block diagram for decoding and classifying motor imagery EEG signals provided by an embodiment of the present invention;

[0059] Fig. 9 It is a structural schematic diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0060] In order to make the purpose, technical solution and advantages of the embodiment of the present invention clearer, the technical solution of the embodiment of the present invention will be clearly and completely described below in conjunction with the drawings of the embodiment of the present invention. Obviously, the described embodiment is a part of the embodiment of the present invention, not all of the embodiments. Based on the described embodiment of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0061] like Figure 1As shown, an embodiment of the present invention provides a method for decoding and classifying motor imagery EEG signals, comprising:

[0062] S1, acquiring and preprocessing motor imagery EEG signals to obtain EEG data represented in a two-dimensional matrix form, and dividing the EEG data into a training set and a test set;

[0063] Optionally, the S1 specifically includes:

[0064] S11, obtaining motor imagery EEG signals (the motor imagery EEG signals can be selected from the public dataset BCI Competition IV dataset2a, or obtained from other datasets, or by collecting the motor imagery EEG signals after the subject wears an electrode cap. The embodiment of the present invention does not limit the manner of obtaining the motor imagery EEG signals, which are all within the protection scope of the embodiment of the present invention), using a notch filter to remove the power frequency noise of the motor imagery EEG signals, using a bandpass filter to filter the motor imagery EEG signals, intercepting the EEG signals of the subjects actually performing motor imagery for a fixed time length in the middle for subsequent training and classification, and obtaining a number of original EEG data represented in the form of a two-dimensional matrix, wherein the rows of the two-dimensional matrix represent the electrode channels of the spatial dimension, and the columns of the two-dimensional matrix represent the sampling points of the time dimension, and the EEG data are divided into a training set and a test set, and each training sample in the training set belongs to a classification label of a different motor imagery category;

[0065] The embodiment of the present invention uses a 50 Hz notch filter to remove the power frequency noise of the motor imagery EEG signal, and uses a 1-80 Hz Butterworth bandpass filter to filter the motor imagery EEG signal, and intercepts the EEG signal of the middle 4 seconds of the data (when the subject actually performs motor imagery) for training and classification.

[0066] The final data set contains 18 folders, each of which contains 288 .mat files. The data format of each .mat file is a 22×1000 two-dimensional matrix. The following table introduces each value:

[0067]

[0068] S12, normalizing the distribution of the original EEG data training samples in the training set to a specific distribution;

[0069] The embodiment of the present invention uses Z-Score standardization (other standardization methods may also be used, which are not limited by the embodiment of the present invention and are all within the protection scope of the embodiment of the present invention) to standardize the distribution of the original EEG data training samples in the training set to a standard normal distribution (i.e., a distribution with a mean of 0 and a variance of 1), and the implementation method is as follows:

[0070]

[0071]

[0072]

[0073] in, For the training samples, For the After standardization, is the number of training samples, is the mean of the training set data, is the variance of the training set data;

[0074] Data standardization can ensure that different data have a unified scale, which is conducive to improving the convergence speed of deep learning models.

[0075] S13, using a segmentation and reconstruction strategy to perform data enhancement on the training samples in the training set, including:

[0076] like Figure 2 As shown, a preset number of samples to be synthesized of each classification label are randomly selected in the training set, each sample to be synthesized is evenly divided into a preset number of parts in chronological order, all samples to be synthesized are selected in sequence, and finally merged together to form a new sample, which is trained together with the original training samples.

[0077] S2. Using the EEG data training samples in the training set, training a decoding classification model, wherein the decoding classification model is based on spatiotemporal feature embedding and twice applying a local window attention mechanism;

[0078] Optionally, the decoding classification model consists of an EEG data input module, a spatiotemporal feature embedding module, a first local window attention module, a feature fusion module, a second local window attention module, and a classifier output module. Figure 3 As shown;

[0079] The EEG data input module is used to input the EEG data training samples;

[0080] The spatiotemporal feature embedding module is used to perform convolution operation on the input EEG data training sample through a series of convolution kernels, each convolution kernel can learn a specific feature pattern to obtain a first low-dimensional feature matrix, the convolution kernel is a shallow convolution, which preliminarily extracts the shallow spatiotemporal feature representation, and then uses two local window attention mechanisms for deep learning;

[0081] This hierarchical feature learning method enables the model to have strong expression and generalization capabilities when processing high-dimensional data such as EEG. Moreover, if the entire model is composed of convolutional layers, it will have the defect of being unable to process long-term temporal dependencies like the prior art. Therefore, the model of the embodiment of the present invention only uses convolution at the shallow level to initially extract spatiotemporal features, and then uses the attention mechanism to learn long-term dependencies.

[0082] The first local window attention module is used to redistribute the local information of the first low-dimensional feature matrix based on the local window attention mechanism for the first time, assign different weights to different information, so that the model focuses on the information related to motor imagery, and helps the model better capture and utilize long-distance information, thereby obtaining a second low-dimensional feature matrix;

[0083] The feature fusion module is used to fuse the features of the second low-dimensional feature matrix to obtain a third low-dimensional feature matrix;

[0084] The second local window attention module is used to redistribute the local information of the third low-dimensional feature matrix again based on the local window attention mechanism, and assign different weights to different information again, so that the model can further focus on the information related to motor imagery, and further help the model to better capture and utilize long-distance information, thereby obtaining a fourth low-dimensional feature matrix;

[0085] The classifier output module is used to further reduce the dimension of the fourth low-dimensional feature matrix and output the predicted probabilities of different motor imagery categories.

[0086] Alternatively, if Figure 4 As shown, the spatiotemporal feature embedding module performs shallow convolution on the time dimension and space dimension of the EEG data training sample respectively (because EEG data is different from RGB image data, the rows and columns of the RGB image data matrix represent the horizontal and vertical coordinates of the pixel points, which have similar meanings and can use convolution at the same time, but the rows and columns of the EEG data matrix represent the electrode channels of the spatial dimension and the sampling points of the time dimension respectively, which have quite different meanings, so it is necessary to process the two dimensions of time and space separately), including a two-dimensional convolution layer, a batch normalization layer, a two-dimensional deep convolution layer, a batch normalization layer, an average pooling layer and a position encoding layer connected in sequence;

[0087] The two-dimensional convolution layer is used as a time filter to generate outputs containing features of different frequency bands. For an EEG data training sample with a shape of 1×22×1000 (in order to facilitate computer calculations, the embodiment of the present invention represents the EEG data training sample of 22×1000 as an EEG data training sample of 1×22×1000), a two-dimensional convolution layer with an output channel of 16 and a convolution kernel size of 1×63 is used, and the shape of the time dimension is kept unchanged by adding padding, so that the shape of the feature matrix is ​​16×22×1000, where the size of the convolution kernel is set to 1 / 4 of the sampling rate (the embodiment of the present invention can obtain frequency information of 4 Hz and above);

[0088] Then, a two-dimensional deep convolution layer with an output channel of 32 and a convolution kernel size of 22×1 is used to convolve each feature channel separately, and the 22 electrode channels are fused into one channel to promote the spatial feature expression across electrodes. The shape of the feature matrix is ​​32×1×1000. Here, deep convolution is used to learn a spatial filter for each temporal filter, thereby effectively extracting the spatial features of a specific frequency band.

[0089] Batch normalization is added after the above two convolutional layers to accelerate model convergence. Next, an average pooling layer with a convolution kernel size of 1×125 and a step size of 1×25 is used in the time dimension for feature dimensionality reduction. The shape of the feature matrix is ​​32×36, where 32 represents the number of feature channels and 36 represents the length of the time series. Finally, parameter-learnable absolute position encoding is added to the features, so that the model can effectively utilize the sequence position information from the markers.

[0090] Optionally, the first local window attention module divides the feature matrix of shape 32×36 into 6 non-overlapping windows of width 6 according to the length of the time series, obtains 6 feature matrices of size 32×6, applies the local window attention mechanism within each window, and maps the input feature matrix to the query vector , the key vector Sum value vector , then the query vector and the transpose of the key vector Perform a dot product and divide by the window width Then use The function generates the attention score, and then uses the generated attention score pair value vector Re-weighting is performed and the calculation is as follows:

[0091]

[0092] Use multi-head attention to extract multi-dimensional features from different subspaces to improve the model's fitting ability and perform parallel computing. The feature mapping of the query vector, key vector and value vector is obtained The shape of the feature matrix after merging these feature matrices is 32×6. ×32×6, and then the output with shape of 32×6 is obtained through feature mapping, which is calculated as follows:

[0093]

[0094]

[0095] in , is the number of attention heads used, They are all parameter matrices of feature mapping layers;

[0096] The first local window attention module completes the calculation process of one window division:

[0097] First, the input feature matrix Perform layer normalization, then calculate the weighted feature matrix of the multi-head attention, and then compare it with the input feature matrix The residual connection is added to obtain the intermediate feature matrix , and then through layer normalization and multi-layer perceptron, and with the intermediate feature matrix The residual connection is added to obtain the output feature matrix , which can be expressed as follows:

[0098]

[0099]

[0100] in Representative layer standardization, stands for Multilayer Perceptron;

[0101] The feature matrices of the shape of 32×6 calculated in the six windows are merged again to obtain a feature matrix of the shape of 32×36 that is consistent with the shape before the windows are divided;

[0102] Next, if Figure 6 As shown, the first local window attention module shifts the window backward by half the window width and merges the first and last two windows together, also obtaining 6 windows of size 32×6. The local window attention mechanism is applied again inside the new window to realize cross-window information interaction to supplement local information.

[0103] Optionally, the feature fusion module enables the model to obtain a gradually increasing receptive field for the EEG data through feature fusion, thereby solving the limitation caused by the fixed window size (the fixed window size in the embodiment of the present invention is 6), including:

[0104] like Figure 7 As shown in the figure, the feature matrix with a shape of 32×36 obtained by the first application of the local window attention mechanism is regarded as a feature sequence with a length of 36, and each group of adjacent features 32×1 in the sequence is concatenated to obtain a 64×18 feature matrix, which is then processed through layer normalization and feature mapping layers. The layer normalization improves the model training speed, and the feature mapping layer captures higher-level abstract features and enhances the expression ability of the network by learning weight parameters and performing linear and nonlinear transformations.

[0105] Optionally, the second local window attention module divides the feature matrix with a shape of 64×18 into three non-overlapping windows of width 6 according to the length of the time series, and obtains three feature matrices of size 64×6, and applies the local window attention mechanism again within each window to redistribute the local information of the feature matrix with a shape of 64×18 to obtain a new feature matrix with a shape of 64×18.

[0106] Next, the second local window attention module shifts the window backward by half the window width and merges the first and last two windows together to obtain three windows of size 64×6. The local window attention mechanism is applied again inside the new window to realize cross-window information interaction to supplement local information.

[0107] Optionally, the classifier output module reduces the dimension of the feature matrix with a shape of 64×18 by layer standardization and an average pooling layer with a convolution kernel size of 1×18 to obtain a feature vector with a shape of 64, further obtains a feature vector with a shape of 4 by a feature mapping layer, and finally obtains a feature vector with a shape of 4 by The output layer obtains the predicted probabilities of different motor imagery categories.

[0108] The method of the embodiment of the present invention further includes comparing the classification result with the true label, and calculating the cross entropy loss by the following specific formula:

[0109]

[0110] in is the number of training samples, is the number of categories of motor imagery, For the The class labels of the training samples, For the training samples belong to the category The predicted probability of .

[0111] According to the calculated loss value, the model parameters are updated using the error back propagation algorithm until the loss value no longer decreases, and a model for decoding and classification of motor imagery EEG signals can be obtained.

[0112] S3. Use the trained decoding and classification model to decode and classify the motor imagery EEG signals to be decoded and classified.

[0113] Regarding the application of the decoding classification model of the embodiment of the present invention, the embodiment of the present invention represents the motor imagery EEG signal to be decoded and classified into a two-dimensional matrix form and standardizes it, and then inputs the trained decoding classification model to output the predicted probability of different motor imagery categories.

[0114] like Figure 8 As shown, an embodiment of the present invention further provides a system for decoding and classifying motor imagery EEG signals, the system comprising:

[0115] An acquisition preprocessing module 810 is used to acquire and preprocess the motor imagery EEG signal to obtain EEG data represented in a two-dimensional matrix form, and divide the EEG data into a training set and a test set;

[0116] A training module 820 is used to train a decoding classification model using the EEG data training samples in the training set, wherein the decoding classification model is based on spatiotemporal feature embedding and twice applying a local window attention mechanism;

[0117] The decoding and classification module 830 is used to use the trained decoding and classification model to decode and classify the motor imagery EEG signals to be decoded and classified.

[0118] The functional structure of a system for decoding and classifying motor imagery EEG signals provided in an embodiment of the present invention corresponds to the method for decoding and classifying motor imagery EEG signals provided in an embodiment of the present invention, which will not be described in detail here.

[0119] Fig. 9 It is a structural diagram of an electronic device 900 provided in an embodiment of the present invention. The electronic device 900 may have relatively large differences due to different configurations or performances, and may include one or more processors (central processing units, CPU) 901 and one or more memories 902, wherein the memory 902 stores at least one instruction, and the at least one instruction is loaded and executed by the processor 901 to implement the steps of the above-mentioned method for decoding and classifying motor imagery EEG signals.

[0120] In an exemplary embodiment, a computer-readable storage medium is also provided, such as a memory including instructions, which can be executed by a processor in a terminal to complete the above method of decoding and classifying motor imagery EEG signals. For example, the computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.

[0121] A person skilled in the art will understand that all or part of the steps to implement the above embodiments may be accomplished by hardware or by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a disk or an optical disk, etc.

[0122] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims

1. A method for decoding and classifying motor imagery EEG signals, characterized in that: The method comprises: S1, acquiring and preprocessing motor imagery EEG signals to obtain EEG data represented in a two-dimensional matrix form, and dividing the EEG data into a training set and a test set; S2. Using the EEG data training samples in the training set, training a decoding classification model, wherein the decoding classification model is based on spatiotemporal feature embedding and twice applying a local window attention mechanism; S3. Use the trained decoding and classification model to decode and classify the motor imagery EEG signals to be decoded and classified.

2. The method according to claim 1, characterized in that The S1 specifically includes: S11, obtaining motor imagery EEG signals, using a notch filter to remove the power frequency noise of the motor imagery EEG signals, using a bandpass filter to filter the motor imagery EEG signals, intercepting the EEG signals of the subjects' actual motor imagery of a fixed time length in the middle for subsequent training and classification, and obtaining a number of original EEG data represented in the form of a two-dimensional matrix, wherein the rows of the two-dimensional matrix represent the electrode channels of the spatial dimension, and the columns of the two-dimensional matrix represent the sampling points of the time dimension, and the EEG data are divided into a training set and a test set, wherein each training sample in the training set belongs to a classification label of a different motor imagery category; S12, normalizing the distribution of the original EEG data training samples in the training set to a specific distribution; S13. Use the segmentation and reconstruction strategy to perform data enhancement on the standardized training samples, including: A preset number of samples to be synthesized of each classification label are randomly selected from the training set, each sample to be synthesized is evenly divided into a preset number of parts in chronological order, a section of all samples to be synthesized is selected in sequence, and finally merged together to form a new sample, which is trained together with the original training samples.

3. The method according to claim 1, characterized in that The decoding classification model consists of an EEG data input module, a spatiotemporal feature embedding module, a first local window attention module, a feature fusion module, a second local window attention module, and a classifier output module; The EEG data input module is used to input the EEG data training samples; The spatiotemporal feature embedding module is used to perform convolution operation on the input EEG data training sample through a series of convolution kernels, each convolution kernel can learn a specific feature pattern to obtain a first low-dimensional feature matrix, the convolution kernel is a shallow convolution, which preliminarily extracts the shallow spatiotemporal feature representation, and then uses two local window attention mechanisms for deep learning; The first local window attention module is used to redistribute the local information of the first low-dimensional feature matrix based on the local window attention mechanism for the first time, assign different weights to different information, so that the model focuses on the information related to motor imagery, and helps the model better capture and utilize long-distance information, thereby obtaining a second low-dimensional feature matrix; The feature fusion module is used to fuse the features of the second low-dimensional feature matrix to obtain a third low-dimensional feature matrix; The second local window attention module is used to redistribute the local information of the third low-dimensional feature matrix again based on the local window attention mechanism, and assign different weights to different information again, so that the model can further focus on the information related to motor imagery, and further help the model to better capture and utilize long-distance information, thereby obtaining a fourth low-dimensional feature matrix; The classifier output module is used to further reduce the dimension of the fourth low-dimensional feature matrix and output the predicted probabilities of different motor imagery categories.

4. The method according to claim 3, characterized in that The spatiotemporal feature embedding module performs shallow convolution on the time dimension and the spatial dimension of the EEG data training sample, respectively, including a two-dimensional convolution layer, a batch normalization layer, a two-dimensional deep convolution layer, a batch normalization layer, an average pooling layer and a position encoding layer connected in sequence; The two-dimensional convolution layer is used as a temporal filter to generate outputs containing features of different frequency bands. For the EEG data training sample with a shape of 1×22×1000, a two-dimensional convolution layer with an output channel of 16 and a convolution kernel size of 1×63 is used, and the shape of the time dimension is kept unchanged by adding padding, resulting in a feature matrix with a shape of 16×22×1000. Here, the size of the convolution kernel is set to 1 / 4 of the sampling rate. Then, a two-dimensional deep convolution layer with an output channel of 32 and a convolution kernel size of 22×1 is used to convolve each feature channel separately, and the 22 electrode channels are fused into one channel to promote the spatial feature expression across electrodes. The shape of the feature matrix is ​​32×1×1000. Here, deep convolution is used to learn a spatial filter for each temporal filter, thereby effectively extracting the spatial features of a specific frequency band. Batch normalization is added after the above two convolutional layers to accelerate model convergence. Next, an average pooling layer with a convolution kernel size of 1×125 and a step size of 1×25 is used in the time dimension for feature dimensionality reduction. The shape of the feature matrix is ​​32×36, where 32 represents the number of feature channels and 36 represents the length of the time series. Finally, parameter-learnable absolute position encoding is added to the features, so that the model can effectively utilize the sequence position information from the markers.

5. The method according to claim 4, characterized in that The first local window attention module divides the feature matrix of shape 32×36 into 6 non-overlapping windows of width 6 according to the length of the time series, obtains 6 feature matrices of size 32×6, applies the local window attention mechanism inside each window, and maps the input feature matrix to the query vector , the key vector Sum value vector , then the query vector and the transpose of the key vector Perform a dot product and divide by the window width Then use The function generates the attention score, and then uses the generated attention score pair value vector Re-weighting is performed and the calculation is as follows: ; Use multi-head attention to extract multi-dimensional features from different subspaces to improve the model's fitting ability and perform parallel computing. The feature mapping of the query vector, key vector and value vector is obtained The shape of the feature matrix after merging these feature matrices is 32×6. ×32×6, and then the output with shape of 32×6 is obtained through feature mapping, which is calculated as follows: ; ; in , is the number of attention heads used, They are all parameter matrices of feature mapping layers; The first local window attention module completes the calculation process of one window division: First, the input feature matrix Perform layer normalization, then calculate the weighted feature matrix of the multi-head attention, and then compare it with the input feature matrix The residual connection is added to obtain the intermediate feature matrix , and then through layer normalization and multi-layer perceptron, and with the intermediate feature matrix The residual connection is added to obtain the output feature matrix , which can be expressed as follows: ; ; in Representative layer standardization, stands for Multilayer Perceptron; The feature matrices of the shape of 32×6 calculated in the six windows are merged again to obtain a feature matrix of the shape of 32×36 that is consistent with the shape before the windows are divided; Next, the first local window attention module shifts the window backward by half the window width and merges the first and last two windows together, also obtaining 6 windows of size 32×6. The local window attention mechanism is applied again inside the new window to realize cross-window information interaction to supplement local information.

6. The method according to claim 5, characterized in that The feature fusion module enables the model to obtain a gradually larger receptive field for EEG data through feature fusion, thereby solving the limitation brought by the fixed window size, including: The 32×36 feature matrix obtained by the first application of the local window attention mechanism is regarded as a feature sequence of length 36. Each group of adjacent features in the sequence is concatenated 32×1 to obtain a 64×18 feature matrix, which is then processed through layer normalization and feature mapping layers. The layer normalization improves the model training speed, and the feature mapping layer captures higher-level abstract features and enhances the expressiveness of the network by learning weight parameters and performing linear and nonlinear transformations.

7. The method according to claim 6, characterized in that The second local window attention module divides the feature matrix with a shape of 64×18 into three non-overlapping windows with a width of 6 according to the length of the time series, obtaining three feature matrices with a size of 64×6, and applies the local window attention mechanism again within each window to redistribute the local information of the feature matrix with a shape of 64×18, thereby obtaining a new feature matrix with a shape of 64×18; Next, the second local window attention module shifts the window backward by half the window width and merges the first and last two windows together to obtain three windows of size 64×6. The local window attention mechanism is applied again inside the new window to realize cross-window information interaction to supplement local information.

8. A system for decoding and classifying motor imagery EEG signals, characterized in that: The system comprises: An acquisition preprocessing module is used to acquire and preprocess the motor imagery EEG signal to obtain EEG data represented in a two-dimensional matrix form, and divide the EEG data into a training set and a test set; A training module, for training a decoding classification model using the EEG data training samples in the training set, wherein the decoding classification model is based on spatiotemporal feature embedding and twice applying a local window attention mechanism; The decoding and classification module is used to use the trained decoding and classification model to decode and classify the motor imagery EEG signals to be decoded and classified.

9. An electronic device, comprising a processor and a memory, wherein instructions are stored in the memory, characterized in that: The instructions are loaded and executed by the processor to implement the method for decoding and classifying motor imagery EEG signals as described in any one of claims 1-7.

10. A computer-readable storage medium, wherein instructions are stored in the storage medium, characterized in that: The instructions are loaded and executed by the processor to implement the method for decoding and classifying motor imagery EEG signals as described in any one of claims 1-7.

Citation Information

Cited By

  • Data-driven electroencephalogram channel expansion method and system

    CN119885074A

  • A data-driven electroencephalography channel expansion method and system

    CN119885074B

  • Robot control method and robot control system

    CN120620235A

  • Robot control method and control system for a robot

    CN120620235B

  • Training method of motor imagery type feedback system

    CN121659067A