Real-time electroencephalogram phase locking closed-loop stimulation method and system

By combining causal phase estimation and artifact isolation techniques with robust baseline gating and three-point crossing criteria, the triggering instability of EEG phase-specific stimulation in complex environments has been solved, achieving a highly accurate and safe EEG stimulation method.

CN121129285APending Publication Date: 2025-12-16XIEHE HOSPITAL ATTACHED TO TONGJI MEDICAL COLLEGE HUAZHONG SCI & TECH UNIV
View PDF 0 Cites 3 Cited by

Patent Information

Application Number
CN202511327633.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-09-17
Publication Date
2025-12-16

AI Technical Summary

Technical Problem

Existing EEG phase-specific stimulation methods suffer from insufficient trigger stability and timing accuracy under complex electromagnetic environments and non-stationary signal conditions, and are susceptible to phase deviation, sensitivity to artifact processing, misjudgment of crossing, and amplitude drift.

Method used

We employ causal phase estimation and sampling to maintain artifact isolation, combined with robust baseline gating and three-point crossing determination, and introduce a schedulable triggering mechanism that includes prediction, quantization, consistency confirmation, and near-cutoff backoff to ensure phase continuity and triggering accuracy.

Benefits of technology

It significantly improves target phase hit rate and induced response accuracy in complex electromagnetic environments, while taking into account stimulus safety and operational assessability, and reducing the risk of false triggering.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121129285A_ABST
    Figure CN121129285A_ABST
Patent Text Reader

Abstract

The invention provides a real-time electroencephalogram phase locking closed-loop stimulation method and system, and relates to the technical field of electroencephalogram signal processing. The method comprises the following steps: firstly, acquiring a cortex electrical activity signal and establishing a baseline statistic, then carrying out causal band-pass filtering on the signal, and carrying out sampling and holding substitution in a stimulation artifact window; setting an amplitude and a duration threshold based on the baseline, and performing phase judgment after conditions are met; estimating an average period through zero crossing and calculating an instantaneous phase; outputting a trigger instruction when the three-point crossing judgment is established; and outputting stimulation under the constraint of charge balance and a safety limit value, setting a minimum prohibition period and link abnormity suppression, and recording a hit rate and a response rate for quality evaluation. According to the method, through causal phase estimation, artifact isolation and a schedulable triggering mechanism, the high hit rate of non-stationary signal phase locking stimulation is achieved, and the safety and effectiveness of a stimulation system are ensured.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of electroencephalogram (EEG) signal processing technology, and in particular to a real-time EEG phase-locked closed-loop stimulation method and system. Background Technology

[0002] Phase-specific EEG stimulation aims to apply electro / magnetic stimulation when a target EEG rhythm (such as the beta band) is in a predetermined phase, in order to improve the stability and plasticity of the evoked response. A common procedure typically includes: bandpass filtering of the raw EEG, estimating the instantaneous phase using Hilbert transform or frequency-locked loop (PLL) methods, setting a single phase threshold for triggering, and using techniques such as template cancellation or window removal to reduce the influence of stimulation artifacts. In engineering implementation, fixed thresholds and fixed sampling rates are often used, and hit rates and response rates are statistically evaluated in saline baths and clinical settings. While this approach can achieve phase triggering under conscious conditions, trigger stability and timing accuracy remain constrained by multiple factors in complex electromagnetic environments and under non-stationary signal conditions.

[0003] Related research is gradually shifting from a basic framework primarily based on offline parameter setting and online execution to one emphasizing low-latency causal processing and greater robustness to stimulus artifacts. Specifically, this manifests in: a preference for causally feasible algorithms with lower sensitivity to group delays in phase estimation; a focus on protecting phase continuity and tolerating morphological drift in artifact handling; the introduction of adaptive designs for discrete sampling conditions in trigger determination to reduce out-of-bounds errors caused by single-point determinations; and an emphasis on pre-triggered gating using stability indicators such as amplitude and duration in operational quality control to reduce false triggers caused by non-stationary segments. The overall trend is towards engineering feasibility and robustness, while also considering real-time performance, security, and cross-scenario consistency.

[0004] Existing solutions generally suffer from the following shortcomings: First, when relying on non-causal operations (such as full-window Hilbert) or higher-order filtering, additional group delays and boundary effects can easily introduce phase deviations. Second, artifact handling methods using template cancellation or fixed windows are sensitive to artifact morphology drift and may disrupt the temporal continuity of the phase trajectory, thus affecting the trigger timing. Third, single-point threshold triggering is prone to misjudgment and sampling jitter amplification under discrete sampling conditions, leading to actual landing point phase deviation from the target. Fourth, fixed amplitude thresholds and threshold settings without continuity constraints are difficult to cope with the slow drift of rhythmic amplitude and background noise, easily resulting in insufficient steady-state response or over-triggering. These factors collectively restrict the phase hit rate and response accuracy under complex electromagnetic and non-stationary conditions, necessitating the introduction of more robust engineering methods at the data processing and trigger determination levels. Summary of the Invention

[0005] To overcome the shortcomings of existing technologies, the present invention aims to provide a real-time EEG phase-locked closed-loop stimulation method and system. This method ensures phase continuity by using causal phase estimation and sampling to maintain artifact isolation, uses robust baseline gating to screen for non-stationary perturbations, uses three-point crossing judgment to suppress discrete sampling ambiguity, and introduces a schedulable triggering mechanism with prediction, quantification, consistency confirmation, and near-cutoff backoff. Under the conditions of complex electromagnetic environment and timing uncertainty, this invention significantly improves the target phase hit rate and evoked response accuracy, while taking into account stimulation safety and operational assessability.

[0006] To achieve the above objectives, the present invention provides the following solution: A real-time EEG phase-locked closed-loop stimulation method, characterized in that it includes: S1. Acquire at least one channel of cortical electrical activity signal and record the timestamp. Obtain the data for the first time period in a non-stimulated state to form baseline statistics. The target frequency band is one of the preset neural oscillation frequency bands. S2. Perform causal bandpass filtering on the cortical electrical activity signal, and when detecting stimulus artifacts, sample and hold the sample in the corresponding time window, replacing it with the most recent valid sample before the stimulus. S3. Set the amplitude and duration thresholds according to the baseline statistics. Phase determination can only proceed when the thresholds are continuously met. S4. Estimate the average period based on the zero-crossing count, and calculate the instantaneous phase using the time interval between the current moment and the most recent zero-crossing. S5. If S3 is true, take the phases of the three most recent sampling points, determine the crossing relationship between the sampling point phases and the preset trigger phase, and output a trigger command if the relationship is true. S6. Output stimulus under the constraints of charge balance and parameters not exceeding safety limits, set minimum prohibition period, and suppress triggering when communication link is abnormal; record hit rate and response rate during operation for quality assessment.

[0007] Preferably, step S1 includes: Align the clocks of the acquisition end and the stimulation control end, set the sampling rate and quantization bit width, and put the stimulation channel in the disabled state; Place the electrodes according to the preset channel list and detect the contact impedance. If the contact impedance meets the threshold condition, the data acquisition is allowed. Raw cortical electrical activity signals were continuously collected for a long period of time in a non-stimulated state, and a monotonically increasing timestamp was written for each sampling point to form a data stream with a one-to-one correspondence between timestamps and samples. The center frequency and bandwidth of the target frequency band are registered as parameters according to the clinical settings. The raw cortical electrical activity signals were subjected to quality screening to remove segments with saturation, abrupt changes, or high-amplitude electromyographic interference, and the remaining segments were retained as the data for the first time period. Baseline statistics are calculated based on the data from the first time period. The baseline statistics include at least the mean amplitude, variance, peak-to-peak value, and absolute deviation of the median of the target frequency band components.

[0008] Preferably, step S2 includes: The lower and upper limits of the target frequency band are set according to the parameters, and a causal bandpass filter is generated according to the preset order and stability conditions; the causal bandpass filter is a linear time-invariant causal system. After starting the acquisition, the preheating section is output first, and the filtered output within the preheating section is discarded to eliminate the initial boundary effect; The cortical electrical activity signal is bandpass filtered point by point in chronological order, while preserving the internal state of the filter. At the timestamp of each trigger command issued by the stimulus control terminal, a fixed duration from the timestamp is defined as the artifact candidate time window; when there is no timestamp, the start and end times of artifacts are detected and the time window is determined by the joint criteria of amplitude threshold and slope threshold. Sampling and holding is performed within the artifact time window, replacing all sample points within the artifact time window with the most recent valid sample that meets the amplitude and slope thresholds before the artifact start point; When several consecutive samples are simultaneously below the amplitude and slope thresholds, the artifact is determined to end, and the true filtered output is restored in a smooth transition mode within a finite length transition period after the artifact ends. The output is the time-domain waveform after bandpass filtering and sample-and-hold processing, and the replaced samples are marked.

[0009] Preferably, step S3 includes: The envelope sequence of the time-domain waveform of the bandpass output in step S2 is calculated in a causal manner and kept updated online. The formula is as follows: ;in, The causal envelope sequence of the target frequency band components; Discrete samples of the time-domain waveform output in step S2; For the reason and The uniquely determined first-order exponential smoothing coefficient; For the registered center frequency; Sampling rate; This represents the absolute value operation; The baseline envelope sequence is obtained based on the first time period data generated in step S1. And calculate the amplitude threshold, the formula is: ;in, Amplitude threshold; The median; The median of the absolute deviation centered at the median; the constant 1.4826 is used to convert MAD to the order of standard deviation under the Gaussian approximation; The baseline envelope sequence obtained under non-stimulatory conditions; Set a duration threshold corresponding to the number of samples, and use a normalized persistence criterion for gating, as shown in the formula: ;in, This is a normalized, persistent indicator; The number of samples corresponding to the duration threshold is approximately equal to the number of sample points in one central period; To round up; The operation is guaranteed to be in the most recent The envelope of each sample is not lower than the threshold; For stability gating, This is an indicator function that takes the value 1 if the condition is met and 0 otherwise. If and only if When the phase estimation and subsequent trigger determination in step S4 are entered; when The entry phase determination remains prohibited until the gating determination condition is met again.

[0010] Preferably, step S4 includes: With discrete samples The rising zero crossover is the event that satisfies A zero-crossing is determined at a certain time, and the crossover position and time with subsampling precision are obtained using linear interpolation, as shown in the formula: ;in, For the first The real-valued sample index corresponding to the second zero crossover; The time of its occurrence; It is a discrete time index and the most recent sample point that satisfies the above condition; and These are the bandpass signal values ​​of the current and previous sampling points, respectively, i.e., discrete samples; Based on the sample index sequence of the most recent rising zero crossovers The average period is estimated, and jitter is suppressed using the median of multiple differences, as shown in the formula: ;in, Estimate the average period for the current moment; The index of the most recently rising zero-crossing real numbers is sorted in ascending order of time; the denominators 1, 2, and 3 are used to reduce the multi-order differences to periodic units. At the current moment The instantaneous phase can be calculated relative to the interval of the most recent rising zero crossover using the following formula: ;in, Estimate the instantaneous phase at the current moment and limit it to ; Not exceeding The most recent rising zero cross index; The sample index is represented by `mod`, which is the modulo operation. Within the sampling interval where no new rising zero-crossing is detected, phase recursion is used to maintain causal continuity, as shown in the formula: ;in, This is an estimate of the instantaneous phase of the previous sampling point.

[0011] Preferably, step S5 includes: If step S3 is true, the estimated value of the instantaneous phase output in step S4 is called, and the phase sequence of the three most recent sampling points is cached. The phase sequence is subjected to monotonicity and continuity checks. If a phase jump exceeds a preset foldback limit, the phase sequence is re-foldback corrected. In the sequence after back-correction, it is detected whether the phase of the third-to-last sampling point and the current sampling point are located on both sides of the preset trigger phase. If so, it is determined that a crossing relationship is formed. Output a stimulus trigger command and record the trigger time and corresponding phase if and only if the cross-relationship determination is true.

[0012] Preferably, a stimulus trigger command is output and the trigger time and corresponding phase are recorded if and only if the traversal relationship determination is valid, including: At the current sampling time Based on the results obtained in step S4 and Calculate instantaneous angular frequency And predict the next time the preset trigger phase is reached. Shortest forward arrival time ;in, The predicted trigger time; This is the current sampling time; Preset trigger phase; For the estimation of the corresponding angular frequency; right The instruction schedule timing is obtained by quantization based on timing resolution, using the following formula: ; Only when And if the gating condition in step S3 is still met, a pre-arm triggering command is generated; wherein, Temporal quantization resolution for the stimulus control interface; Minimum schedulable lead time; The three parameters are preset system parameters, representing the maximum schedulable lead time. Recalculate on a rolling basis at each subsequent sampling point. and When the quantized plan is in continuous preset integer time... If the sampling point remains unchanged and step S3 is still valid, the pre-arm trigger command is upgraded to the stimulus trigger command; if the planned time changes or step S3 fails, the pre-arm trigger command is revoked. when Furthermore, once the cross-relationship has been determined to be established, the immediate stimulus trigger command is generated directly to avoid missing the target phase window; According to the stimulus triggering command The stimulation control interface triggers a stimulation pulse and records the current time and corresponding... As pairing information.

[0013] Preferably, step S6 includes: After receiving the stimulus trigger command generated in step S5, the stimulus parameters to be output are checked according to the preset safety limit. The process continues only if the stimulus parameters do not exceed the safety limit. The charge of the two phases of the biphasic pulse is calculated, and the amplitude or pulse width of the second phase is adjusted so that the net charge of a single pulse is zero or does not exceed the preset tolerance to satisfy the charge balance. Before output, check the minimum prohibition period timer status. If the timer has not expired, refuse to execute the stimulus trigger command. When the timer expires, allow output and reset the minimum prohibition period timer. Before output, the arrival jitter, packet loss and timestamp monotonicity of the communication link are detected. If any indicator is abnormal, the trigger suppression flag is set and the execution of the stimulus triggering command is suspended. The flag is automatically cleared after the link recovers and the threshold is continuously met. For each successfully output stimulus, record the trigger time and the instantaneous phase corresponding to step S4, and calculate and archive the phase hit rate and response rate according to the rolling time window.

[0014] Preferably, the stimulation parameters include: amplitude, pulse width, pulse rate, number of pulses, duty cycle, and train duration.

[0015] A real-time EEG phase-locked closed-loop stimulation system includes: The signal acquisition and baseline establishment unit is used to acquire at least one channel of cortical electrical activity signal and record the timestamp. It acquires data for the first time period in a non-stimulated state to form baseline statistics. The target frequency band is one of the preset neural oscillation frequency bands. The causal filtering and artifact isolation unit is used to perform causal bandpass filtering on the cortical electrical activity signal, and to sample and maintain the corresponding time window when detecting stimulus artifacts, replacing them with the most recent valid sample before the stimulus. A stability gating unit is used to set amplitude and duration thresholds according to the baseline statistics, and the phase determination can only be entered when the thresholds are continuously met. The phase estimation unit is used to estimate the average period based on the zero-crossing count and to calculate the instantaneous phase with the time interval of the current moment relative to the most recent zero-crossing. The crossing determination and trigger generation unit is used to take the phases of the three most recent sampling points under the condition that the stability gating unit is established, determine the crossing relationship between the phases of the sampling points and the preset trigger phase, and output a trigger command when the relationship is established. The stimulus output and quality assessment unit is used to output stimuli under the constraints of charge balance and parameters not exceeding safety limits, set a minimum prohibition period, and suppress triggering when the communication link is abnormal; during operation, the hit rate and response rate are recorded for quality assessment.

[0016] According to specific embodiments provided by the present invention, the present invention discloses the following technical effects: (i) Compared with schemes that rely on non-causal Hilbert or high-order linear phase filtering, this invention adopts a phase acquisition link based on causal bandpass and zero-crossing average period estimation, avoiding the accumulation of group delay and boundary effects caused by full-window operation, and reducing phase deviation caused by algorithm delay drift; the time-domain robust processing is completed before phase gating, which fundamentally improves the real-time performance and accuracy of trigger moment positioning.

[0017] (ii) To address the problem that the morphology of stimulus artifacts drifts with changes in electrode impedance, environmental electromagnetic field and output channel, this invention implements sampling and holding substitution within the artifact window. The nearest valid sample before the artifact starting point stably crosses the artifact interval, maintaining the temporal continuity and monotonicity of the phase trajectory, reducing the sensitivity of template cancellation or fixed window to artifact non-steadiness, and significantly suppressing the chain effect of "misjudgment of zero crossover - wrong triggering".

[0018] (III) To address the issue of threshold solidification and distortion under non-stationary backgrounds, this invention implements stability gating using baseline statistics and duration thresholds. It preferably constructs amplitude thresholds using anti-abnormal statistics such as median and MAD, and uses continuous satisfaction of a central period as a necessary condition for entering phase determination. This can effectively eliminate short-term electromyography / motor artifacts and rhythm transients, and improve the reliability of phase determination and the quality of triggering.

[0019] (iv) To address the problem that "single-point threshold crossing triggering" caused by discrete sampling is easily amplified by quantization error and sampling jitter, this invention adopts a three-point crossing triggering judgment combined with back-correction. It performs consistency checks and cross-relationship identification on the phase sequence of the three most recent sampling points, which reduces misjudgment caused by phase back-correction and narrows the effective landing point deviation of the target phase window without increasing the algorithm delay.

[0020] (V) Addressing the core challenge of "unclear future time crossing relationships", this invention proposes a schedulable triggering process of prediction reservation - time quantization - consistency confirmation - near deadline rollback: Based on the current phase and average period, the shortest arrival time is predicted, quantized into an executable time according to the interface resolution, and the planned time is required to remain consistent within continuous sampling before execution triggering; if the deadline is approaching and a crossing has already occurred, the execution is immediately rolled back, thereby taking into account both missed triggering and advanced triggering risk control when communication and timing jitter exist.

[0021] (vi) In terms of safety and maintainability, this invention ensures the output safety boundary through charge balance verification, minimum prohibition period gating and link anomaly suppression, and supports the quality assessment and alarm during operation with rolling statistical traces of phase hit rate and response rate. It does not limit specific hardware and communication methods, and is easy to deploy and migrate across devices in saline pool simulation and clinical scenarios. Attached Figure Description

[0022] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0023] Figure 1 A flowchart of the method provided in an embodiment of the present invention; Figure 2 This is a flowchart of causal filtering and artifact isolation provided in an embodiment of the present invention; Figure 3 This is a schematic diagram of the system structure provided in an embodiment of the present invention. Detailed Implementation

[0024] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0025] The purpose of this invention is to provide a real-time EEG phase-locked closed-loop stimulation method and system that is more accurate, more stable, and simultaneously improves safety and assessability.

[0026] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.

[0027] Figure 1The method flowchart provided in the embodiments of the present invention is as follows: Figure 1 As shown, the present invention provides a real-time EEG phase-locked closed-loop stimulation method, characterized in that it includes: S1. Acquire at least one channel of cortical electrical activity signal and record the timestamp. Obtain the data for the first time period in a non-stimulated state to form baseline statistics. The target frequency band is one of the preset neural oscillation frequency bands. S2. Perform causal bandpass filtering on the cortical electrical activity signal, and sample and hold the corresponding time window when detecting stimulus artifacts, replacing them with the most recent valid sample before the stimulus. S3. Set the amplitude and duration thresholds according to the baseline statistics. Phase determination can only proceed when the thresholds are met continuously. S4. Estimate the average period based on the zero-crossing count, and calculate the instantaneous phase using the time interval between the current moment and the most recent zero-crossing. S5. Under the condition that S3 is true, take the phase of the three most recent sampling points, determine the crossing relationship between the sampling point phase and the preset trigger phase, and output the trigger command when it is true. S6. Output stimulus under the constraints of charge balance and parameters not exceeding safety limits, set minimum prohibition period, and suppress triggering when communication link is abnormal; record hit rate and response rate during operation for quality assessment.

[0028] In a preferred embodiment of the present invention, the acquisition and baseline establishment in step S1 can be implemented as follows: First, the system clocks of the acquisition end and the stimulation control end are aligned to ensure the timing consistency of data sampling and stimulation triggering. Simultaneously, the sampling rate and quantization bit width are set as acquisition parameters, and the stimulation channel is placed in a disabled state during the baseline acquisition phase. Subsequently, electrodes are arranged according to a preset channel list, and the electrode contact impedance is detected in real time. Formal acquisition is only allowed when the contact impedance is lower than a preset threshold condition to avoid data distortion caused by poor contact. During the acquisition phase, cortical electrical activity signals for a preset duration are continuously recorded in a non-stimulated state, and a monotonically increasing timestamp is written to each sampling point, thereby forming a data stream with a one-to-one correspondence between timestamps and sampling points.

[0029] Furthermore, after data acquisition, the center frequency and bandwidth of the target frequency band are registered as parameters based on clinical or experimental settings, providing a basis for subsequent filtering and phase calculation. During quality screening of the raw signal, amplitude thresholds, slope thresholds, and statistical discrimination methods are used to remove segments exhibiting saturation, abrupt changes, or high-amplitude electromyographic interference, retaining the remaining segments that meet stability conditions as the first time-segment data. Subsequently, statistical calculations are performed on the first time-segment data to obtain baseline statistics. These baseline statistics include at least the mean amplitude, variance, peak-to-peak value, and median absolute deviation of the target frequency band components. The results will serve as a benchmark reference for stability gating and amplitude determination in subsequent steps.

[0030] The "baseline statistics" described in this specification refer to a set of statistical characteristic parameters calculated from the cortical electrical activity signal of the target frequency band under conditions without stimuli or interference. Their function is to characterize the average level and fluctuation range of the signal in this frequency band under resting conditions, serving as a reference benchmark for setting amplitude thresholds and determining duration in subsequent steps. These statistics include at least: mean amplitude, reflecting the average energy level of the signal; variance, measuring signal volatility; peak-to-peak value, characterizing the difference in extreme values ​​of the signal; and absolute deviation of the median, providing a robust measure of dispersion in the presence of outliers. Introducing baseline statistics ensures that stability gating and phase determination are individualized and robust.

[0031] In a preferred embodiment of the present invention, such as Figure 2 As shown, step S2 first sets the lower and upper frequency limits based on the target frequency band parameters registered in step S1, and constructs a causal bandpass filter by combining the preset order and stability conditions. This filter is a linear time-invariant causal system. After the acquisition starts, the filter first outputs a preheating data segment, discarding the filtered output of the preheating segment to eliminate the initial boundary effect. Subsequently, the cortical electrical activity signal is subjected to causal bandpass filtering point by point according to the sampling order, while continuously retaining the internal state of the filter, thereby ensuring real-time performance and output continuity.

[0032] Furthermore, during the detection of stimulus artifacts, this invention defines candidate time windows for artifacts using timestamps issued by the trigger control terminal. When no trigger timestamp is detected, a joint criterion of amplitude and slope thresholds is used to automatically identify the start and end times of the artifact. For the identified artifact time windows, this invention employs a sample-and-hold strategy, replacing all sample points within the time window with the nearest valid sample that simultaneously meets the amplitude and slope threshold conditions before the artifact's starting point. This avoids phase trajectory distortion caused by abnormal artifact amplitudes.

[0033] In the artifact termination determination, the artifact is considered to have ended when the amplitude and slope of several consecutive samples are both below a threshold. A smooth transition strategy is then implemented within a finite-length transition period after the artifact ends, gradually restoring the output from the sample-and-hold result to the true filtered result, thus reducing phase discontinuities caused by signal abrupt changes. Finally, the output is the time-domain waveform after causal bandpass filtering and sample-and-hold processing, with the replaced samples marked. This marking information is used for subsequent phase estimation and quality assessment.

[0034] The "artifact candidate time window" described in this specification refers to the time period after stimulus output where current interference or hardware coupling noise may exist. This time window can be directly defined by the timestamp of the trigger control terminal, or it can be identified by jointly detecting amplitude and slope thresholds on the filtered signal. Within this time window, the real neural signal is often masked by high-amplitude, rapidly changing artifacts. Directly using this for phase estimation can lead to serious misjudgments. Therefore, a sample-and-hold substitution strategy is adopted to extend the effective samples before the artifact initiation point to cover this time window, in order to maintain the continuity and stability of the phase trajectory.

[0035] In one embodiment, the sampling rate It can be set to 1000Hz, with a quantization bit width of 16 bits; target frequency band center frequency. The frequency is set to 20Hz with a bandwidth of 10Hz, resulting in a lower limit frequency of 15Hz and an upper limit frequency of 25Hz. The artifact candidate time window can be set from 2ms to 5ms. The amplitude threshold can be set to the baseline mean plus twice the median absolute deviation (MAD), corresponding to a value of approximately 30μV. The slope threshold can be set to the baseline mean slope plus 1.5 times the standard deviation, corresponding to a value of approximately 50μV / ms. The minimum forbid period is set to 50ms to avoid repeated triggering. The transition segment length is set to 10 sampling points to ensure smooth recovery. These values ​​are within the commonly used range in this field and can ensure the effectiveness and safety of filtering, artifact isolation, and trigger determination.

[0036] Furthermore, in step S2 of this embodiment, whether to use Hampshire filtering as an isolated noise suppression step before bandpass filtering is designed to be optional: existing practices often use Hampshire filtering to replace isolated abnormal samples with local medians in order to avoid introducing artifacts due to ringing (often described as "Gabor / Gibbs-like oscillations") generated by narrowband causal bandpass to pulse-type signals; however, under the target data form of this embodiment, scalp EEG usually has fewer "isolated noise" in the engineering sense, and even if there are high-amplitude spikes in invasive recordings, they are mostly physiological events or transients related to stimuli. To ensure real-time performance and causality, this embodiment prioritizes a processing chain of "artifact candidate time window detection, sample-and-hold substitution, and amplitude / slope threshold discrimination" to stabilize the phase trajectory. The Hampshire filter is set to be activated only when leaving the artifact window and the pre-detection shows sparse isolated anomalies. The window width and threshold are taken within the normal engineering range and do not introduce significant additional group delay. If no obvious isolated noise is found in the pre-detection, the Hampshire step is omitted and the process directly proceeds to causal bandpass and subsequent phase estimation, thereby avoiding unnecessary phase shifts and delays, while maintaining the simplicity and robustness of the processing flow of this invention.

[0037] In this embodiment, the stability gating in S3 is implemented as follows: The time-domain waveform output in step S2 is smoothed sample by sample using a causal method to obtain an envelope sequence that updates online over time. The smoothing employs exponential recursion, utilizing only the data from the current and previous moments to meet real-time requirements. Subsequently, the first time-segment data acquired in step S1 under non-stimulated conditions is called, and its envelope is calculated using the same smoothing process as described above, serving as the baseline envelope. Based on this, the median of the baseline envelope and the median of the absolute deviation calculated with the median as the center are used to construct a robust statistic, from which the amplitude threshold is obtained. To avoid misjudgment caused by short-term fluctuations, a sliding window of equal length to the center period of the target frequency band is used as the duration threshold. Within this window, the envelope is checked point by point to ensure that it is not lower than the amplitude threshold. If all conditions are met, a gating pass flag is output, allowing entry into phase estimation and subsequent triggering judgment. If the condition is not met at any moment, the gating remains in the prohibited state and is re-judged at the next sampling point. The above process relies only on the arrived data for calculation, ensuring causality and low latency characteristics.

[0038] "Causal envelope sequence" refers to the amplitude representation updated over time obtained by exponentially smoothing the instantaneous amplitude without using future samples, used to track the strength changes of the target frequency band components; "median absolute deviation" refers to calculating the absolute value of the difference between each sample and the median, centered on the sample median, and taking the median of its distribution, which has robustness insensitive to outliers; "normalized persistence criterion" refers to evaluating the degree of persistence by the ratio of the minimum envelope value within the sliding window to the threshold, and it is determined to be stable when the ratio is not less than one and lasts for one central period.

[0039] In this embodiment, the sampling rate and quantization bit width are obtained by setting the acquisition parameters in step S1; the center frequency and bandwidth of the target frequency band are given by the registration parameters in step S1; the time constant of envelope smoothing is determined by the center frequency and sampling rate, and automatically adjusted as both change, without the need for repeated manual parameter tuning; the amplitude threshold is derived from the statistics of the baseline envelope, and is obtained by superimposing a correction term proportional to its dispersion on the median level of the baseline, where the scaling factor can be 1.4826; the duration threshold is set according to the center period of the target frequency band, taking a window length equal to that period and rounded up to the integer sampling point; the gate flag is a Boolean value, indicating whether entry into phase estimation and subsequent triggering determination is allowed. For example, to improve robustness, the scaling factor can be adjusted from 1.4826 to 2.0, corresponding to stricter entry conditions.

[0040] Specifically, in this embodiment, the sampling rate is 1000Hz, and the baseline acquisition duration is 30s; the target frequency band center frequency is 20Hz, and the bandwidth is 10Hz, resulting in a center period of approximately 50ms and a window length of approximately 50 sampling points; the envelope smoothing coefficient calculated based on this center frequency and sampling rate is approximately 0.88; in a subject's baseline data, the median envelope is approximately 15μV, and the absolute deviation based on the median is approximately 7μV, so the amplitude threshold can be taken as the median plus 1.4826 times this deviation, approximately 25.4μV; point-by-point judgment is performed using this threshold and a window of 50 sampling points. When the envelope value within the window is not lower than the threshold, the gate is set to pass and enters phase estimation and trigger judgment. The above values ​​can be adaptively updated according to differences in subjects and devices under the same process to ensure direct reproducibility.

[0041] In this embodiment, the phase estimation process is initiated after the gating is established in step S3: First, using discrete samples of the time-domain waveform output in step S2 as input, rising zero-crossing events are detected. When a sign change occurs where "the previous sampling point is not greater than zero and the current sampling point is greater than zero," a rising zero-crossing is determined to have occurred. To obtain the crossover position and time with sub-sampling precision, this embodiment performs linear interpolation between these two adjacent samples according to the amplitude ratio to obtain the crossover position between the two sampling points and its corresponding timestamp, and writes this position into the zero-crossing sequence buffer. This process relies only on current and past data, satisfying the causal real-time requirement.

[0042] Subsequently, the average period is estimated based on the position sequence of the most recent rising zero crosses. This embodiment calculates the intervals between adjacent zero crosses, the interval between one zero cross, and the interval between two zero crosses separately. The median of these three types of intervals is then converted to time and used as the estimated average period for the current moment to suppress biases caused by sampling jitter or local anomalies. The estimate is updated on a rolling basis each time a new zero cross is added, while the buffer length is capped to ensure stable computation under limited memory and low latency conditions.

[0043] After obtaining the average period, the instantaneous phase is calculated based on the proportion of the elapsed time of the current moment relative to the most recent rising zero crossover. To unify the units of measurement and facilitate subsequent triggering decisions, this embodiment limits the phase to a range of one cycle and performs a reversal when crossing a full cycle, so that the phase remains continuously changing within a predetermined interval. When the sampling point is located within the artifact-marked interval, the phase calculation follows the time trajectory of the most recent valid sample before the artifact, avoiding abrupt changes caused by artifacts.

[0044] Within the sampling interval where no new rising zero-crossing is detected, this embodiment employs sample-by-sample phase recursion: the phase of the previous time step is linearly advanced using the phase increment of each sample corresponding to the average period, and a reversal is performed after the advancement, thus maintaining causal continuity and avoiding "phase stagnation" while waiting for the next zero-crossing. When a new rising zero-crossing is confirmed, the phase recursion benchmark is reset and the average period estimate is refreshed, using this crossover as the new starting point.

[0045] Specifically, "rising zero crossing" refers to a zero-crossing event where the discrete waveform changes from not greater than zero to greater than zero between two adjacent sampling points; "subsampling precision" refers to obtaining the decimal position and time accurate to the sampling interval by interpolating the amplitude ratio between adjacent sampling points; "phase foldback" refers to mapping the phase back to a predetermined one-cycle interval when the phase accumulates for more than one cycle or drops below zero, thereby maintaining the bounded continuous representation of the phase. The sampling rate and timestamp used in this embodiment come from the acquisition configuration in step S1; the discrete waveform used for phase estimation comes from the output of step S2; linear interpolation can be completed using only the amplitude and time information of the two adjacent samples that trigger the zero crossing; the average period estimation defaults to using the time values ​​corresponding to the three most recent intervals (adjacent, one-interval, two-interval) and takes the median to enhance robustness; the minimum length of the zero crossing buffer is not less than four events, preferably six to nine events; the phase foldback interval can be a standard one-cycle interval; samples within the artifact-marked interval do not participate in the zero crossing determination and average period update to ensure the continuity and reliability of the phase trajectory. As an example, the sampling rate in this embodiment is 1000Hz; the three most recent time intervals detected are approximately 49ms, 50ms, and 51ms, respectively, with a median of 50ms, which is used as the current average period; the current sampling point is approximately 12ms away from the most recent rising zero crossover, so the instantaneous phase ratio is approximately 24%, which is equivalent to an angle of approximately 86.4° (returning to 0°~360°), or approximately 1.51 radians; if no new zero crossover arrives and the average period remains at 50ms, the phase increment for each sampling point is approximately 7.2°, and when the cumulative increment exceeds 360°, it returns to the interval according to the return rule and continues to recursively calculate.

[0046] In this embodiment, the trigger determination begins after the stability gating condition in step S3 is met. First, the instantaneous phase estimate output in step S4 is called, and the phase sequence of the three most recent sampling points is cached for subsequent determination of crossing relationships. This cache is kept updated in a first-in-first-out manner to ensure that it always contains phase data from the third-to-last sampling point to the current sampling point. Subsequently, monotonicity and continuity checks are performed on the cached phase sequence. This embodiment sets a foldback limit; when a phase jump in the sequence exceeds this limit, it is determined that a phase foldback boundary has been crossed. At this time, through foldback correction, the phase is mapped back to the specified interval, so that the entire phase sequence remains continuously increasing or decreasing, avoiding false crossings caused by phase foldback. In the phase sequence after foldback correction, this embodiment detects whether the phase of the third-to-last sampling point and the current sampling point are located on opposite sides of the preset trigger phase. If the detection result shows that the phase crosses from one side to the other, it is determined that the trigger condition is met. This determination uses a three-point sequence instead of a single-point threshold, which can significantly reduce erroneous triggers caused by sampling jitter and instantaneous errors. This embodiment generates a stimulus trigger command and transmits it to the stimulus control interface only when the cross-relationship determination is valid. Simultaneously, the system records the trigger time and the corresponding instantaneous phase, forming paired data for operational quality assessment and subsequent statistical analysis. This method ensures a dual correspondence between the trigger time and phase conditions, improving the accuracy and traceability of the stimulus.

[0047] Exemplary "crossing relationship" refers to a situation where, under the condition of a preset trigger phase as a boundary, two sampling points in a phase sequence are located on opposite sides of the trigger phase, i.e., crossing from a phase less than the trigger phase to a phase greater than the trigger phase, or vice versa. This relationship is used to determine whether the target phase point has been truly crossed, thereby triggering stimulus output. In a specific embodiment, the sampling rate is 1000Hz, the buffered phase sequence length is fixed at 3 sampling points, the foldback limit is set to 270°, i.e., foldback correction is triggered when the phase jump exceeds 270°, and the preset trigger phase is 90° as the boundary for crossing determination; in a typical operation, if the phase of the third-to-last sampling point is 70° and the phase of the current sampling point is 110°, then the crossing relationship is determined to be valid and a trigger command is generated; the trigger command is assigned a trigger timestamp of 125.0ms in the system, and the instantaneous phase of 92° corresponding to the trigger moment is recorded simultaneously.

[0048] Furthermore, in this embodiment, when verifying the monotonicity and continuity of the instantaneous phase output in step S4 after step S3 is established, a "zero-crossing priority, dynamic tolerance, and selective foldback" processing method is adopted for the case of "rapidly rising from 13Hz to 30Hz causing a phase abrupt change": Specifically, when the phase jump amplitude is detected to exceed the preset foldback limit, it is first checked whether a rising zero-crossing event or an equivalent one-cycle foldback indication is marked between two adjacent sampling points in step S4; if such a mark exists, it indicates that the phase abrupt change is caused by a real zero crossing, and is regarded as a natural foldback, without correction (i.e., samples that cross 0° / 360° are retained according to their original values); only when there is no zero-crossing mark and the measured jump deviates significantly from the dynamic tolerance increment estimated based on the current average period is it determined to be a pseudo-abrupt change and foldback correction is performed (by adding or subtracting a whole cycle to shift the phase back to a continuous trajectory). Therefore, under rapid frequency transitions such as 13-30 Hz, legitimate integer hops are fully preserved, while non-physical large jumps caused by high-frequency remnants, artifacts, or link jitter are corrected. This avoids miscorrecting "treating real zero hops as abnormal" and prevents abnormal jumps from undermining the reliability of the three-point hop determination.

[0049] In this embodiment, the schedulable triggering process is initiated after the stability gating in step S3 is satisfied and the crossing relationship in step S5 has been determined by the three-point phase sequence judgment logic. First, at the current sampling time, the instantaneous phase and average period output in step S4 are read, the instantaneous angular frequency is calculated, and the shortest forward arrival time to the preset trigger phase is predicted accordingly to obtain the predicted triggering time. This prediction relies only on the current and previous samples, satisfies causal real-time performance, and serves as the time reference for subsequent scheduling. Second, the predicted triggering time is forward-quantized according to the time quantization resolution of the stimulus control interface to obtain the instruction planning time. Only when the planned time falls within the schedulable time window after the current sampling time (defined by the minimum and maximum schedulable lead) and the gating condition in step S3 is still satisfied, a pre-arm triggering order is generated and the planned time and the instantaneous phase at the time of generation are registered, awaiting subsequent consistency confirmation; if the above conditions are not met, a pre-arm triggering order is not generated and the process is re-evaluated at the next sampling point. Secondly, the predicted trigger time and the instruction plan time are recalculated at each subsequent sampling point. When the quantized plan time remains unchanged within a consecutive preset integer number of sampling points, and the gating condition in step S3 remains true, this embodiment elevates the pre-arm trigger command to an execution stimulus trigger command and locks the plan time. If the plan time changes or the gating condition fails, the pre-arm trigger command is revoked and the relevant registration is cleared to avoid issuing stimuli under uncertain conditions. Finally, for scenarios nearing the deadline, when the interval between the predicted trigger time and the current sampling time is less than the time quantization resolution, and the crossing relationship has been determined to be true, this embodiment directly generates an immediate stimulus trigger command to avoid missing the target phase window. Subsequently, according to the stimulus trigger command, the stimulus pulse is triggered at the planned time through the stimulus control interface, and the trigger timestamp and the corresponding instantaneous phase are recorded simultaneously as pairing information for runtime quality assessment and traceability.

[0050] As an example, the "pre-arm trigger command" refers to the draft trigger command to be executed generated after the prediction, quantization and gating checks have all passed. It includes the planned time and status flags and is used to enter the consistency confirmation phase. The "time quantization resolution" refers to the minimum time step that the stimulus control interface can identify and schedule, which is used to fall the predicted continuous time into the executable discrete time grid. The "minimum schedulable lead" and the "maximum schedulable lead" together define the time window that can be scheduled for execution from the current time. The lower limit is used to ensure that the interface and hardware are ready, and the upper limit is used to avoid the drift risk caused by queuing too early.

[0051] Unlike traditional approaches that rely on instantaneous triggering of a single crossing or are based solely on fixed thresholds, this embodiment transforms uncertain future crossings into verifiable and revocable planned events through a time-series schedulable mechanism of "prediction-quantization-consistency confirmation-near-cutoff backoff." On the one hand, it uses time quantization and window constraints to align continuous time to hardware-executable moments; on the other hand, it uses a consistency maintenance criterion of continuous multi-sampling to suppress false triggers caused by jitter and link latency, and provides an instant backoff channel in critical situations to reduce missed triggers. This combination effectively solves the dual uncertainties of "whether a crossing will occur in the future" and "when it can be reliably executed" without adding extra non-causal operations and complex weights, significantly improving phase hit and execution stability.

[0052] In one run, the time quantization resolution was set to 0.10ms, the minimum schedulable lead time was 1.0ms, the maximum schedulable lead time was 20ms, and the consistency confirmation window took three consecutive sampling points. At a certain moment, the shortest positive arrival time to the trigger phase was predicted to be 6.37ms after the current time, which was quantized to a planned time of 6.40ms. The planned times for the subsequent three sampling points were recalculated sequentially as 6.40ms, 6.40ms, and 6.40ms, and the stability gating was always valid. The system promoted the pre-arm trigger command to a stimulus trigger command. If the planned time of 6.50ms appeared at the second sampling point, the pre-arm trigger command was immediately canceled and the system waited for the next prediction. In the near-cutoff case, if the difference between the predicted arrival time and the current time was 0.08ms (less than 0.10ms) and the crossing relationship was valid, an immediate trigger was generated and issued at 213.60ms. At the same time, the phase corresponding to this moment was recorded as 88° for quality assessment.

[0053] Specifically, in this embodiment, after receiving the stimulus trigger command generated in step S5, step S6 first performs a safety check on the stimulus parameters to be output. The stimulus parameters include amplitude, pulse width, pulse rate, number of pulses, duty cycle, and train duration. Before output, this embodiment compares each parameter to a preset safety limit; if any parameter exceeds the limit, execution is rejected or automatically pruned according to the principle of not exceeding the upper limit. Simultaneously, the charge of the two phases of the biphasic pulse is calculated, and without exceeding the safety limit, the amplitude or pulse width of the second phase is adjusted first to ensure that the net charge of a single pulse is zero or does not exceed the preset tolerance. When charge balance cannot be achieved within the tolerance, this embodiment terminates the output and records the reason for traceability. Subsequently, this embodiment checks the minimum prohibition period timing status to avoid high-frequency repetitive stimulation: if the minimum prohibition period has not yet been reached, the current trigger command is rejected and the timing is maintained; when the timing reaches the limit, output is allowed, and the minimum prohibition period timer is immediately reset after the actual stimulus is emitted, so that subsequent triggers must again meet the prohibition period constraint. The above gating does not change the content of the trigger command, but only determines whether execution is permitted at the current moment. Before output, this embodiment performs anomaly detection on the communication link, with detection indicators including at least arrival jitter, packet loss rate, and timestamp monotonicity. If any indicator exceeds a preset threshold, a trigger suppression flag is set and the execution of the current trigger command is suspended. When the link recovers within a continuous observation window and consistently meets the threshold, the trigger suppression flag is automatically cleared and processing of subsequent trigger commands resumes. This embodiment records suppressed triggers for operational diagnostics and parameter tuning. For each successfully output stimulus, this embodiment simultaneously records the trigger timestamp, the instantaneous phase corresponding to step S4, and a snapshot of the stimulus parameters effective at that time, and calculates the phase hit rate and response rate according to a rolling time window before archiving. If any indicator remains below the threshold, this embodiment can trigger a derating strategy or a safety shutdown strategy and output alarm information for operation and maintenance. The above statistics and alarms do not change the aforementioned gating logic and are only used for operational quality assessment and safety assurance.

[0054] Specifically, "charge balance" refers to the fact that the charge amounts of the two phases of a biphasic pulse cancel each other out within a single pulse time window, resulting in a net charge of zero or within the tolerance range, which is used to reduce tissue polarization and electrochemical risks; "minimum prohibition period timer" refers to a timer that starts after a stimulus is emitted, and is not allowed to be triggered again before the timer expires, which is used to control the minimum pulse interval; "trigger inhibition flag" refers to a status flag that temporarily prohibits the execution of trigger commands due to communication link abnormalities, and is automatically cleared after the link is restored.

[0055] The minimum prohibition period in this embodiment is set for the following engineering reasons: Step S2 uses a causal bandpass filter with a half-amplitude cutoff frequency of 13–30Hz. Although it has a relatively steep roll-off, a small amount of high-frequency components may still remain when interference or artifact trails are present. This causes the bandpass output to cross zero multiple times within a single β cycle, and the interval between adjacent zero crossings may be less than 1 / 30s (approximately 33.3ms). At this time, the zero crossing point can no longer stably correspond to the 0° / 180° phase of the β rhythm, which can easily lead to misjudgment of the crossing relationship. Therefore, this embodiment introduces a minimum prohibition period control in step S6 and sets it to 60ms, which is significantly greater than the period of 33.3ms corresponding to the upper limit frequency of 30Hz, thereby completing the engineering "de-jittering": only one trigger is allowed within the same target phase window, and repeated triggering is automatically suppressed when false zero crossings caused by high-frequency residues or link jitter occur. This setting also takes into account charge safety, stimulus interval, and the stability of rolling statistical evaluation, and works in conjunction with the duration threshold in step S3 and the causal phase estimation in step S4.

[0056] In a demonstrative scenario, during a single operation, the safety limits are set as follows: amplitude not exceeding 1.5mA, single-phase pulse width not exceeding 200μs, pulse rate not exceeding 50Hz, single train duration not exceeding 1.0s, and duty cycle not exceeding 50%; charge balance tolerance is set to not exceed 0.05μC; minimum prohibition period is set to 60ms; link arrival jitter threshold is set to 0.5ms, packet loss rate threshold is set to 0.5%, and timestamp monotonicity tolerance is set to a maximum of one consecutive reversal; in a certain trigger, the proposed output parameters are amplitude 1.2mA, single-phase pulse width 180μs, single pulse, pulse rate 20Hz, duty cycle 20%, and train duration 0.5s. After adjusting the second phase pulse width to 184μs through charge balance verification, the tolerance is met; when the minimum prohibition period timer arrives and the link detection is normal, this embodiment allows the output and recording of the trigger timestamp 327.480ms and the corresponding instantaneous phase 92°, which are included in the rolling 60s window for statistical phase hit rate and response rate.

[0057] In addition, in this embodiment, after each output, the trigger timestamp, corresponding instantaneous phase, and snapshot of the current stimulus parameters are recorded, and the phase hit rate and stimulus response rate are calculated in a rolling 60s window. When the hit rate is continuously lower than 70% or the response rate is lower than 60%, a derating process is performed (amplitude reduced by 20%, train duration shortened to 0.5s). If the standard is still not met after three consecutive windows, a safety shutdown is initiated. Before output, safety limits are checked item by item: amplitude ≤ 1.5mA, single-phase pulse width ≤ 200μs, pulse rate ≤ 50Hz, single train duration ≤ 1.0s, duty cycle ≤ 50%, and two-phase net charge ≤ 0.05μC. At the same time, the minimum prohibition period of 60ms and the link status are checked (arrival jitter ≤ 0.5ms, packet loss rate ≤ 0.5%, and timestamp monotonicity tolerance not exceeding 1 time). If any limit is exceeded or the link is abnormal, the suppression is set and output is rejected; it is automatically released after stabilization. The specific timestamps and phase records of the aforementioned exemplary operation have been given in the examples above in this specification, and will not be repeated in this embodiment.

[0058] To ensure the stimulus truly falls on the target phase (e.g., π), this embodiment adds a runtime phase alignment calibration (optional) after trigger generation in step S5, the process of which is as follows. First, at the decision moment when "phase = π is seen on the PC side," this embodiment calculates the sum of the processing delay and the visibility delay from the electrode to the decision based on the instantaneous frequency estimation in step S4 and the timestamp of the unified clock, and converts it into a phase deviation Δπ; simultaneously, the execution delay from the decision to trigger issuance to the actual start of the stimulus is measured and converted into a phase deviation δπ. Thus, when this embodiment observes a phase of π on the PC side and sends a trigger, the stimulus start phase at the patient end can be represented as π + Δπ + δπ; both types of delays are maintained using online rolling averages and are not updated temporarily in the event of link anomalies, artifact marking, or gating failures.

[0059] Secondly, in this embodiment, after each effective stimulus, the artifact isolation output of step S2 and the causal phase estimation of step S4 are used to calculate the stimulus initiation phase estimate at the timestamp of the "actual stimulus start time". Then, a foldback is performed according to the error = (stimulus initiation phase estimate - target phase) (limited to -π to π), and the trigger phase parameter is updated accordingly: new trigger phase = old trigger phase - error (also folded back to 0 to 2π). This update takes effect directly in the next three-point crossover determination and schedulable trigger (prediction, quantization, consistency confirmation, near-cutoff backoff), thereby offsetting the systematic offset caused by observation / execution delay into the trigger phase parameter.

[0060] Finally, to avoid overcalibration, this embodiment only performs phase updates when the gating in step S3 is successful, the link status is normal, and the suppression flag is not triggered; an upper limit is set for the single error (e.g., not exceeding 30°), and the error is adjusted according to the upper limit when it exceeds the upper limit; when the absolute value of the error is less than the threshold (e.g., 10°) for several consecutive times (e.g., 3 times), the update is paused to stabilize the parameters. Relying on the aforementioned "sampling-preserving artifact isolation," "causal zero-crossing phase estimation," and "schedulable triggering" mechanisms, the calibration process does not introduce non-causal calculations and redundant weights, and achieves target phase alignment only with a single additive compensation.

[0061] Corresponding to the above methods, such as Figure 3 As shown, this embodiment also provides a real-time EEG phase-locked closed-loop stimulation system, including: The signal acquisition and baseline establishment unit is used to acquire at least one channel of cortical electrical activity signal and record the timestamp. It acquires data for the first time period in a non-stimulated state to form baseline statistics. The target frequency band is one of the preset neural oscillation frequency bands. The causal filtering and artifact isolation unit is used to perform causal bandpass filtering on the cortical electrical activity signal, and to sample and maintain the corresponding time window when detecting stimulus artifacts, replacing them with the most recent valid sample before the stimulus. A stability gating unit is used to set amplitude and duration thresholds according to the baseline statistics, and the phase determination can only be entered when the thresholds are continuously met. The phase estimation unit is used to estimate the average period based on the zero-crossing count and to calculate the instantaneous phase with the time interval of the current moment relative to the most recent zero-crossing. The crossing determination and trigger generation unit is used to take the phases of the three most recent sampling points under the condition that the stability gating unit is established, determine the crossing relationship between the phases of the sampling points and the preset trigger phase, and output a trigger command when the relationship is established. The stimulus output and quality assessment unit is used to output stimuli under the constraints of charge balance and parameters not exceeding safety limits, set a minimum prohibition period, and suppress triggering when the communication link is abnormal; during operation, the hit rate and response rate are recorded for quality assessment.

[0062] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the systems disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the descriptions are relatively simple; relevant parts can be referred to the method section.

[0063] This document uses specific examples to illustrate the principles and implementation methods of the present invention. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of the present invention. Furthermore, those skilled in the art will recognize that, based on the ideas of the present invention, there will be changes in the specific implementation methods and application scope. Therefore, the content of this specification should not be construed as a limitation of the present invention.

Claims

1. A real-time EEG phase-locked closed-loop stimulation method, characterized in that, include: S1. Collect at least one channel of cortical electrical activity signal and record the timestamp. Obtain the data of the first time period in the non-stimulated state to form baseline statistics. The target frequency band is one of the preset neural oscillation frequency bands; S2. Perform causal bandpass filtering on the cortical electrical activity signal, and when detecting stimulus artifacts, sample and hold the sample in the corresponding time window, replacing it with the most recent valid sample before the stimulus. S3. Set the amplitude and duration thresholds according to the baseline statistics. Phase determination can only proceed when the thresholds are continuously met. S4. Estimate the average period based on the zero-crossing count, and calculate the instantaneous phase using the time interval between the current moment and the most recent zero-crossing. S5. If S3 is true, take the phases of the three most recent sampling points, determine the crossing relationship between the sampling point phases and the preset trigger phase, and output a trigger command if the relationship is true. S6. Output stimulus under the constraints of charge balance and parameters not exceeding safety limits, set minimum prohibition period, and suppress triggering when communication link is abnormal; record hit rate and response rate during operation for quality assessment.

2. The real-time EEG phase-locked closed-loop stimulation method according to claim 1, characterized in that, Step S1 includes: Align the clocks of the acquisition end and the stimulation control end, set the sampling rate and quantization bit width, and put the stimulation channel in the disabled state; Place the electrodes according to the preset channel list and detect the contact impedance. If the contact impedance meets the threshold condition, the data acquisition is allowed. Raw cortical electrical activity signals were continuously collected for a long period of time in a non-stimulated state, and a monotonically increasing timestamp was written for each sampling point to form a data stream with a one-to-one correspondence between timestamps and samples. The center frequency and bandwidth of the target frequency band are registered as parameters according to the clinical settings. The raw cortical electrical activity signals were subjected to quality screening to remove segments with saturation, abrupt changes, or high-amplitude electromyographic interference, and the remaining segments were retained as the data for the first time period. Baseline statistics are calculated based on the data from the first time period. The baseline statistics include at least the mean amplitude, variance, peak-to-peak value, and absolute deviation of the median of the target frequency band components.

3. The real-time EEG phase-locked closed-loop stimulation method according to claim 2, characterized in that, Step S2 includes: The lower and upper limits of the target frequency band are set according to the parameters, and a causal bandpass filter is generated according to the preset order and stability conditions; the causal bandpass filter is a linear time-invariant causal system. After starting the acquisition, the preheating section is output first, and the filtered output within the preheating section is discarded to eliminate the initial boundary effect; The cortical electrical activity signal is bandpass filtered point by point in chronological order, while preserving the internal state of the filter. At the timestamp of each trigger command issued by the stimulus control terminal, a fixed duration from the timestamp is defined as the artifact candidate time window; when there is no timestamp, the start and end times of artifacts are detected and the time window is determined by the joint criteria of amplitude threshold and slope threshold. Sampling and holding is performed within the artifact time window, replacing all sample points within the artifact time window with the most recent valid sample that meets the amplitude and slope thresholds before the artifact start point; When several consecutive samples are simultaneously below the amplitude and slope thresholds, the artifact is determined to end, and the true filtered output is restored in a smooth transition mode within a finite length transition period after the artifact ends. The output is the time-domain waveform after bandpass filtering and sample-and-hold processing, and the replaced samples are marked.

4. The real-time EEG phase-locked closed-loop stimulation method according to claim 3, characterized in that, Step S3 includes: The envelope sequence of the time-domain waveform of the bandpass output in step S2 is calculated in a causal manner and kept updated online. The formula is as follows: ;in, The causal envelope sequence of the target frequency band components; Discrete samples of the time-domain waveform output in step S2; For the reason and The uniquely determined first-order exponential smoothing coefficient; For the registered center frequency; Sampling rate; This represents the absolute value operation; The baseline envelope sequence is obtained based on the first time period data generated in step S1. And calculate the amplitude threshold, the formula is: ;in, Amplitude threshold; The median; The median of the absolute deviation centered at the median; the constant 1.4826 is used to convert MAD to the order of standard deviation under the Gaussian approximation; The baseline envelope sequence obtained under non-stimulatory conditions; Set a duration threshold corresponding to the number of samples, and use a normalized persistence criterion for gating, as shown in the formula: ;in, This is a normalized, persistent indicator; The number of samples corresponding to the duration threshold is approximately equal to the number of sample points in one central period; To round up; The operation is guaranteed to be in the most recent The envelope of each sample is not lower than the threshold; For stability gating, This is an indicator function that takes the value 1 if the condition is met and 0 otherwise. If and only if When the phase estimation and subsequent trigger determination in step S4 are entered; when The entry phase determination remains prohibited until the gating determination condition is met again.

5. The real-time EEG phase-locked closed-loop stimulation method according to claim 4, characterized in that, Step S4 includes: With discrete samples The rising zero crossover is the event that satisfies A zero-crossing is determined at a certain time, and the crossover position and time with subsampling precision are obtained using linear interpolation, as shown in the formula: ;in, For the first The real-valued sample index corresponding to the second zero crossover; The time of its occurrence; It is a discrete time index and the most recent sample point that satisfies the above condition; and These are the bandpass signal values ​​of the current and previous sampling points, respectively, i.e., discrete samples; Based on the sample index sequence of the most recent rising zero crossovers The average period is estimated, and jitter is suppressed using the median of multiple differences, as shown in the formula: ;in, Estimate the average period for the current moment; The index of the most recently rising zero-crossing real numbers is sorted in ascending order of time; the denominators 1, 2, and 3 are used to reduce the multi-order differences to periodic units. At the current moment The instantaneous phase can be calculated relative to the interval of the most recent rising zero crossover using the following formula: ;in, Estimate the instantaneous phase at the current moment and limit it to ; Not exceeding The most recent rising zero cross index; The sample index is represented by `mod`, which is the modulo operation. Within the sampling interval where no new rising zero-crossing is detected, phase recursion is used to maintain causal continuity, as shown in the formula: ;in, This is an estimate of the instantaneous phase of the previous sampling point.

6. The real-time EEG phase-locked closed-loop stimulation method according to claim 5, characterized in that, Step S5 includes: If step S3 is true, the estimated value of the instantaneous phase output in step S4 is called, and the phase sequence of the three most recent sampling points is cached. The phase sequence is subjected to monotonicity and continuity checks. If a phase jump exceeds a preset foldback limit, the phase sequence is re-foldback corrected. In the sequence after back-correction, it is detected whether the phase of the third-to-last sampling point and the current sampling point are located on both sides of the preset trigger phase. If so, it is determined that a crossing relationship is formed. Output a stimulus trigger command and record the trigger time and corresponding phase if and only if the cross-relationship determination is true.

7. The real-time EEG phase-locked closed-loop stimulation method according to claim 6, characterized in that, Output a stimulus trigger command and record the trigger time and corresponding phase if and only if the crossover relationship determination is valid, including: At the current sampling time Based on the results obtained in step S4 and Calculate instantaneous angular frequency And predict the next time the preset trigger phase is reached. Shortest forward arrival time ;in, The predicted trigger time; This is the current sampling time; Preset trigger phase; For the estimation of the corresponding angular frequency; right The instruction schedule timing is obtained by quantization based on timing resolution, using the following formula: ; Only when And if the gating condition in step S3 is still met, a pre-arm triggering command is generated; wherein, Temporal quantization resolution for the stimulus control interface; Minimum schedulable lead time; The three parameters are preset system parameters, representing the maximum schedulable lead time. Recalculate on a rolling basis at each subsequent sampling point. and When the quantized plan is in continuous preset integer time... If the sampling point remains unchanged and step S3 is still valid, the pre-arm trigger command is upgraded to the stimulus trigger command; if the planned time changes or step S3 fails, the pre-arm trigger command is revoked. when Furthermore, once the cross-relationship has been determined to be established, the immediate stimulus trigger command is generated directly to avoid missing the target phase window; According to the stimulus triggering command The stimulation control interface triggers a stimulation pulse and records the current time and corresponding... As pairing information.

8. The real-time EEG phase-locked closed-loop stimulation method according to claim 1, characterized in that, Step S6 includes: After receiving the stimulus trigger command generated in step S5, the stimulus parameters to be output are checked according to the preset safety limit. The process continues only if the stimulus parameters do not exceed the safety limit. The charge of the two phases of the biphasic pulse is calculated, and the amplitude or pulse width of the second phase is adjusted so that the net charge of a single pulse is zero or does not exceed the preset tolerance to satisfy the charge balance. Before output, check the minimum prohibition period timer status. If the timer has not expired, refuse to execute the stimulus trigger command. When the timer expires, allow output and reset the minimum prohibition period timer. Before output, the arrival jitter, packet loss and timestamp monotonicity of the communication link are detected. If any indicator is abnormal, the trigger suppression flag is set and the execution of the stimulus triggering command is suspended. The flag is automatically cleared after the link recovers and the threshold is continuously met. For each successfully output stimulus, record the trigger time and the instantaneous phase corresponding to step S4, and calculate and archive the phase hit rate and response rate according to the rolling time window.

9. The real-time EEG phase-locked closed-loop stimulation method according to claim 8, characterized in that, The stimulation parameters include: amplitude, pulse width, pulse rate, number of pulses, duty cycle, and train duration.

10. A real-time EEG phase-locked closed-loop stimulation system, characterized in that, include: The signal acquisition and baseline establishment unit is used to acquire at least one channel of cortical electrical activity signal and record the timestamp. It acquires data for the first time period in a non-stimulated state to form baseline statistics. The target frequency band is one of the preset neural oscillation frequency bands. The causal filtering and artifact isolation unit is used to perform causal bandpass filtering on the cortical electrical activity signal, and to sample and maintain the corresponding time window when detecting stimulus artifacts, replacing them with the most recent valid sample before the stimulus. A stability gating unit is used to set amplitude and duration thresholds according to the baseline statistics, and the phase determination can only be entered when the thresholds are continuously met. The phase estimation unit is used to estimate the average period based on the zero-crossing count and to calculate the instantaneous phase with the time interval of the current moment relative to the most recent zero-crossing. The crossing determination and trigger generation unit is used to take the phases of the three most recent sampling points under the condition that the stability gating unit is established, determine the crossing relationship between the phases of the sampling points and the preset trigger phase, and output a trigger command when the relationship is established. The stimulus output and quality assessment unit is used to output stimuli under the constraints of charge balance and parameters not exceeding safety limits, set a minimum prohibition period, and suppress triggering when the communication link is abnormal; during operation, the hit rate and response rate are recorded for quality assessment.

Citation Information

Cited By

  • Emotion intervention system and device based on reminiscence therapy

    CN121371433A

  • Phase-locked neural feedback analgesia system based on personalized multi-mode stimulation

    CN121868713A

  • Phase-sensitive amplifier performance optimization method based on double-same-difference measurement and dynamic gain

    CN122026832A