Brain-computer interface experiment-oriented low-artifact high-synchronization electroencephalogram acquisition paradigm automatic control system and method
Patent Information
- Application Number
- CN202611020658.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-09
- Publication Date
- 2026-10-30
AI Technical Summary
但现有系统普遍存在以下问题:缺乏统一的时间管理机制,时序控制多依赖框架原生计时或人工代码控制,精度难以保证;刺激事件与脑电采样信号时间错位显著,误差可达数百毫秒,直接影响后续特征提取的准确性与分类算法的性能;虽然已有研究提出了基于分布式事件分发系统的解决方案,如TiD系统,通过TCP或共享内存分发含时间戳的XML格式事件消息,事件分发延迟在千兆网络下可达0.3~0.5ms,但其应用尚不普及,且需要额外的服务器基础设施支持;事件记录格式与字段定义不统一,导致数据无法直接与脑电原始信号对齐分析,降低了实验数据的利用价值
本发明基于Routine级时钟锁定算法与统一时间管理机制,单试次各阶段时间误差≤10ms,实现刺激事件与脑电采样的精准对齐,较传统系统时序精度大幅提升;试次间1.5s纯黑无视觉刺激设计从源头抑制EOG、VEP等视觉伪迹,伪迹比例降低≥30%,运动想象相关脑电成分信噪比提升≥25%;带约束的全随机试次分配算法避免同类任务连续出现≥3次,有效消除受试者任务预期,非运动想象神经活动混入比例降低≥40%,数据客观性与纯粹性显著增强;模块化范式构建与标准化参数配置使跨实验室复现成功率≥95%,范式移植时间缩短至30分钟内,解决了传统范式碎片化、不可复用的问题;全流程自动化控制与多传感同步接口设计,使采集效率提升≥50%、人工干预降低,拓展了系统应用规模;多格式标准化数据存储与完整性校验机制,确保数据具备良好的跨平台兼容性、可追溯性与安全性,为大规模标准化脑电数据集构建、BCI算法训练与验证提供了高质量技术支撑。
Smart Images

Figure CN123017416A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of brain-computer interface and neural engineering experimental systems, and in particular to an automatic control system and method for a low-artifact, high-synchronization EEG acquisition paradigm for brain-computer interface experiments. Background Technology
[0002] Brain-computer interface (BCI) technology enables direct information interaction between humans and machines by collecting and analyzing neural signals from the human brain. It has wide applications in fields such as neurorehabilitation, assisted control, cognitive neuroscience research, and intelligent interaction. In BCI research, the motor imagery (MI) paradigm is one of the most core experimental paradigms. By inducing specific brain neural activities in subjects, it provides core training and validation data for BCI algorithms.
[0003] However, the standardization and reproducibility of brain-computer interface (BCI) experiments have become a key bottleneck restricting the field's development. Research by the European Consortium for Quality Preclinical Data (EQIPD) indicates significant differences in EEG experimental data between different laboratories, and that standardized protocols and centralized data processing are crucial for reducing inter-laboratory variability. Multicenter studies by international brain laboratories further confirm that even with standardized procedures, variability and non-reproducibility of experimental results remain prominent in neurophysiological recordings, necessitating the establishment of unified quality control standards to improve reproducibility. This reproducibility crisis in biological and biomedical research has also spread to BCI research, hindering the speed of validating new discoveries and causing significant financial and ethical consequences.
[0004] In EEG acquisition experiments for motor imagery, the experimental system needs to simultaneously perform core tasks such as stimulus presentation control, experimental process scheduling, experimental event timing recording, EEG signal acquisition, and experimental data storage. However, existing brain-computer interface experimental systems still have the following shortcomings in the acquisition and control of motor imagery paradigms: The development of traditional brain-computer interface (BCI) experimental systems heavily relies on manually written low-level control programs. Experimental procedures, stimulation logic, timing control, and trial scheduling are all independently written by researchers. Due to significant differences in programming habits, program structure design, and parameter definitions among researchers, the experimental paradigm is severely fragmented, lacking unified module division and interface standards. Paradigm parameters (such as stimulation duration, number of trials, and rest mechanisms) lack unified specifications, making direct reuse or comparison between different experiments and laboratories impossible. Experimental procedures are difficult to reproduce, hindering the formation of unified experimental data standards and consequently making it difficult to construct large-scale, standardized, high-quality EEG datasets, thus impeding the cross-platform validation and development of BCI algorithms. Furthermore, simulations from multi-laboratory studies show that while complete standardization can reduce variability, a certain degree of heterogeneity may actually improve the ability of multi-center studies to discover real effects. Therefore, striking a balance between standardization and flexibility is a pressing issue.
[0005] Motor imagery EEG acquisition demands high temporal accuracy, requiring a precise one-to-one correspondence between stimulus presentation time, experimental event occurrence time, and EEG sampling time. Event tagging in BCI experiments is crucial for recording and describing various events during the experiment, and is essential for subsequent data analysis and real-time processing. However, existing systems generally suffer from the following problems: a lack of a unified time management mechanism, with timing control relying heavily on native framework timing or manual code control, making it difficult to guarantee accuracy; significant time misalignment between stimulus events and EEG sampling signals, with errors reaching hundreds of milliseconds, directly impacting the accuracy of subsequent feature extraction and the performance of classification algorithms; although some studies have proposed solutions based on distributed event distribution systems, such as the TiD system, which distributes timestamped XML-formatted event messages via TCP or shared memory, achieving event distribution latency of 0.3–0.5 ms on gigabit networks, its application is not yet widespread and requires additional server infrastructure support; inconsistent event recording formats and field definitions prevent data from being directly aligned with raw EEG signals for analysis, reducing the utilization value of experimental data.
[0006] EEG signals related to motor imagery (such as mu / β rhythms) are relatively weak and highly susceptible to interference from various physiological and non-physiological artifacts. The inherent low signal-to-noise ratio (SNR) of EEG signals is one of the core challenges faced by BCI systems. Existing experimental systems generally suffer from design flaws during the rest phase between trials: some systems embed visual cues such as text, icons, and progress bars during the rest phase, forcibly activating the subject's visual cortex and eye-tracking system; this introduces strong artifacts such as electrooculography (EOG) and visual evoked potentials (VEP), severely contaminating the core EEG features related to motor imagery; the lack of artifact suppression mechanisms leads to a significant reduction in the SNR of EEG signals, directly affecting the reliability of subsequent neuroanalysis results and the training effect of BCI algorithms. Although some studies have proposed backend artifact suppression algorithms such as pre-whitening and zero projection (PWNP) that can achieve 78%–85% artifact suppression in invasive BCI, these methods focus on the data processing stage rather than source suppression in the experimental paradigm design stage.
[0007] Trial scheduling is a core component of motor imagery experiments, directly impacting the subjects' neural activity. Traditional trial scheduling strategies often employ a fixed sequence, making it easy for subjects to form task expectations and generate preparatory neural activity in their brains. Simple randomization strategies fail to consider constraints to avoid consecutive similar tasks, leading to an excessively high probability of similar tasks appearing consecutively. These issues result in a large amount of non-motor imagery neural activity being mixed into the subjects' EEG signals, compromising the objectivity and purity of the experimental data and severely affecting the convergence and generalization ability of the BCI model training.
[0008] Existing BCI experimental systems are mostly limited to the visual stimulus presentation level, exhibiting significant shortcomings in their integration with underlying EEG sensing devices. While open-source modules (such as the pymarkerlib library) support sending event markers to external devices via serial communication for synchronization, and PsychoPy and the BCI2000 platform can remotely update states and events through custom components, these solutions are mostly independent tools and have not formed a standardized interface architecture between the paradigm and the sensing layer. Furthermore, the lack of dedicated sensing synchronization interfaces and algorithms prevents precise time synchronization between stimulus events and multi-channel EEG sensing device sampling. This severely limits the scalability and application scale of experimental systems, failing to meet the current demands of brain science research for large-scale, multimodal data acquisition. Summary of the Invention
[0009] To achieve the above-mentioned objectives and other advantages of the present invention, a first objective of the present invention is to provide an automatic control system for a low-artifact, high-synchronization EEG acquisition paradigm for brain-computer interface experiments, comprising: The experimental parameter configuration module is used to receive the input of experimental parameters through a graphical user interface, and generate a standardized experimental configuration structure after verifying the format of the experimental parameters. The experimental paradigm construction module is used to divide the experimental process into multiple standardized independent stages and establish the experimental process structure through a stage component loading algorithm. The independent stages include the gaze stage, the task prompting stage, the motor imagery stage, and the rest stage. The experimental process control module, as the system's overall control unit, is used to coordinate the execution order of each module and realize fully automated management of the entire process from experimental environment initialization to experimental conclusion. The stimulus presentation control module is used to uniformly control the presentation time of experimental stimuli using a routine-level clock-locking algorithm. In a single trial, it presents the gaze cross, auditory cues, and directional clues according to a preset sequence, and performs a rest control without visual stimulation after the motor imagery phase ends. The experimental loop scheduling module is used to generate a sequence of trials using a fully random trial allocation algorithm with continuous task constraints, and to schedule the execution of trials according to a round-trial double-loop structure. The experimental event tagging module is used to capture the global clock timestamps of each key experimental event in real time and record standardized event attribute information, including trial number, task type and stimulus time. The multi-sensor synchronization docking module is used to encode experimental events into tag codes, transmit them synchronously to the EEG acquisition device through parallel or serial communication interfaces, and record synchronization timestamps to achieve time synchronization between stimulation events and EEG sampling. The data storage management module is used to temporarily store structured experimental data during the experiment and generate standardized data files in multiple formats after the experiment.
[0010] Furthermore, in the stimulus presentation control module, the timing control accuracy of the routine-level clock locking algorithm is ≤10ms for the time error of each stage in a single trial; The temporal structure of a single trial is as follows: 0-2 seconds, a gaze cross is presented and an auditory cue is played; 2-3 seconds, a directional cue is presented; 3-3.25 seconds, the directional cue cue ends and the motor imagery preparation stage begins; 3.25-6 seconds, the motor imagery stage, which is the main time window for EEG signal acquisition; 6-7.5 seconds, a resting stage without visual stimulation, presented using a pure black screen.
[0011] Furthermore, in the stimulus presentation control module, the rest control without visual stimulation adopts an automated rest mechanism with pure black and no visual stimulation. No visual cue information is presented during the rest phase between trials and between rounds, so as to suppress electrooculography artifacts and visual evoked potential artifacts.
[0012] Furthermore, in the experimental cyclic scheduling module, the fully randomized trial allocation algorithm with continuous task constraints includes: Read the experimental conditions table to obtain all task types and the number of trials for each type of task; An unbiased assignment of trial order is performed using a fully random algorithm; Set a constraint condition for consecutive tasks, wherein the number of consecutive occurrences of the same type of task does not exceed 2. If the generated trial sequence violates the constraints, random assignment is performed again until the constraints are satisfied.
[0013] Furthermore, in the round-trial double-layer loop structure, the experiment includes N round loops, N≥1; each round includes M trials, M≥1; and the number of trials for each task type is evenly distributed in each round.
[0014] Furthermore, in the multi-sensor synchronous docking module, the process of encoding experimental events into tag codes and synchronously transmitting them to the EEG acquisition device via a parallel or serial communication interface includes: Pre-configure unique marker codes for various key experimental events; When an event occurs, the tag code is sent to the EEG acquisition device via a parallel port or a serial port; Synchronously record the global clock timestamp of the transmission time and store it in the experimental data structure; The port is reset after a delay after the transmission is completed.
[0015] The second objective of this invention is to provide an automatic control method for a low-artifact, high-synchronization EEG acquisition paradigm for brain-computer interface experiments, comprising the following steps: S1. Start the experimental running framework, complete the experimental window initialization, global clock calibration and device manager initialization, and establish a unified experimental running environment; S2. Receive experimental parameter inputs through a graphical user interface and perform format verification to generate a standardized experimental configuration structure; S3. Adopt a modular assembly method to divide the complete experimental process into multiple functional stages, and establish the experimental process structure through a stage component loading algorithm. S4. Start round-robin scheduling. Each round contains multiple trials. At the beginning of each round, a trial sequence is generated by a fully random trial allocation algorithm with continuous task constraints. S5. Execute each trial task in sequence according to the generated trial sequence. In each trial, the routine-level clock-locking algorithm is used to control the timing of stimulus presentation. The timing control process of a single trial is to present the gaze cross, auditory cues and directional clues in the preset timing sequence, enter the motor imagery stage, and execute the rest control without visual stimulation after the motor imagery stage ends. S6. During the stimulus presentation process, experimental event marking is performed synchronously. The global clock timestamps of key experimental events are recorded through a unified timestamp recording algorithm and stored uniformly through the data management module. S7. Synchronously execute the EEG acquisition synchronization process, and send the experimental event code to the EEG acquisition device through the event-sampling synchronization algorithm to achieve time synchronization between the stimulus event and the EEG sampling. S8. After a single trial is completed, the trial data is written into the experimental data structure. S9. After all trials in the current round have been completed, enter the inter-round rest phase, using rest control without visual stimulation, and wait for the continue instruction before entering the next round; S10. After all rounds of iteration are completed, save the experimental data as a standardized format file and perform data integrity verification. S11. Release experimental system resources and complete the experiment.
[0016] Furthermore, the timing control flow for a single trial is as follows: At 0 seconds, start the global clock, display the gaze crosshair and play an auditory cue tone; At 2 seconds, the gaze cross is turned off, and directional cues are presented; At 3 seconds, directional cues continue to appear, entering the preparation stage for motion visualization; At 3.25 seconds, the motion visualization phase begins; At 6 seconds, the directional cues are turned off, and the system enters a pure black, visually stimulating rest phase. At 7.5 seconds, a single trial ends.
[0017] Furthermore, the event-sampling synchronization algorithm includes: Assign a unique identifier to each of the events: gaze cross presentation, auditory cue playback, directional cue presentation, start of motor imagery, end of motor imagery, and end of trial. When each event occurs, the corresponding tag code is sent to the EEG acquisition device via a parallel or serial communication interface; Synchronously record the global clock timestamps of each event occurrence.
[0018] Furthermore, the fully randomized trial allocation algorithm with continuous task constraints includes: Import the experimental conditions table containing all task types and corresponding number of trials; The initial trial sequence is generated using a fully randomized algorithm; If there are cases in the detection sequence where the same type of task appears more than twice consecutively, then regenerate the trial sequence until the constraints are met.
[0019] Furthermore, the experimental parameters include subject ID, experimental session ID, and experimental version information; The standardized format files include CSV format files, Pickle format files, and log files.
[0020] Compared with the prior art, the beneficial effects of the present invention are: This invention, based on a routine-level clock-locking algorithm and a unified time management mechanism, achieves precise alignment between stimulus events and EEG sampling, with a time error of ≤10ms across all stages of a single trial, significantly improving timing accuracy compared to traditional systems. The 1.5s pure blackout design between trials, eliminating visual stimuli, suppresses visual artifacts such as EOG and VEP at the source, reducing artifact proportions by ≥30% and improving the signal-to-noise ratio of motor imagery-related EEG components by ≥25%. The constrained, fully randomized trial allocation algorithm avoids the consecutive occurrence of similar tasks ≥3 times, effectively eliminating subject task expectations and reducing the proportion of non-motor imagery neural activity contamination by ≥40%. The system's visibility and purity are significantly enhanced; modular paradigm construction and standardized parameter configuration enable cross-laboratory reproducibility success rates of ≥95%, and paradigm transfer time is shortened to within 30 minutes, solving the problems of fragmentation and non-reusability of traditional paradigms; fully automated control and multi-sensor synchronous interface design improve acquisition efficiency by ≥50%, reduce manual intervention, and expand the scale of system applications; multi-format standardized data storage and integrity verification mechanisms ensure that the data has good cross-platform compatibility, traceability, and security, providing high-quality technical support for the construction of large-scale standardized EEG datasets and the training and verification of BCI algorithms.
[0021] The above description is merely an overview of the technical solution of the present invention. In order to better understand the technical means of the present invention and to implement it according to the contents of the specification, the preferred embodiments of the present invention are described in detail below with reference to the accompanying drawings. Specific embodiments of the present invention are given in detail below with reference to the accompanying drawings. Attached Figure Description
[0022] The accompanying drawings, which are included to provide a further understanding of the invention and form part of this application, illustrate exemplary embodiments of the invention and, together with their description, serve to explain the invention and do not constitute an undue limitation thereof. In the drawings: Figure 1 This is an architecture diagram of an automatic control system for a low-artifact, high-synchronization EEG acquisition paradigm for brain-computer interface experiments. Figure 2 A diagram showing the algorithm composition of an EEG acquisition paradigm for brain-computer interface experiments; Figure 3 This is a schematic diagram of the temporal structure of a single trial stimulus; Figure 4 Flowchart of an automatic control method for a low-artifact, high-synchronization EEG acquisition paradigm for brain-computer interface experiments; Figure 5 This is a schematic diagram of a computer device. Figure 6 This is a schematic diagram of a computer-readable storage medium. Detailed Implementation
[0023] The present invention will now be further described with reference to the accompanying drawings and specific embodiments. Obviously, the described embodiments are only a part of the embodiments of the present invention, and not all of them. It should be noted that, without conflict, the various embodiments or technical features described below can be arbitrarily combined to form new embodiments.
[0024] Based on the embodiments of this invention, all other embodiments obtained by those skilled in the art without inventive effort are within the scope of protection of this invention.
[0025] The drawing numbers in this application are only used to distinguish the steps in the scheme and are not used to limit the execution order of the steps. The specific execution order is as described in the specification.
[0026] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains. The terminology used herein in the description of the invention is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention.
[0027] This invention constructs a unified software control architecture to achieve functions such as experimental parameter configuration, modular construction of experimental paradigms, precise control of stimulus presentation, intelligent scheduling of trial cycles, synchronous marking of experimental events, and automated storage of experimental data in brain-computer interface experiments. It also integrates precise timing control, low-artifact acquisition, multi-sensor synchronization, modular construction, and automated scheduling to automate, modularize, standardize, and increase the precision of data acquisition in brain-computer interface motor imagery experiments. It is suitable for scenarios such as the construction of large-scale standardized EEG datasets and the training and validation of BCI algorithms. The specific solution is as follows: Example 1 This invention provides an automatic control system for a low-artifact, high-synchronization EEG acquisition paradigm for brain-computer interface experiments, the overall structure of which is as follows: Figure 1 As shown, this system is built on the PsychoPy visual programming framework and adopts a modular architecture design, including modules for experimental parameter configuration, experimental paradigm construction, experimental process control, stimulus presentation control, experimental cycle scheduling, experimental event marking, multi-sensor synchronization, and data storage management. These modules communicate and collaborate through standardized data interfaces, forming an integrated control architecture encompassing experimental parameter configuration, modular paradigm construction, automated process control, precise stimulus presentation, intelligent trial scheduling, event time marking, multi-sensor synchronization, and structured data storage.
[0028] The system's hardware platform includes an experimental control computer, EEG acquisition equipment, parallel / serial communication interfaces, and a visual stimulation display. The experimental control computer, as the core computing and control unit of the system, establishes a physical connection with the EEG acquisition equipment via a parallel or serial port to achieve real-time transmission of event tag codes.
[0029] In some embodiments, the experimental control computer is configured with an Intel Core i7 or higher processor, 16GB or more of memory, and a display that supports 1920×1080 resolution and a refresh rate of 100Hz or higher to ensure the smoothness and timing accuracy of the presentation of visual stimuli.
[0030] The experimental parameter configuration module is used to receive the input of experimental parameters through a graphical user interface, and generate a standardized experimental configuration structure after verifying the format of the experimental parameters.
[0031] In some embodiments, the experimental parameter configuration module uses the gui.DlgFromDict component provided by the PsychoPy framework as a visual interactive interface. The implementation process of this module is as follows: First, the system defines a default dictionary structure containing the core parameters of the experiment. This dictionary structure must contain at least the following fields: participant ID, session ID, date, expName, and expVersion. The participant ID field uses a random number generator to automatically generate a six-digit numeric code, which is then formatted as a string and used as the default value; the date field automatically obtains the current system date by calling a date function.
[0032] Secondly, the module creates a parameter input dialog box using the gui.DlgFromDict component. This dialog box displays each parameter field in form format, with each field containing a parameter name identifier and an input box. Users can modify or confirm parameter values in the input boxes. The dialog box's sorting method is set to maintain the original dictionary order (sortKeys=False), and the title is set to "Experimental Parameter Configuration" for easy user identification.
[0033] Then, the module responds to user actions. When the user clicks the "OK" button to confirm the input, the module reads the current values of each field and encapsulates them into a standardized experimental configuration structure; when the user clicks the "Cancel" button to cancel the operation, the module calls the core exit function to terminate the experiment.
[0034] Finally, the module performs format validation on the key parameters entered by the user. The validation rules include: subject IDs must be in six-digit format, and session IDs must be in three-digit format. If the format validation passes, a standardized experimental configuration structure is generated and passed to other functional modules; if the format validation fails, an error message window pops up prompting the user to re-enter the information.
[0035] In some embodiments, the standardized experimental configuration structure is stored and transmitted using a Python dictionary object data structure, containing all experimental parameter key-value pairs. It adopts a unified field naming convention and data type definition to ensure that all modules in the system can read and use experimental parameters in a consistent manner, thereby eliminating the problem of paradigm fragmentation caused by inconsistent parameter definitions.
[0036] The experimental paradigm construction module is used to divide the experimental process into multiple standardized independent stages, and to establish the experimental process structure through a stage component loading algorithm. Each independent stage includes at least a gaze stage, a task-cue stage, a motor imagery stage, and a rest stage.
[0037] In some embodiments, the experimental paradigm building module divides a complete motion imagery experiment into the following standardized phases: title phase, welcome phase, trial phase, break time phase, and ending phase. The title phase displays the experiment name and basic information at the start of the experiment, guiding participants to confirm the start of the experiment; the welcome phase displays the experimental instructions and precautions to help participants understand the experimental procedure; the trial execution phase is the core phase of the experiment, responsible for performing stimulus presentation and data collection tasks for each trial; the rest phase provides participants with rest time between trials or rounds; and the end phase displays information on the completion of the experiment and the data retention status.
[0038] Each stage of the module is constructed using a visual component configuration approach. Taking the title stage as an example, the module first creates a text stimulus component (visual.TextStim), sets the text content to "BCI Motor Imagery EEG Acquisition Experiment," the position coordinates to the center of the screen (0,0), the font size to 0.06, and the color to white. Then, by setting the drawing property (setAutoDraw(True)), the text is automatically drawn to the screen buffer during each frame rendering, and the buffer content is pushed to the display for presentation using the window flipping command (win.flip()). This stage uses a key event listening mechanism (event.waitKeys(keyList=['space']))) to wait for the user to press the space bar to trigger the next stage.
[0039] The module establishes logical connections and transition conditions between stages through a stage component loading algorithm. Each stage has independent entry and exit conditions, and automatically switches to the next stage after the previous stage is completed according to the preset flow control logic, without manual intervention.
[0040] In some embodiments, parameters for each stage (such as stimulus text content, location coordinates, font size, trigger buttons, etc.) can be adjusted via a configuration panel without modifying the underlying source code. The experimental workflow structure is visualized as a flowchart, allowing researchers to intuitively view the logical relationships and transition sequences between stages. This modular assembly method makes the experimental paradigm highly reusable and compatible across laboratories.
[0041] The experimental process control module, as the system's overall control unit, is used to coordinate the execution order of each module, achieving fully automated management of the entire process from experimental environment initialization to experimental completion.
[0042] In some embodiments, the implementation process of the experimental process control module is as follows: Experimental environment initialization phase: The module first calls the window initialization function of the PsychoPy framework to create the experimental display window and configure window parameters, including window size, color mode, full-screen mode, etc. At the same time, the module initializes the global clock (core.Clock) to establish a unified experimental time base; and calls the device manager (hardware.DeviceManager) to complete the connection and configuration of peripherals such as parallel ports, serial ports, and audio devices.
[0043] Module scheduling and execution phase: The module calls each functional module sequentially according to the preset scheduling order. The specific scheduling logic is as follows: First, the experimental parameter configuration module is invoked to complete parameter input and verification. Then, the experimental paradigm construction module is invoked to establish the experimental process structure. Next, the round loop begins. In each round, the experimental loop scheduling module is invoked to generate the trial sequence, and then the trial loop begins. In each trial, the stimulus presentation control module, experimental event marking module, and multi-sensor synchronization docking module are executed sequentially. After a single trial is completed, the temporary storage function of the data storage management module is executed. The rest control function is invoked between rounds. After all rounds are completed, the final data storage and integrity verification are performed.
[0044] System resource release phase: After the experiment is completed, the module closes the display window, releases the device communication interface, saves the experiment log, and completes the system resource reclamation.
[0045] In some embodiments, the process control module records the experimental operation status in real time through a unified status management mechanism, including the current stage, the current round number, the current trial number, etc., providing basic support for the system's anomaly handling and breakpoint recovery.
[0046] The stimulus presentation control module is one of the core modules of this invention for achieving precise timing control and artifact suppression. This module is used to uniformly control the presentation time of experimental stimuli using a routine-level clock-locking algorithm. In a single trial, it presents the gaze cross, auditory cues, and directional clues according to a preset timing sequence, and performs a rest control without visual stimulation after the motor imagery phase ends.
[0047] In some embodiments, the routine-level clock-locking algorithm achieves precise timing control of stimulus presentation through the following steps: First, at the start of a single trial, the module creates a dedicated routine timer (routineTimer = core.Clock()) that starts counting from the start of the trial.
[0048] Next, the module enters the timing control main loop. In the main loop, the module obtains the current timer reading in real time (t = routineTimer.getTime()) and automatically switches the stimulus state based on the difference between the current time and the preset time point. A tolerance parameter (frameTolerance) is introduced in the timing comparison. This parameter is dynamically calculated based on the display refresh rate and is typically set to half the display refresh cycle to compensate for the slight delay caused by frame refresh.
[0049] Then, the module controls the display state of each stimulus component through conditional statements. When the current time reaches the preset time point, the module adds the corresponding stimulus component to the drawing queue by setting the drawing property (setAutoDraw(True)); when the display end time point is reached, the module removes the stimulus component from the drawing queue by canceling the drawing property (setAutoDraw(False)).
[0050] Finally, in each iteration of the timing control main loop, the module calls the window flip function (win.flip()) to synchronously present all stimuli in the drawing queue to the display. This loop continues to run until the total trial duration ends.
[0051] In some embodiments, the accuracy of timing control is ensured through the following mechanisms: high-precision clock timing using the PsychoPy framework, unaffected by operating system multitasking; frame synchronization mechanism to ensure that stimulus switching and display refresh remain synchronized; and the elimination of cumulative errors caused by the display frame refresh cycle through tolerance parameter settings. Experimental verification shows that the timing control error of each stage in a single trial is ≤10ms.
[0052] In some embodiments, the total duration of a single trial is 7.5 seconds, such as... Figure 3 As shown, the specific timing structure is as follows: At 0 seconds, the system starts the global clock, displays the gaze crosshair, and plays an audible cue simultaneously. The gaze crosshair is a white cross shape, drawn using the visual.ShapeStim component, with a size of 0.03 and a white color, located in the center of the screen. The audible cue is a pure A tone, lasting 0.3 seconds, played through the sound.Sound component, and its start time is precisely aligned with the appearance time of the gaze crosshair.
[0053] At the 2-second mark, the system deactivates the gaze crosshair and presents directional cues. These cues are left, right, up, or down arrows drawn using the `visual.TextStim` component, with a font size of 0.2, white color, and centered on the screen. The specific direction of the cues is determined by the task type of the current trial (left hand corresponds to a left arrow, right hand to a right arrow, both feet to a down arrow, and tongue to an up arrow). These directional cues remain displayed for up to 6 seconds.
[0054] At the 3-second mark, the directional cues have been presented for 1 second, and the subject has completed the identification and understanding of the task direction and has begun to mentally prepare for motion visualization.
[0055] At 3.25 seconds, the subject enters the motor imagery phase. Based on directional cues, the subject mentally performs a corresponding motor imagery task. This phase, lasting up to 6 seconds, is the primary time window for EEG signal acquisition. It is important to note that directional cues remain present throughout the motor imagery phase, providing continuous visual reference for the subject.
[0056] At the 6-second mark, the system shuts down directional cues and enters a completely black, visually stimulating rest phase. During this time, the screen displays a completely black image, without any text, icons, progress bars, or other visual cues.
[0057] At 7.5 seconds, a single trial ends.
[0058] In some embodiments, the graded rest control without visual stimulation includes two levels: rest control between trials and rest control between rounds.
[0059] Inter-trial rest control: During a 6-7.5 second interval between each trial, the system automatically enters a completely black, visually stimulating rest state. During this rest phase, the screen displays absolutely no visual information, thus preventing activation of the visual cortex and suppressing eye movement artifacts (EOG) and visual evoked potentials (VEPs). Subjects take a short rest during this phase to prepare for the next trial.
[0060] Inter-run rest control: After all trials are completed in each run, the system enters the inter-run rest phase. This phase also employs a pure black, non-visually stimulating design; the screen displays a completely black image without any text, icons, or progress bars. Unlike trial-to-trial rests, the duration of the inter-run rest is controlled by the subject. The system uses a button event listening mechanism to wait for the subject or experimenter to press a designated button before automatically proceeding to the next run.
[0061] In some embodiments, during the rest periods between rounds, the system records the start and end times of the rest in the background and stores them in the experimental data as supplementary information. Simultaneously, the system maintains the connection of the EEG acquisition device during the rest period but does not send event markers to avoid additional interference with the EEG signals.
[0062] Through the above-mentioned rest control design without visual stimulation, this invention suppresses visually induced physiological artifacts at the source from the experimental paradigm design level, and significantly improves the purity and signal-to-noise ratio of motor imagery EEG signals.
[0063] The experimental loop scheduling module is used to generate a sequence of trials using a fully random trial allocation algorithm with continuous task constraints, and to schedule the execution of trials according to a round-trial double-loop structure.
[0064] In some embodiments, the experiment consists of 6 runs, each containing 48 trials. Four types of motor imagery tasks (left hand, right hand, both feet, tongue) appear 12 times in each run.
[0065] The scheduling of rounds is implemented using the TrialHandler2 component. The module first creates a round-level trial handler (runs = data.TrialHandler2(name='runs', nReps=6, method='sequential',trialList=[None])), using the sequential execution method and setting the number of rounds to 6. Then, the round is added to the experimental workflow using the experimental data management object (thisExp.addLoop(runs)).
[0066] Within each round, the module creates a trial-level trial handler (run = data.TrialHandler2(name='trial', nReps=12, method='fullRandom', trialList=trialList)) using a fully randomized method, repeating each task type 12 times. The trial list (trialList) is read from the experimental conditions table file using the data import function (data.importConditions('conditions.xlsx')).
[0067] In some embodiments, the fully randomized trial allocation algorithm with continuous task constraints includes the following steps: The module reads the experimental conditions table file (conditions.xlsx) to obtain all task types and the number of trials for each task type. The experimental conditions table is an Excel file containing fields such as task type name (task_type), task code (task_code), and cue text (cue_text).
[0068] The module employs a fully randomized algorithm to initially assign the order of trials. The core idea of this algorithm is to ensure that the number of trials for each task is fixed, while maintaining a completely random order without pre-setting any fixed sequence. Specifically, it first generates a complete list containing all trials, then uses the Fisher-Yates shuffle algorithm to randomly arrange the list, obtaining the initial trial sequence.
[0069] The module sets a constraint on consecutive tasks, which stipulates that the number of consecutive occurrences of the same type of task shall not exceed 2. That is, in the generated trial sequence, no two or more tasks of the same type may occur three or more times consecutively.
[0070] The module performs constraint checks on the initial sequence of trials. The check is performed by iterating through each trial in the sequence and counting the number of consecutive occurrences of the same task type in the current trial and subsequent trials. If any task type is found to occur three or more times consecutively, the sequence is deemed to violate the constraints.
[0071] If the sequence violates the constraints, the module performs a fully random reassignment, generating a new sequence of trials, and checks the constraints again. This process is repeated until the generated sequence satisfies the constraints. Experiments show that, under the condition of 12 trials for each of the four types of tasks, the algorithm typically generates a sequence that satisfies the constraints in no more than 3 retries.
[0072] In some embodiments, in order to ensure the unpredictability of the trial sequence, the module will also perform a randomness test on the sequence after each sequence that meets the constraints, to ensure that there is no significant periodic pattern in the sequence, and further eliminate the possibility of the subject forming task expectations.
[0073] The experimental event tagging module is used to capture the global clock timestamps of each key experimental event in real time and record standardized event attribute information, which includes at least the trial number, task type and stimulus time.
[0074] In some embodiments, the experimental event marking module implements unified management of event data through an experimental data management object (ExperimentHandler). The core implementation of this module is as follows: First, the module obtains the current time in floating-point format using the global clock (globalClock.getTime(format='float')). The global clock starts counting from the moment the experiment begins, ensuring that the timestamps of all events are based on the same time base.
[0075] Secondly, the module captures and records timestamps when the following key events occur: The gaze cross presentation event (fixation_start): At 0 seconds, the system calls the data addition function (thisExp.addData('fixation_start', t_fixation)) to store the current timestamp as the key "fixation_start" into the experimental data structure.
[0076] Auditory cue playback event (audio_cue_start): At 0 seconds, in sync with the gaze crosshair, the system records the start timestamp of the auditory cue.
[0077] Directional cue presentation event (cue_start): At 2 seconds, the system records the timestamp of the directional cue presentation.
[0078] Motion imagery start event (MI_start): At 3.25 seconds, the system records the start timestamp of the motion imagery phase.
[0079] End of Motion Imagination Event (MI_end): At 6 seconds, the system records the timestamp of the end of the motion imagination phase.
[0080] Trial end event (trial_end): At 7.5 seconds, the system records the trial end timestamp.
[0081] Then, the module associates and stores the timestamps of each event with the context information of the current trial. The context information includes: trial number (obtained via thisExp.trialIndex), current round number, task type (obtained via thisExp.getCurrentTrial().task_type), task code (task_code), etc.
[0082] In some embodiments, all event data are stored in the experimental data structure as structured fields. Each event record contains complete information such as event name, timestamp, trial number, task type, and additional parameters, providing a complete data foundation for subsequent signal-event alignment analysis.
[0083] The multi-sensor synchronization docking module is used to encode experimental events into tag codes, transmit them synchronously to the EEG acquisition device through parallel or serial communication interfaces, and record synchronization timestamps to achieve time synchronization between stimulation events and EEG sampling.
[0084] In some embodiments, the multi-sensor synchronization docking module achieves physical communication with the EEG acquisition device based on a parallel port. The parallel port address is set to 0x378 (standard LPT1 port address). The implementation of this module is as follows: First, the module establishes a parallel port communication connection during the system initialization phase. A parallel port object is created by calling `parallel.ParallelPort(address=0x378)`, and a port communication test is performed to confirm port availability.
[0085] Secondly, the module pre-configures unique marker codes for various key experimental events. In some embodiments, the marker codes are configured as follows: Then, at the moment each event occurs, the module executes the event-sampling synchronization algorithm. The specific steps of this algorithm are as follows: Based on the task type of the current trial, look up the corresponding tag code value from the tag code dictionary.
[0086] The tag code is sent to the EEG acquisition device through the data output function of the parallel port (parallel_port.setData(task_code[current_task])).
[0087] Synchronously record the global clock timestamp of the transmission time (sync_time = globalClock.getTime(format='float')) and store the timestamp as the key in the experimental data structure.
[0088] Wait 1 millisecond (core.wait(0.001)) to ensure that the EEG acquisition device has correctly received the tag code.
[0089] The parallel port data bits are set to zero by using the port reset instruction (parallel_port.setData(0)), thus completing one mark transmission cycle.
[0090] In some embodiments, to ensure reliable transmission of the tag code, the module performs an acknowledgment verification after each tag is sent to ensure that the EEG acquisition device has correctly received the tag code, effectively avoiding the tag code loss problem caused by hardware communication interference.
[0091] Through the above-described event-sampling synchronization algorithm, this invention achieves precise time synchronization between the paradigm system and the EEG acquisition device, with the synchronization error controlled within the range of parallel port hardware transmission delay (usually less than 1 millisecond), providing a reliable technical guarantee for the precise alignment of stimulus events and EEG sampling.
[0092] The data storage management module is used to temporarily store structured experimental data during the experiment and generate multi-format standardized data files after the experiment.
[0093] In some embodiments, the data storage management module implements full lifecycle management of data through an ExperimentHandler object. The implementation of this module is as follows: During the experiment, each module writes experimental data into the experimental data structure in real time using the data addition function (thisExp.addData(key, value)). The data is written append-only, with each trial's data added as a row record to the data table. The data table structure includes the following fields: Timestamp fields include: fixation_start, audio_cue_start, cue_start, MI_start, MI_end, trial_end, sync_timestamp, etc. Context information fields include: trial_index (trial number), run_index (round number), task_type (task type), and task_code (task code). Subject information fields include: participant (subject ID), session (session ID), and date (experiment date).
[0094] After all rounds of iterations have been completed, the module performs the final data storage operation. The module generates filenames according to preset file naming rules, with the naming format: {participant}_BCI_MI_{date}, where participant is the subject number and date is the experiment date.
[0095] The module generates data files in various formats in the following ways: CSV format file: Call the data saving function (thisExp.saveAsWideText(filename+'.csv')) to save the experimental data as a CSV file in wide table format. CSV files are a universal data format, compatible with mainstream data analysis tools such as Excel, MATLAB, and Python pandas, facilitating cross-platform data sharing and subsequent analysis.
[0096] Pickle format files: Calling the data saving function (thisExp.saveAsPickle(filename+'.pickle')) saves the experimental data as a Pickle file in Python serialization format. Pickle files fully preserve the original structure of the experimental data, including the data type and nested structure of each field, facilitating accurate reproduction and in-depth analysis in the Python environment.
[0097] Log files: The module synchronously generates log files (.log) during the experiment to record key events, system status and abnormal information of the experiment, providing a basis for tracing the source of the experiment and troubleshooting problems.
[0098] In some embodiments, the module performs a data integrity check after the data is saved. The check includes: checking whether the generated CSV file is complete and readable, checking whether the number of data rows matches the expected total number of trials, and checking whether there are any missing values in each key field. If the check passes, the system displays a "Data saved successfully" message on the interface; if the check fails, the system generates an error report and prompts the experimenter to check.
[0099] Through the aforementioned structured and automated data storage mechanism, this invention ensures that experimental data has good cross-platform compatibility, traceability, and integrity, providing a solid data management foundation for the construction of large-scale standardized EEG datasets.
[0100] Example 2 Based on the same concept, this embodiment also provides an automatic control method for a low-artifact, high-synchronization EEG acquisition paradigm for brain-computer interface experiments, which is applied to the automatic control system for the low-artifact, high-synchronization EEG acquisition paradigm for brain-computer interface experiments provided in Embodiment 1. For a detailed description of the automatic control system for the low-artifact, high-synchronization EEG acquisition paradigm for brain-computer interface experiments provided in Embodiment 1, please refer to the corresponding description in Embodiment 1, which will not be repeated here.
[0101] This invention provides an automatic control method for a low-artifact, high-synchronization EEG acquisition paradigm for brain-computer interface experiments. The overall process is as follows: Figure 2 and Figure 4 As shown. This method, through a unified software control flow, realizes a complete experimental control process from experimental initialization, experimental paradigm construction, trial scheduling, stimulus presentation, event labeling to synchronous acquisition and structured storage of EEG data. The method includes the following steps: S1. The system starts the experimental framework, completes experimental window initialization, global clock calibration, and device manager initialization, and establishes a unified experimental environment. The specific implementation process is as follows: First, the system calls the window initialization function of the PsychoPy framework to create the experiment display window.
[0102] Secondly, the system creates a global clock object (globalClock = core.Clock()), which starts counting from the moment of creation, providing a unified time reference for the entire experiment.
[0103] Then, the system creates a Device Manager object (deviceManager = hardware.DeviceManager()), which is responsible for managing the connection and configuration of peripherals such as parallel ports, serial ports, and audio devices. In this embodiment, the Device Manager performs the following initialization operations: detects available parallel port addresses and establishes a connection; if the parallel port is unavailable, it attempts to communicate via the serial port; and initializes the audio device.
[0104] Finally, the system performs a hardware self-test, which includes checking whether the display window is created correctly, whether the global clock is keeping time correctly, whether parallel port communication is normal, and whether the audio device can play sound correctly. After the self-test passes, the system proceeds to step S2.
[0105] S2. The system receives experimental parameter inputs through a graphical user interface, performs format validation, and generates a standardized experimental configuration structure. The specific implementation process is as follows: First, the system defines an experimental parameter dictionary. This dictionary contains the following fields: expInfo = { 'participant': f"{randint(0,999999):06.0f}", # Subject ID, automatically generates a 6-digit random number 'session': '001', # Session number, default is 001 'date': data.getDateStr(), # Experiment date, automatically retrieves the system date 'expName': 'BCI_MotorImagery', # Experiment Name 'expVersion': 'V1.0' # Experimental version number } The subject ID is generated as a six-digit string using a random number generator to ensure that each subject has a unique identifier.
[0106] Secondly, the system uses the gui.DlgFromDict component to create a parameter input dialog box. The dialog box displays all parameter fields in a table format, with each field containing a label and an input box. Users can directly modify parameter values in the input boxes. The dialog box maintains the original dictionary order, and the title is set to "Experimental Parameter Configuration".
[0107] Then, the system detects the user's response. If the user clicks the "OK" button, the module reads the current values of each field in the dialog box and creates a standardized experimental configuration structure; if the user clicks the "Cancel" button, the system calls the core.quit() function to terminate the experiment.
[0108] Finally, the system validates the key parameters input by the user. The specific validation rules are as follows: Subject ID Validation: Check if the participant field is in 6-digit format. If not, display the error message "Subject ID must be 6 digits". Session ID validation: Checks if the session field is in 3-digit number format. If not, an error message "Session ID must be 3 digits" will pop up.
[0109] After successful verification, the standardized experimental configuration structure is provided as a dictionary object for use in subsequent steps.
[0110] S3. The system adopts a modular assembly approach, dividing the complete experimental process into multiple functional stages, and establishing the experimental process structure through a stage component loading algorithm. The specific implementation process is as follows: First, the system defines a list of stages for the experimental process. The stages are arranged in the order of execution: title stage, welcome stage, trial stage, break time stage, and ending stage.
[0111] Secondly, for each stage, the system creates corresponding visualization components and sets parameters. Take the title stage as an example: Create a text stimulus component: title_text = visual.TextStim(win=win, text='BCI Motor Imagery EEG Acquisition Experiment', pos=(0,0), height=0.06, color='white'); Set the component's drawing property: title_text.setAutoDraw(True) to make the text automatically draw in each frame; Perform a window flip using win.flip() to display the text content on the screen. Waiting for a key press: event.waitKeys(keyList=['space']), waits for the user to press the space bar to enter the next stage; Disable component drawing: title_text.setAutoDraw(False) stops text drawing.
[0112] Similarly, the welcome phase displays experimental instructions, the trial execution phase executes the core experimental tasks, the rest phase controls rest between rounds, and the end phase displays experimental completion information.
[0113] In some embodiments, the switching conditions for each stage are controlled by button events, and the next stage is automatically initiated upon completion of each stage without manual intervention. The logical transition relationships between stages are managed uniformly through the process control module.
[0114] S4. The system initiates round-robin scheduling, with each round containing multiple trials. At the beginning of each round, a trial sequence is generated using a fully random trial allocation algorithm with continuous task constraints. The specific implementation process is as follows: First, the system creates round-level trial handlers. A round handler named `runs` is created using `data.TrialHandler2`, with 6 rounds and sequential execution. The trial list for each round is empty. The round handler is added to the experimental loop using `thisExp.addLoop(runs)`.
[0115] Secondly, at the beginning of each round, the system executes a trial sequence generation process. This process is implemented using a fully random trial allocation algorithm with continuous task constraints. The algorithm steps are as follows: The system reads the experimental condition table file (conditions.xlsx) to obtain all task types and the number of trials. In this embodiment, the condition table contains 4 types of tasks, with 12 trials for each type, for a total of 48 trials.
[0116] The system uses the Fisher-Yates shuffle algorithm to generate the initial random trial sequence. Specifically, it iterates backward from the last element, swapping the current element with the element at a random position (inclusive) each time, until all elements have been traversed.
[0117] The system performs a consecutive task constraint check on the generated sequence. The check method is as follows: traverse each position in the sequence and check if the number of consecutive tasks of the same type starting from the current position exceeds 2. If any task type appears consecutively 3 times or more, the sequence is determined to not meet the constraint conditions.
[0118] If the sequence does not meet the constraints, the system re-executes steps (b) and (c) until a trial sequence that meets the constraints is generated.
[0119] Finally, the system stores the generated trial sequence in the trial processor for subsequent steps to execute in sequence.
[0120] S5. The system executes each trial task sequentially according to the generated trial sequence. In each trial, a routine-level clock-locking algorithm is used to control the timing of stimulus presentation. The system presents the gaze cross, auditory cues, and directional clues according to the preset timing, then enters the motor imagery stage. After the motor imagery stage ends, a rest control without visual stimulation is implemented. The specific implementation process is as follows: Implementation of the routine-level clock locking algorithm: At the beginning of each trial, the system creates a routine timer (routineTimer = core.Clock()), which starts counting from the beginning of the trial. Subsequently, the system enters the timing control main loop. The pseudocode for the main loop is as follows: while routineTimer.getTime()<7.5: t = routineTimer.getTime() # 0 seconds to 2 seconds: Present the gaze cross and play an auditory cue. if 0 <= t < 2: fixation_cross.setAutoDraw(True) if t < 0.3: # Play the alert sound only for the first 0.3 seconds audio_cue.play() # 2 seconds to 6 seconds: Turn off gaze at the crosshair, present directional cues. if 2 <= t < 6: fixation_cross.setAutoDraw(False) cue_arrow.setAutoDraw(True) # 6 to 7.5 seconds: Turn off directional cues and enter rest phase. if t>= 6: cue_arrow.setAutoDraw(False) win.flip() The specific process of single-trial timing control is as follows: At time 0, the system starts the global clock, displays the gaze crosshair, and plays an auditory cue. The gaze crosshair is a white cross shape, located in the center of the screen, with a size of 0.03. The auditory cue is a pure tone in the key of A (440Hz), lasting for 300 milliseconds. The gaze crosshair continues to be displayed for 2 seconds.
[0121] At the 2-second mark, the system deactivates the gaze crosshair and presents directional cues. These directional cues are arrows indicating the task direction, with a font size of 0.2 and a white color, located in the center of the screen. The directional cues are determined based on the current task type: left-hand tasks display a left arrow "←", right-hand tasks display a right arrow "→", two-foot tasks display a down arrow "↓", and tongue tasks display an up arrow "↑".
[0122] At the 3-second mark, the directional cue has been presented for 1 second. During this time, the subject observes the directional cue, identifies the task type, and mentally prepares for motor imagery.
[0123] At 3.25 seconds, the system marks the start of the motor imagery phase in the background and records this timestamp in the experimental data structure. This time point is a key starting reference point for EEG signal analysis.
[0124] Between 3.25 and 6 seconds, subjects performed a motor imagery task. During this period, directional cues continued to be presented, but subjects typically stopped focusing on them, providing continuous visual reference. This phase represents the primary time window for EEG signal acquisition.
[0125] At 6 seconds, the system shuts down directional cues and enters a rest phase. The screen turns completely black, providing no visual stimulation.
[0126] A 6-7.5 second rest period without visual stimulation is observed. Subjects take a short break during this period to prepare for the next trial. The completely black screen design suppresses the generation of electrooculography (EOG) and visual evoked potential (VAP) artifacts at their source.
[0127] At 7.5 seconds, a single trial ends. The system records the trial end timestamp and exits the timing control main loop.
[0128] In some embodiments, the timing control tolerance parameter (frameTolerance) is dynamically calculated based on the display refresh rate. For a 100Hz refresh rate display, the tolerance is set to 0.005 seconds (half of the refresh cycle) to ensure that the stimulus switching is no earlier than and no later than the target time point by more than one refresh cycle.
[0129] S6. During stimulus presentation, the system synchronously performs experimental event marking, records the global clock timestamps of key experimental events using a unified timestamp recording algorithm, and stores them uniformly through the data management module. The specific implementation process is as follows: In the timing control main loop of step S5, the system calls the timestamp recording function at the moment each key event occurs.
[0130] The marker for the fixation crosshair presentation event: At time 0, the system calls thisExp.addData('fixation_start',globalClock.getTime()) to record the global timestamp of the fixation crosshair presentation.
[0131] The event marker for the audio cue playback event: At time 0, the system calls thisExp.addData('audio_cue_start',globalClock.getTime()) to record the global timestamp when the audio cue started playing.
[0132] The marker for the directional cue presentation event: At 2 seconds, the system calls thisExp.addData('cue_start',globalClock.getTime()) to record the global timestamp when the directional cue began to appear.
[0133] Marking the start of the motion visualization event: At 3.25 seconds, the system calls thisExp.addData('MI_start',globalClock.getTime()) to record the global timestamp of the start of the motion visualization phase.
[0134] Marking the end of motion visualization event: At 6 seconds, the system calls thisExp.addData('MI_end',globalClock.getTime()) to record the global timestamp of the end of the motion visualization phase.
[0135] The trial end event is marked as follows: At 7.5 seconds, the system calls thisExp.addData('trial_end',globalClock.getTime()) to record the global timestamp of the trial end.
[0136] Meanwhile, during the timestamp recording process, the system also records the context information of the current trial, including: thisExp.addData('trial_index',thisExp.trialIndex) records the trial number, thisExp.addData('run_index',runs.thisIndex) records the current round number, and thisExp.addData('task_type', current_task) records the task type of the current trial.
[0137] All event-marked data is stored in the experimental data structure as structured fields. Each event record contains complete attribute information such as event name, timestamp value, trial number, round number, and task type, forming a complete experimental event timeline and providing accurate time reference for subsequent signal-event alignment analysis.
[0138] S7. The system synchronously executes the EEG acquisition synchronization process, using an event-sampling synchronization algorithm to encode and send experimental events to the EEG acquisition device, achieving time synchronization between stimulus events and EEG sampling. The specific implementation process is as follows: In the timing control main loop of step S5, synchronized with step S6, the system calls the event-sampling synchronization algorithm when a critical event occurs. Taking the motion visualization start event as an example, the specific execution process of the algorithm is as follows: The system searches for the corresponding tag code value from the pre-configured tag code dictionary based on the task type of the current trial. The tag code dictionary is defined as: task_code = {'←':769, '→':770, '↓':771, '↑':772}.
[0139] The system sends the tag code to the EEG acquisition device via the parallel port data output function (parallel_port.setData(task_code[current_task])). This operation is performed directly through the hardware I / O port, with a transmission latency in the microsecond range.
[0140] The system synchronously calls the global clock to obtain the current timestamp (sync_time = globalClock.getTime(format='float')) and stores this timestamp in the experimental data structure with "sync_timestamp" as the key. This timestamp is theoretically the same as the MI_start timestamp recorded in step S6, providing a double verification basis for subsequent data alignment.
[0141] The system executes a 1-millisecond wait delay (core.wait(0.001)) to ensure that the EEG acquisition device has sufficient time to receive and latch the tag code.
[0142] The system clears all data bits of the parallel port to zero using the port reset instruction (parallel_port.setData(0)) to complete the tag transmission cycle.
[0143] In some embodiments, to prevent data asynchrony caused by failed tag code transmission, the system performs an acknowledgment check after each tag transmission to confirm that the EEG acquisition device has correctly received the tag code.
[0144] Through the above-described event-sampling synchronization algorithm, this invention ensures that each key event has a corresponding parallel port marker and timestamp record, achieving precise time synchronization between the paradigm system and the EEG acquisition device.
[0145] S8. After a single trial is completed, the system writes the trial data into the experimental data structure. The specific implementation process is as follows: When the timing control main loop of a single trial ends (i.e., after 7.5 seconds), the system performs the following data storage operation: The system calls the thisExp.nextEntry() function to end the data recording for the current trial and submit all data fields of the current trial (including all timestamps, context information, and task parameters) to the data table of the experimental data structure.
[0146] The system appends the data of the current trial to the data structure in memory as row records. Each row record contains all the field data for that trial, with each field name corresponding to a specific data value.
[0147] The system updates the internal state of the experimental data management object, including automatically incrementing the trial counter (thisExp.trialIndex) by 1, in preparation for the next trial.
[0148] S9. After all trials in the current round have been completed, the system enters a rest phase between rounds, using a rest control without visual stimulation, and waits for the continuation instruction before entering the next round. The specific implementation process is as follows: Once the system detects that all 48 trials in the current run have been completed, the system automatically enters the inter-run rest phase. The specific implementation is as follows: The system switches the screen to a completely black state, displaying no text, icons, progress bars, or other visual information.
[0149] The system records the break start timestamp between rounds in the background (break_start = globalClock.getTime()) and stores it in the experimental data structure.
[0150] The system enters a key-pressing wait state, using the `event.waitKeys()` function to wait for the subject or experimenter to press the space bar. During this wait period, the screen remains completely black, the audio channel remains muted, and no prompts are provided to the subject.
[0151] When the space bar is detected to be pressed, the system records the break end timestamp between rounds (break_end = globalClock.getTime()) and exits the key wait state.
[0152] The system automatically proceeds to the next round, repeating steps S4 through S8.
[0153] In some embodiments, the duration of the rest phase between each round can be flexibly adjusted according to the subject's condition. During the rest period, the EEG acquisition device remains connected but does not send any event markers.
[0154] S10. After all rounds of execution are completed, the system saves the experimental data into a standardized format file and performs data integrity verification. The specific implementation process is as follows: Once all 6 rounds (a total of 288 trials) have been completed, the system will automatically execute the final data storage process.
[0155] The system generates file names based on the experimental parameters obtained in step S2. The naming format is: {participant}_BCI_MI_{date}, where participant is the subject number and date is the experiment date. The file is saved in the "data" subfolder under the current working directory. If this folder does not exist, the system will create it automatically.
[0156] The system generates data files in three formats: CSV format: The `thisExp.saveAsWideText(filename+'.csv')` method saves the experimental data as a comma-separated value (CSV) file. CSV files are stored in a wide table format, with each row representing a data record for one trial and each column representing a data field. The CSV format has good cross-platform compatibility and can be directly opened and analyzed using tools such as Excel, MATLAB's `readtable` function, and Python's `pandas.read_csv` function.
[0157] Pickle format files: Calling `thisExp.saveAsPickle(filename+'.pickle')` saves experimental data in Python serialization format. Pickle files fully preserve the original object structure of the experimental data, including the data types and nesting relationships of all fields, facilitating accurate reproduction in the Python environment.
[0158] Log file: The system outputs the system status, key operations and abnormal information recorded during the experiment to the {filename}.log file for experimental tracing and problem investigation.
[0159] After the data file is generated, the system performs the following integrity verification operations: File existence check: Check whether the CSV file and Pickle file have been successfully created and whether the file size is greater than 0; Data row count verification: Read the number of data rows in the CSV file and compare it with the expected total number of trials (number of rounds × number of trials per round) to confirm that the number of data rows is consistent; Key field integrity verification: Check whether there are null or abnormal values in each key field (such as task type, timestamp fields).
[0160] If all checks pass, the system displays a "Data saved successfully" message in the experiment window and writes a "Data integrity check passed" record to the experiment log. If the checks fail, the system displays an error report in the experiment window, prompting the experimenter to check the data file.
[0161] S11. The system releases experimental system resources, completing the experiment. The specific implementation process is as follows: The system closes the experiment display window by calling the win.close() function to close the window object and release graphics display resources. The system releases parallel port communication resources: the parallel_port.close() function is called to close the parallel port connection and release hardware I / O resources; The system shuts down the audio device: stops all audio playback and releases the audio buffer; The system saves the final experimental log: all log records are flushed to the log file, and the file handle is closed; The system outputs the experiment completion information: "Experiment completed, thank you for your participation" is printed in the console.
[0162] This concludes the entire brain-computer interface experiment process.
[0163] To verify the technical effects of the present invention, the inventors conducted verification tests on the above system and method in an actual brain-computer interface experimental environment.
[0164] The relative time difference between the parallel port marker pulse and the display refresh synchronization signal was measured using an oscilloscope. In 1000 trials, the standard deviation of the time error at each stage was ≤5ms, and the maximum error was ≤10ms, verifying the time accuracy of the routine-level clock locking algorithm.
[0165] By comparing two sets of experimental data using rest control without visual stimulation (the present invention) and rest control with visual cues (the conventional approach), the amplitude of electrooculogram artifacts in the EEG data using the present invention was reduced by 32%, and the characteristic components of visual evoked potentials were reduced by 28%, verifying the artifact suppression effect of graded rest control without visual stimulation.
[0166] Statistical analysis of the 48 generated trial sequences showed that, among the 100 independently generated sequences, no sequence showed that the same task appeared more than 3 times consecutively, verifying the effectiveness of the fully randomized trial allocation algorithm with consecutive task constraints.
[0167] The entire experimental system can complete the data collection of all 288 trials within 45 minutes without human intervention, which is 50% more efficient than the traditional manual operation method.
[0168] Through the detailed description of the above specific embodiments, those skilled in the art can clearly understand that the present invention effectively solves the technical problems of existing brain-computer interface experimental systems in terms of paradigm fragmentation, temporal asynchrony, artifact interference, trial bias, and poor sensor synergy through modular architecture design, core algorithm innovation, and standardized process construction. It realizes the automation, modularization, standardization, and high precision of the brain-computer interface motor imagery experiment data acquisition process, and has significant technical progress and practical value.
[0169] Example 3 A computer device 100, such as Figure 5 As shown, the system includes a memory 110, a processor 120, and a computer program 130 stored in the memory and executable on the processor. When the processor executes the computer program, it implements the steps of an automatic control method for a low-artifact, high-synchronization EEG acquisition paradigm for brain-computer interface experiments. For a detailed description of the method, please refer to the corresponding description in the above method embodiments; it will not be repeated here.
[0170] Example 4 A computer-readable storage medium, such as Figure 6 As shown, a computer program is stored thereon. When executed by a processor, this computer program implements the steps of an automatic control method for a low-artifact, high-synchronization EEG acquisition paradigm for brain-computer interface experiments. For a detailed description of the method, please refer to the corresponding description in the above method embodiments; it will not be repeated here.
[0171] The number of devices and processing scale described herein are for the purpose of simplifying the description of the invention. Applications, modifications, and variations of the invention will be readily apparent to those skilled in the art.
[0172] Although embodiments of the present invention have been disclosed above, they are not limited to the applications listed in the specification and embodiments. They can be applied to various fields suitable for the present invention. For those skilled in the art, other modifications can be easily made. Therefore, without departing from the general concept defined by the claims and their equivalents, the present invention is not limited to the specific details and illustrations shown and described herein.
[0173] The apparatus, computer device, and non-volatile computer storage medium and method provided in the embodiments of this specification are corresponding. Therefore, the apparatus, computer device, and non-volatile computer storage medium also have similar beneficial technical effects as the corresponding method. Since the beneficial technical effects of the method have been described in detail above, the beneficial technical effects of the corresponding apparatus, computer device, and non-volatile computer storage medium will not be repeated here.
[0174] Those skilled in the art will also know that, besides implementing the controller in the form of purely computer-readable program code, the same functions can be achieved by logically programming the method steps, making the controller take the form of logic gates, switches, application-specific integrated circuits (ASICs), programmable logic controllers (PLCs), and embedded microcontrollers. Therefore, such a controller can be considered a hardware component, and the devices included within it for implementing various functions can also be considered structures within that hardware component. Alternatively, the devices for implementing various functions can be considered as both software units implementing the method and structures within a hardware component.
[0175] The systems, apparatuses, or units described in the above embodiments can be implemented by computer chips or physical entities, or by products with certain functions. For ease of description, the above apparatuses are described separately as various units based on their functions. Of course, when implementing one or more embodiments of this specification, the functions of each unit can be implemented in one or more software and / or hardware.
[0176] Those skilled in the art will understand that the embodiments of this specification can be provided as methods, systems, or computer program products. Therefore, the embodiments of this specification can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the embodiments of this specification can take the form of a computer program product implemented on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0177] This specification is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this specification. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0178] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0179] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0180] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0181] This specification may be described in the general context of computer-executable instructions, such as program units, that are executed by a computer. Generally, program units include routines, programs, objects, components, data structures, etc., that perform a specific task or implement a specific abstract data type. This specification may also be practiced in distributed computing environments, where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program units may reside in local and remote computer storage media, including storage devices.
[0182] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to interchangeably. Each embodiment focuses on describing the differences from other embodiments. In particular, the system embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments.
[0183] The above description is merely an embodiment of this specification and is not intended to limit the scope of one or more embodiments of this specification. Various modifications and variations can be made to one or more embodiments of this specification by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principle of one or more embodiments of this specification should be included within the scope of the claims of one or more embodiments of this specification.
Claims
1. An automatic control system for a low-artifact, high-synchronization EEG acquisition paradigm for brain-computer interface experiments, characterized in that, include: The experimental parameter configuration module is used to receive the input of experimental parameters through a graphical user interface, and generate a standardized experimental configuration structure after verifying the format of the experimental parameters. The experimental paradigm construction module is used to divide the experimental process into multiple standardized independent stages and establish the experimental process structure through a stage component loading algorithm. The independent stages include the gaze stage, the task prompting stage, the motor imagery stage, and the rest stage. The experimental process control module, as the system's overall control unit, is used to coordinate the execution order of each module and realize fully automated management of the entire process from experimental environment initialization to experimental conclusion. The stimulus presentation control module is used to uniformly control the presentation time of experimental stimuli using a routine-level clock-locking algorithm. In a single trial, it presents the gaze cross, auditory cues, and directional clues according to a preset sequence, and performs a rest control without visual stimulation after the motor imagery phase ends. The experimental loop scheduling module is used to generate a sequence of trials using a fully random trial allocation algorithm with continuous task constraints, and to schedule the execution of trials according to a round-trial double-loop structure. The experimental event tagging module is used to capture the global clock timestamps of each key experimental event in real time and record standardized event attribute information, including trial number, task type and stimulus time. The multi-sensor synchronization docking module is used to encode experimental events into tag codes, transmit them synchronously to the EEG acquisition device through parallel or serial communication interfaces, and record synchronization timestamps to achieve time synchronization between stimulation events and EEG sampling. The data storage management module is used to temporarily store structured experimental data during the experiment and generate standardized data files in multiple formats after the experiment.
2. The automatic control system for a low-artifact, high-synchronization EEG acquisition paradigm for brain-computer interface experiments as described in claim 1, characterized in that, In the stimulus presentation control module, the timing control accuracy of the routine-level clock locking algorithm is ≤10ms for the time error of each stage in a single trial. The temporal structure of a single trial is as follows: 0-2 seconds, a gaze cross is presented and an auditory cue is played; 2-3 seconds, a directional cue is presented; 3-3.25 seconds, the directional cue cue ends and the motor imagery preparation stage begins; 3.25-6 seconds, the motor imagery stage, which is the main time window for EEG signal acquisition; 6-7.5 seconds, a resting stage without visual stimulation, presented using a pure black screen.
3. The automatic control system for a low-artifact, high-synchronization EEG acquisition paradigm for brain-computer interface experiments as described in claim 1, characterized in that, In the stimulus presentation control module, the rest control without visual stimulation adopts an automated rest mechanism with pure black and no visual stimulation. No visual cue information is presented during the rest phase between trials and rounds to suppress electrooculography artifacts and visual evoked potential artifacts.
4. The automatic control system for a low-artifact, high-synchronization EEG acquisition paradigm for brain-computer interface experiments as described in claim 1, characterized in that, In the experimental cyclic scheduling module, the fully randomized trial allocation algorithm with continuous task constraints includes: Read the experimental conditions table to obtain all task types and the number of trials for each type of task; An unbiased assignment of trial order is performed using a fully random algorithm; Set a constraint condition for consecutive tasks, wherein the number of consecutive occurrences of the same type of task does not exceed 2. If the generated trial sequence violates the constraints, random assignment is performed again until the constraints are satisfied.
5. The automatic control system for a low-artifact, high-synchronization EEG acquisition paradigm for brain-computer interface experiments as described in claim 1, characterized in that, In the round-trial double-layer loop structure, the experiment contains N rounds, N≥1; each round contains M trials, M≥1; the number of trials for each task type is evenly distributed in each round.
6. The automatic control system for a low-artifact, high-synchronization EEG acquisition paradigm for brain-computer interface experiments as described in claim 1, characterized in that, In the multi-sensor synchronous docking module, the process of encoding experimental events into tag codes and synchronously transmitting them to the EEG acquisition device via a parallel or serial communication interface includes: Pre-configure unique marker codes for various key experimental events; When an event occurs, the tag code is sent to the EEG acquisition device via a parallel port or a serial port; Synchronously record the global clock timestamp of the transmission time and store it in the experimental data structure; The port is reset after a delay after the transmission is completed.
7. An automatic control method for a low-artifact, high-synchronization EEG acquisition paradigm for brain-computer interface experiments, characterized in that, Includes the following steps: S1. Start the experimental running framework, complete the experimental window initialization, global clock calibration and device manager initialization, and establish a unified experimental running environment; S2. Receive experimental parameter inputs through a graphical user interface and perform format verification to generate a standardized experimental configuration structure; S3. Adopt a modular assembly method to divide the complete experimental process into multiple functional stages, and establish the experimental process structure through a stage component loading algorithm. S4. Start round-robin scheduling. Each round contains multiple trials. At the beginning of each round, a trial sequence is generated by a fully random trial allocation algorithm with continuous task constraints. S5. Execute each trial task in sequence according to the generated trial sequence. In each trial, the routine-level clock-locking algorithm is used to control the timing of stimulus presentation. The timing control process of a single trial is to present the gaze cross, auditory cues and directional clues in the preset timing sequence, enter the motor imagery stage, and execute the rest control without visual stimulation after the motor imagery stage ends. S6. During the stimulus presentation process, experimental event marking is performed synchronously. The global clock timestamps of key experimental events are recorded through a unified timestamp recording algorithm and stored uniformly through the data management module. S7. Synchronously execute the EEG acquisition synchronization process, and send the experimental event code to the EEG acquisition device through the event-sampling synchronization algorithm to achieve time synchronization between the stimulus event and the EEG sampling. S8. After a single trial is completed, the trial data is written into the experimental data structure. S9. After all trials in the current round have been completed, enter the inter-round rest phase, using rest control without visual stimulation, and wait for the continue instruction before entering the next round; S10. After all rounds of iteration are completed, save the experimental data as a standardized format file and perform data integrity verification. S11. Release experimental system resources and complete the experiment.
8. The automatic control method for a low-artifact, high-synchronization EEG acquisition paradigm for brain-computer interface experiments as described in claim 7, characterized in that, The timing control flow for a single trial is as follows: At 0 seconds, start the global clock, display the gaze crosshair and play an auditory cue tone; At 2 seconds, the gaze cross is turned off, and directional cues are presented; At 3 seconds, directional cues continue to appear, entering the preparation stage for motion visualization; At 3.25 seconds, the motion visualization phase begins; At 6 seconds, the directional cues are turned off, and the system enters a pure black, visually stimulating rest phase. At 7.5 seconds, a single trial ends.
9. The automatic control method for a low-artifact, high-synchronization EEG acquisition paradigm for brain-computer interface experiments as described in claim 7, characterized in that, The event-sampling synchronization algorithm includes: Assign a unique identifier to each of the events: gaze cross presentation, auditory cue playback, directional cue presentation, start of motor imagery, end of motor imagery, and end of trial. When each event occurs, the corresponding tag code is sent to the EEG acquisition device via a parallel or serial communication interface; Synchronously record the global clock timestamps of each event occurrence.
10. The automatic control method for a low-artifact, high-synchronization EEG acquisition paradigm for brain-computer interface experiments as described in claim 7, characterized in that, The fully randomized trial allocation algorithm with continuous task constraints includes: Import the experimental conditions table containing all task types and corresponding number of trials; The initial trial sequence is generated using a fully randomized algorithm; If there are cases in the detection sequence where the same type of task appears more than twice consecutively, then regenerate the trial sequence until the constraints are met.
11. The automatic control method for a low-artifact, high-synchronization EEG acquisition paradigm for brain-computer interface experiments as described in claim 7, characterized in that, The experimental parameters include subject ID, experimental session ID, and experimental version information; The standardized format files include CSV format files, Pickle format files, and log files.
