Clock synchronization method, device and equipment and computer readable storage medium

By performing phase compensation and clustering processing on the clock synchronization message data, filtering and fitting the message data to determine the frequency and phase correction amount, the problem of low clock synchronization accuracy is solved and high-precision and stable clock synchronization is achieved.

CN118677555APending Publication Date: 2024-09-20CRRC ZHUZHOU ELECTRIC LOCOMOTIVE RESEARCH INSTITUTE CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202310253465.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-03-16
Publication Date
2024-09-20

AI Technical Summary

Technical Problem

The existing technology fails to effectively improve the synchronization accuracy in clock synchronization. Especially when facing an environment with large delay jitter, the frequency pulling method causes the clock frequency to be unstable and does not consider the impact of noise, resulting in low synchronization accuracy.

Method used

By performing phase compensation on multiple cycles of historical clock synchronization message data, clustering and filtering target message data, and performing linear fitting to determine the frequency and phase correction amounts, the clock is corrected based on these correction amounts, filtering noise interference, and reducing Delay jitter.

Benefits of technology

Significantly improves the accuracy and stability of clock synchronization, reduces delay jitter, realizes adaptive capabilities under different network topologies, avoids large corrections in frequency and phase, and ensures stability in the synchronization state.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118677555A
    Figure CN118677555A
Patent Text Reader

Abstract

The invention discloses a clock synchronization method and device, equipment and a computer readable storage medium, and the method comprises the steps: carrying out the phase compensation of a time parameter contained in the obtained historical clock synchronization message data of a plurality of periods, so as to obtain initial message data; and when the obtained initial message data meets the data volume requirement, clustering the initial message data and the newly obtained message data after phase compensation to screen out target message data meeting the bottom time delay characteristic. And when the target message data meets a set convergence condition, performing linear fitting on the target message data to obtain a frequency correction amount. Determining a phase correction amount according to the target message data of the current period and the minimum transmission time delay determined based on minimum time delay iteration; and performing clock correction on the slave clock according to the frequency correction amount and the phase correction amount. Noise generated by queuing delay is filtered out, and phase correction is carried out on the basis of stable frequency, so that the precision and stability of clock synchronization are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of device communication technology, and in particular to a clock synchronization method, apparatus, device and computer-readable storage medium. Background Art

[0002] In the network, background traffic and Precise Time Protocol (PTP) messages share bandwidth resources. PTP packets will queue in the switch and wait for forwarding. The queuing time has a certain randomness, which makes the transmission delay of PTP packets in the entire path also random. This random change in delay is also called delay jitter. The jitter of transmission delay will cause very large noise interference to clock synchronization and is the main source of error in clock synchronization. If the noise is not processed, in an environment with large delay jitter, the synchronization performance between the master and slave clocks of the network will be significantly deteriorated. Clock synchronization technology is the basis of time-sensitive network (TSN) technology. Therefore, it is very important to ensure the synchronization accuracy of the clock in TSN technology.

[0003] Both the general Precise Time Protocol (gPTP) and its predecessor PTP protocol only provide the basic principles of clock synchronization. However, there is little research on synchronization accuracy at present, and the improvement points of the existing technology are mainly concentrated in the smoothing filtering part, by trying various filtering algorithms to smooth the phase difference of the slave clock. Among them, the most commonly used improvement methods are Proportional-Integral-Differential (PID) controller and Kalman filter and its variants, but due to the lack of systematic analysis of the noise model of the synchronization process, the actual effect achieved is very limited.

[0004] In the clock correction link, the existing solution uses frequency traction to achieve frequency and phase convergence and ultimately synchronization. The so-called frequency traction refers to correcting the phase by correcting the frequency according to the phase difference of the slave clock. In this process, the frequency is over-corrected, so that the frequency and phase converge at the same time and finally converge to a synchronized state. However, the disadvantages of the frequency traction method are also obvious. Unless the phase of the slave clock is completely synchronized with the master clock, the frequency of the clock cannot remain stable. Complete phase synchronization is basically impossible to achieve in a practical environment, so the frequency traction method keeps the frequency of the slave clock in a state of continuous and rapid adjustment. Since the frequency is not synchronized and stable, once the master clock is disconnected in the network, each slave clock device will lose lock in a short time and cannot maintain synchronization, making the network unable to operate normally. In fields such as train communication networks that require high security, there may even be safety hazards.

[0005] Current frequency compensation methods do not take the impact of noise into consideration, and are designed based more on experience rather than theory, resulting in low accuracy of clock synchronization.

[0006] It can be seen that how to improve the accuracy of clock synchronization is a problem that technical personnel in this field need to solve. Summary of the invention

[0007] The purpose of the embodiments of the present application is to provide a clock synchronization method, apparatus, device and computer-readable storage medium, which can improve the accuracy of clock synchronization.

[0008] In order to solve the above technical problems, an embodiment of the present application provides a clock synchronization method, including:

[0009] Performing phase compensation on time parameters contained in the acquired historical clock synchronization message data of multiple cycles to obtain initial message data;

[0010] In the case that the acquired initial message data meets the data volume requirement, clustering the initial message data and the latest acquired phase-compensated message data is performed to filter out target message data that meets the bottom delay feature;

[0011] When the target message data satisfies a set convergence condition, linear fitting is performed on the target message data to obtain a frequency correction value;

[0012] Determine a phase correction amount according to target message data of the current cycle and a minimum transmission delay determined based on minimum delay iteration;

[0013] The slave clock is corrected according to the frequency correction amount and the phase correction amount.

[0014] Optionally, clustering the initial message data and the latest acquired phase-compensated message data to filter out target message data satisfying the bottom delay feature includes:

[0015] In the case where the slave clock is in an unstable state, the initial message data is used as an initial clustering cluster, and all the phase-compensated message data currently cached are clustered according to the initial clustering cluster to screen out the first message data that meets the bottom delay characteristics; and a clustering mark is set for the first message data;

[0016] When the slave clock is in a stable state, each time new phase-compensated message data is received, the new phase-compensated message data is clustered using the message data with a clustering mark set to filter out second message data that meets the bottom delay feature; and a clustering mark is set for the second message data;

[0017] The first message data and the second message data are used as target message data.

[0018] Optionally, when the target message data satisfies a set convergence condition, performing linear fitting on the target message data to obtain a frequency correction value includes:

[0019] Determine whether the value and density of the target message data in the current period meet the set convergence conditions; wherein the convergence conditions include value distribution conditions and density conditions;

[0020] When the value and density of the target message data of the current period meet the set convergence conditions, a linear fitting is performed on the target message data to obtain a frequency correction amount.

[0021] Optionally, the determining whether the value and density of the target message data in the current period meet a set convergence condition includes:

[0022] Count the number of target message data whose values ​​in the current period are less than the set threshold;

[0023] Calculate the ratio of the number to the total number of target message data in the current cycle;

[0024] Determine whether the proportion is greater than or equal to a set ratio;

[0025] When the proportion is greater than or equal to the set ratio, determining whether the data volume of the target message data of the current cycle is greater than or equal to the data volume of the target message data of the previous cycle;

[0026] When the data volume of the target message data in the current cycle is greater than or equal to the data volume of the target message data in the previous cycle, the step of performing linear fitting on the target message data to obtain the frequency correction amount is performed.

[0027] Optionally, it also includes:

[0028] When the proportion is less than the set ratio or the data volume of the target message data of the current cycle is less than the data volume of the target message data of the previous cycle, the protocol state machine of the next cycle is controlled to enter the slave clock unstable state.

[0029] Optionally, it also includes:

[0030] When the acquired initial message data does not meet the data volume requirement, linear fitting is performed on the initial message data to obtain an initial frequency deviation;

[0031] The slave clock is frequency corrected based on the initial frequency offset.

[0032] Optionally, performing linear fitting on the target message data to obtain a frequency correction value includes:

[0033] Calculating the linear relationship between the target message data and time;

[0034] The slope corresponding to the linear relationship is used as the frequency correction amount.

[0035] Optionally, determining the phase correction amount according to the target message data of the current period and the minimum transmission delay determined based on the minimum delay iteration includes:

[0036] Performing minimum delay iteration on the transmission delay corresponding to the current cycle and the minimum transmission delays corresponding to multiple historical cycles to determine the minimum transmission delay corresponding to the current cycle;

[0037] The phase correction amount is determined according to the time parameters included in the target message data of the current cycle and the minimum transmission delay corresponding to the current cycle.

[0038] Optionally, performing phase compensation on time parameters included in the acquired historical clock synchronization message data of multiple cycles to obtain initial message data includes:

[0039] Determine the accumulated frequency correction amount corresponding to n periods according to the historical frequency correction amount contained in the historical clock synchronization message within n periods;

[0040] Determine the accumulated phase correction amount corresponding to the n periods according to the accumulated frequency correction amount, the historical phase correction amount contained in the historical clock synchronization message within the n periods, and the preset clock nominal frequency;

[0041] Phase compensation is performed on the timestamp of the slave clock received message contained in the historical clock synchronization message according to the accumulated phase correction amount to obtain initial message data.

[0042] Optionally, determining the accumulated frequency correction amount corresponding to n periods according to the historical frequency correction amount contained in the historical clock synchronization messages within n periods includes:

[0043] The frequency correction formula is called to process the historical frequency correction amount contained in the historical clock synchronization message within n cycles to determine the cumulative frequency correction amount corresponding to the n cycles; the frequency correction formula is as follows:

[0044] Δf ∑ [n] = Δf ∑ [n-1]+Δf s [n];

[0045] Where n represents the set number of cycles, Δf ∑ [n] represents the cumulative frequency correction of the previous n times, Δf ∑ [n-1] represents the cumulative frequency correction of the previous n-1 times, Δf s [n] represents the nth frequency correction amount.

[0046] Optionally, determining the accumulated phase correction amount corresponding to the n periods according to the accumulated frequency correction amount, the historical phase correction amount contained in the historical clock synchronization messages within the n periods, and a preset clock nominal frequency includes:

[0047] The phase correction formula is called to process the accumulated frequency correction amount, the historical phase correction amount contained in the historical clock synchronization message within the n cycles, and the preset clock nominal frequency to determine the accumulated phase correction amount corresponding to the n cycles; the phase correction formula is as follows:

[0048]

[0049] Among them, k represents the kth period, Indicates the cumulative phase correction amount for the previous n times, f s0 Indicates the preset clock nominal frequency, Δf ∑ [k-1] represents the cumulative frequency correction amount, Δt represents the time interval between two adjacent frequency corrections, Indicates the nth phase correction amount.

[0050] Optionally, for the storage of historical clock synchronization message data, the method includes:

[0051] A circular array queue is used to store the historical clock synchronization message data of the most recent n cycles; wherein the historical clock synchronization message data of each cycle includes the message sequence number, the local timestamp of the message sent by the master clock, the local timestamp of the message received by the slave clock, the correction time, the frequency correction amount, the phase correction amount and the clustering mark bit.

[0052] The embodiment of the present application also provides a clock synchronization device, including a compensation unit, a clustering unit, a fitting unit, a determination unit and a correction unit;

[0053] The compensation unit is used to perform phase compensation on the time parameters contained in the acquired historical clock synchronization message data of multiple cycles to obtain initial message data;

[0054] The clustering unit is used to cluster the initial message data and the latest acquired phase-compensated message data when the acquired initial message data meets the data volume requirement, so as to screen out target message data that meets the bottom delay feature;

[0055] The fitting unit is used to perform linear fitting on the target message data to obtain a frequency correction value when the target message data meets a set convergence condition;

[0056] The determining unit is used to determine the phase correction amount according to the target message data of the current period and the minimum transmission delay determined based on the minimum delay iteration;

[0057] The correction unit is used to perform clock correction on the slave clock according to the frequency correction amount and the phase correction amount.

[0058] Optionally, the clustering unit includes a first screening subunit, a first marking subunit, a second screening subunit, a second marking subunit and as a subunit;

[0059] The first screening subunit is used for, when the slave clock is in an unstable state, taking the initial message data as an initial clustering cluster, and clustering all the phase-compensated message data currently cached according to the initial clustering cluster, so as to screen out the first message data that meets the bottom delay characteristics;

[0060] The first marking subunit is used to set a clustering mark for the first message data;

[0061] The second screening subunit is used for clustering the new phase-compensated message data by using the message data with a clustering mark set each time the new phase-compensated message data is received when the slave clock is in a stable state, so as to screen out the second message data that meets the bottom delay feature;

[0062] The second marking subunit is used to set a clustering mark for the second message data;

[0063] The subunit is used to use the first message data and the second message data as target message data.

[0064] Optionally, the fitting unit includes a judging subunit and an obtaining subunit;

[0065] The judging subunit is used to judge whether the value and density of the target message data of the current period meet the set convergence conditions; wherein the convergence conditions include value distribution conditions and density conditions;

[0066] The obtaining subunit is used to perform linear fitting on the target message data in the current period when the value and density of the target message data meet the set convergence condition to obtain the frequency correction value.

[0067] Optionally, the judging subunit is used to count the number of target message data of the current period whose value is less than a set threshold;

[0068] Calculate the ratio of the number to the total number of target message data in the current cycle;

[0069] Determine whether the proportion is greater than or equal to a set ratio;

[0070] When the proportion is greater than or equal to the set ratio, determining whether the data volume of the target message data of the current cycle is greater than or equal to the data volume of the target message data of the previous cycle;

[0071] When the data volume of the target message data in the current cycle is greater than or equal to the data volume of the target message data in the previous cycle, the step of performing linear fitting on the target message data to obtain the frequency correction amount is performed.

[0072] Optionally, a control unit is also included;

[0073] The control unit is used to control the protocol state machine of the next cycle to enter an unstable state from the clock when the proportion is less than a set ratio or the data volume of the target message data of the current cycle is less than the data volume of the target message data of the previous cycle.

[0074] Optionally, it also includes an initial fitting unit and an initial correction unit;

[0075] The initial fitting unit is used to perform linear fitting on the initial message data to obtain an initial frequency deviation when the acquired initial message data does not meet the data volume requirement;

[0076] The initial correction unit is used to perform frequency correction on the slave clock based on the initial frequency deviation.

[0077] Optionally, the fitting unit includes a calculation subunit and an acting subunit;

[0078] The calculation subunit is used to calculate the linear relationship between the target message data and time;

[0079] The subunit is used to use the slope corresponding to the linear relationship as a frequency correction amount.

[0080] Optionally, the determining unit is used to perform minimum delay iteration on the transmission delay corresponding to the current cycle and the minimum transmission delays corresponding to multiple historical cycles to determine the minimum transmission delay corresponding to the current cycle;

[0081] The phase correction amount is determined according to the time parameters included in the target message data of the current cycle and the minimum transmission delay corresponding to the current cycle.

[0082] Optionally, the compensation unit includes a first determining subunit, a second determining subunit and an obtaining subunit;

[0083] The first determining subunit is used to determine the accumulated frequency correction amount corresponding to n periods according to the historical frequency correction amount contained in the historical clock synchronization message within n periods;

[0084] The second determining subunit is used to determine the accumulated phase correction amount corresponding to the n periods according to the accumulated frequency correction amount, the historical phase correction amount contained in the historical clock synchronization message within the n periods, and the preset clock nominal frequency;

[0085] The obtaining subunit is used to perform phase compensation on the timestamp of the slave clock received message contained in the historical clock synchronization message according to the accumulated phase correction amount to obtain initial message data.

[0086] Optionally, the first determination subunit is used to call a frequency correction formula to process the historical frequency correction amount contained in the historical clock synchronization message within n cycles to determine the cumulative frequency correction amount corresponding to the n cycles; the frequency correction formula is as follows:

[0087] Δf ∑ [n] = Δf ∑ [n-1]+Δf s [n];

[0088] Where n represents the set number of cycles, Δf ∑ [n] represents the cumulative frequency correction of the previous n times, Δf ∑[n-1] represents the cumulative frequency correction of the previous n-1 times, Δf s [n] represents the nth frequency correction amount.

[0089] Optionally, the second determination subunit is used to call a phase correction formula to process the cumulative frequency correction amount, the historical phase correction amount contained in the historical clock synchronization message within the n cycles, and the preset clock nominal frequency to determine the cumulative phase correction amount corresponding to the n cycles; the phase correction formula is as follows:

[0090]

[0091] Among them, k represents the kth period, Indicates the cumulative phase correction amount for the previous n times, f s0 Indicates the preset clock nominal frequency, Δf ∑ [k-1] represents the cumulative frequency correction amount, Δt represents the time interval between two adjacent frequency corrections, Indicates the nth phase correction amount.

[0092] Optionally, for the storage of historical clock synchronization message data, the device includes a storage unit;

[0093] The storage unit is used to store the historical clock synchronization message data of the most recent n periods using a circular array queue; wherein the historical clock synchronization message data of each period includes a message sequence number, a local timestamp of the message sent by the master clock, a local timestamp of the message received by the slave clock, a correction time, a frequency correction amount, a phase correction amount and a clustering mark bit.

[0094] The present application also provides an electronic device, including:

[0095] Memory for storing computer programs;

[0096] A processor is used to execute the computer program to implement the steps of the clock synchronization method as described above.

[0097] An embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned clock synchronization method are implemented.

[0098] It can be seen from the above technical scheme that the time parameters contained in the historical clock synchronization message data of multiple cycles obtained are phase compensated to obtain the initial message data; through phase compensation, the influence of the continuous correction of the clock can be offset, thereby restoring the linear relationship of the timestamp. When the initial message data obtained meets the data volume requirements, the initial message data and the latest acquired phase-compensated message data are clustered to filter out the target message data that meets the bottom delay characteristics. The target message data is the valid message data remaining after the message data removes the noise influence. When the target message data meets the set convergence conditions, the target message data can be linearly fitted to obtain the frequency correction amount. According to the target message data of the current cycle and the minimum transmission delay determined based on the minimum delay iteration, the phase correction amount is determined; the clock of the slave clock is corrected according to the frequency correction amount and the phase correction amount. In this technical scheme, by performing phase compensation and clustering processing on the message data, the noise generated by the queuing delay can be effectively filtered out, the jitter of the delay is greatly reduced, and the synchronization accuracy is improved. In addition, the implementation process does not require setting empirical parameters, which can meet the user's needs for flexible networking and can adapt to various network topologies. After the frequency is stable, there is no need to make major corrections to the frequency and phase, only slow fine-tuning is required, which ensures synchronization accuracy while improving the stability of the synchronization state. BRIEF DESCRIPTION OF THE DRAWINGS

[0099] In order to more clearly illustrate the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0100] Figure 1 A flowchart of a clock synchronization method provided in an embodiment of the present application;

[0101] Figure 2 A schematic diagram of an internal architecture of a sliding time window provided in an embodiment of the present application;

[0102] Figure 3 A flowchart of a method for screening target message data that meets the bottom delay characteristics provided in an embodiment of the present application;

[0103] Figure 4 A flowchart of a method for message data phase compensation provided in an embodiment of the present application;

[0104] Figure 5 A schematic diagram of the structure of a clock synchronization device provided in an embodiment of the present application;

[0105] Figure 6A structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0106] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0107] The terms "including" and "having" in the specification and claims of this application and the above drawings, as well as any variations thereof, are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device comprising a series of steps or units is not limited to the listed steps or units, but may include steps or units that are not listed.

[0108] In order to enable those skilled in the art to better understand the present application, the present application is further described in detail below in conjunction with the accompanying drawings and specific implementation methods.

[0109] Next, a clock synchronization method provided in an embodiment of the present application is described in detail. Figure 1 A flowchart of a clock synchronization method provided in an embodiment of the present application, the method comprising:

[0110] S101: performing phase compensation on time parameters included in multiple cycles of acquired historical clock synchronization message data to obtain initial message data.

[0111] A historical clock synchronization message is a special message sent from a master clock to a slave clock to synchronize the slave clock with the master clock. It is also called a Sync message.

[0112] In the embodiment of the present application, frequency synchronization is based on linear fitting of the timestamp of the Sync message.

[0113] The frequency synchronization method of linear fitting needs to use historical data within a certain period of time to obtain more accurate synchronization parameters. Therefore, in the embodiment of the present application, a sliding time window can be used to store nearly n Sync messages. In the specific implementation, in addition to storing the timestamp data of the Sync message, the clock correction corresponding to each reception of the Sync message is also stored. Among them, the clock correction can include frequency correction and phase correction.

[0114] Since the master clock sends Sync messages periodically, the interval between two adjacent master clock Sync messages is defined as a PTP cycle. In the embodiment of the present application, a suitable data type (such as C language) can be predefined to store the data of each cycle, including the timestamp data obtained from the Sync message and the clock correction data obtained from the feedback path.

[0115] The data types are defined as follows:

[0116] struct SyncData{

[0117] uint16_t seqId; / / Sync message sequence number, used to indicate the PTP cycle

[0118] TimeStamp t1; / / Local timestamp of the Sync message sent by the master clock

[0119] TimeStamp t2; / / Local timestamp of receiving Sync message from the clock

[0120] TimeStamp adjTime; / / corrected time

[0121] int32_t adjF; / / frequency correction

[0122] int32_t adjP; / / Phase correction

[0123] bool isValid; / / Data flag, used by clustering units to mark whether it is a valid message

[0124] };

[0125] In the SyncData structure, the data type TimeStamp is defined in the protocol standard and is used to represent a timestamp. The t1 timestamp and t2 timestamp are the times when the master and slave clocks send and receive the Sync message, respectively. adjTime is the timestamp obtained from the local clock at the correction time, adjF is the single correction value of the frequency, and adjP is the single correction value of the phase. In addition, the structure also provides a clustering flag bit isValid for marking the message filtering results in the subsequent message filtering link.

[0126] When the PTP clock is not corrected, the clock phase changes linearly over time. However, in actual work, the frequency of the PTP clock is always being corrected. In the embodiment of the present application, a phase compensation method is used to offset the influence of the clock's continuous correction, thereby restoring the linear relationship of the timestamp, and finally using the linear relationship to obtain the frequency correction of the clock.

[0127] In a specific implementation, the frequency correction and phase correction contained in the historical clock synchronization message data of multiple cycles can be analyzed based on the mathematical differential and integral relationship between the frequency and phase of the clock, so as to determine the phase to be compensated. Through the phase compensation method, a timestamp equivalent to the natural increase of the slave clock over time without correction can be obtained, and the obtained timestamp data can be called the initial message data.

[0128] S102: When the acquired initial message data meets the data volume requirement, cluster the initial message data and the latest acquired phase-compensated message data to filter out target message data that meets the bottom delay feature.

[0129] In the initial time when the master and slave clocks are not synchronized, the slave clock is in an unstable state, namely, the UNCALIBRATED state. At this time, a certain number of initial message data can be selected from the ring data queue as the initial seed data by using the minimum value sampling method every 1 second.

[0130] In an embodiment of the present application, in order to reduce noise interference, a clustering method can be used to filter out message data that is not interfered by noise or is less interfered by noise from the phase-compensated message data. This type of filtered message data can be called target message data.

[0131] When the data volume of the sample is small, the accuracy of cluster analysis is low. In order to improve the accuracy of clustering, it is necessary to ensure that the initial message data has a certain amount of data. Therefore, in the embodiment of the present application, a data volume requirement can be set for the initial message data. When the acquired initial message data meets the data volume requirement, it means that the requirements of cluster analysis are met. At this time, the initial message data and the latest acquired phase-compensated message data can be clustered to screen out the target message data that meets the bottom delay characteristics.

[0132] The bottom latency feature refers to the fact that the timestamp values ​​in the message data are small and distributed more concentratedly.

[0133] Considering that the master clock sends Sync messages periodically, the message data stored in the ring data queue will change continuously. Therefore, when performing cluster analysis, the initial message data can be used as the initial clustering cluster, all the data in the ring data queue can be clustered, and the messages with the bottom delay characteristics can be screened out and marked with clustering tags. The data with clustering tags are added to the clustering cluster, so that a larger cluster can be formed.

[0134] The process of expanding the cluster by relying on a small number of seed data is the seed expansion process, which is completed in one PTP cycle. Starting from the next cycle, the protocol state machine enters the slave clock stable state, namely the SLAVE state. In the SLAVE state, the newly acquired phase-compensated message data can be clustered according to the already acquired clusters, thereby continuously improving the clusters to obtain the required target message data.

[0135] In practical applications, cluster analysis is performed only when the collected initial message data meets the data volume requirement. However, in the initial stage, the acquired initial message data may not meet the data volume requirement. In this case, linear fitting can be performed on the initial message data to obtain the initial frequency deviation; the frequency of the slave clock can be corrected based on the initial frequency deviation.

[0136] S103: When the target message data meets the set convergence condition, linear fitting is performed on the target message data to obtain a frequency correction value.

[0137] The convergence condition can be regarded as a re-verification of whether the target message data meets the bottom delay characteristics. Under normal conditions, the target message data obtained after cluster analysis should meet the convergence condition. However, under abnormal conditions, due to problems with the message data, the target message data obtained after cluster analysis will not meet the convergence condition.

[0138] The convergence condition may include the determination of the value and density of the target message data.

[0139] In the embodiment of the present application, it can be determined whether the value and density of the target message data of the current period meet the set convergence condition; wherein the convergence condition includes the value distribution condition and the density condition. When the value and density of the target message data of the current period meet the set convergence condition, the target message data is linearly fitted to obtain the frequency correction amount.

[0140] The value distribution condition may include a determination of the proportion of target message data with a smaller value in the entire target message data. In a specific implementation, the number of target message data of the current cycle whose value is less than a set threshold may be counted; the proportion of the number to the total number of target message data of the current cycle may be calculated. It is determined whether the proportion is greater than or equal to the set ratio.

[0141] As the cycle continues to iterate, target message data that meets the bottom latency characteristics will be continuously added to the clustering cluster. In order to ensure the availability of data in the clustering cluster, message data with a longer time can be deleted from the clustering cluster. Under normal circumstances, as the clustering effect continues to improve, the amount of target message data contained in the clustering cluster of the current cycle should be greater than or equal to the amount of target message data in the previous cycle.

[0142] Combined with the judgment of the proportion, in a specific implementation, when the proportion is greater than or equal to the set ratio, it can be further judged whether the data volume of the target message data of the current cycle is greater than or equal to the data volume of the target message data of the previous cycle.

[0143] When the data volume of the target message data in the current cycle is greater than or equal to the data volume of the target message data in the previous cycle, it indicates that the clustering is normal. At this time, a step of performing linear fitting on the target message data to obtain a frequency correction amount can be performed.

[0144] Regarding the determination of the frequency correction amount, in a specific implementation, the linear relationship between the target message data and time may be calculated; and the slope corresponding to the linear relationship may be used as the frequency correction amount.

[0145] The linear relationship can be determined by least squares fitting.

[0146] By performing linear fitting on the denoised target message data, the precise value of the clock deviation can be obtained, so that the determined frequency correction amount is the minimum variance unbiased estimator.

[0147] In an embodiment of the present application, when the proportion is less than the set ratio or the data volume of the target message data in the current cycle is less than the data volume of the target message data in the previous cycle, it indicates that an abnormality has occurred in the clustering. At this time, the clock correction may not be performed on the slave clock, but the protocol state machine of the next cycle may be controlled to enter an unstable state of the slave clock, and return to S102 to re-acquire the message data for clustering analysis.

[0148] S104: Determine a phase correction amount according to target message data of the current period and a minimum transmission delay determined based on the minimum delay iteration.

[0149] In the embodiment of the present application, the minimum delay iteration can be performed on the transmission delay corresponding to the current cycle and the minimum transmission delay corresponding to multiple historical cycles to determine the minimum transmission delay corresponding to the current cycle. The phase correction amount is determined based on the time parameters included in the target message data of the current cycle and the minimum transmission delay corresponding to the current cycle.

[0150] In the specific implementation, the following formula can be called to perform the minimum delay iteration of the transmission delay:

[0151] D min [n]=min{D[n],D min [n-1]};

[0152] Among them, D min [n] represents the minimum transmission delay measured in the first n cycles, D[n] represents the transmission delay measured in the nth cycle, and Dmin [n-1] indicates the minimum transmission delay measured in the first n-1 cycles.

[0153] The measurement of transmission delay can be obtained based on the end-to-end delay measurement mechanism in the traditional way, which will not be discussed in detail here.

[0154] When the Sync message of the current period has the bottom delay characteristic, its transmission delay is close to the minimum transmission delay, so the formula The phase correction of the clock can be calculated.

[0155] After the phase correction amount is determined, a smoothing filter process may be performed on the phase correction amount to improve the stability of the phase adjustment and avoid drastic phase changes.

[0156] S105: Correct the slave clock according to the frequency correction amount and the phase correction amount.

[0157] In practical applications, the slave clock is corrected according to the frequency correction amount and the phase correction amount, so that the synchronization accuracy of the master and slave clocks can be stabilized to the sub-microsecond level.

[0158] It can be seen from the above technical scheme that the time parameters contained in the historical clock synchronization message data of multiple cycles obtained are phase compensated to obtain the initial message data; through phase compensation, the influence of the continuous correction of the clock can be offset, thereby restoring the linear relationship of the timestamp. When the initial message data obtained meets the data volume requirements, the initial message data and the latest acquired phase-compensated message data are clustered to filter out the target message data that meets the bottom delay characteristics. The target message data is the valid message data remaining after the message data removes the noise influence. When the target message data meets the set convergence conditions, the target message data can be linearly fitted to obtain the frequency correction amount. According to the target message data of the current cycle and the minimum transmission delay determined based on the minimum delay iteration, the phase correction amount is determined; the clock of the slave clock is corrected according to the frequency correction amount and the phase correction amount. In this technical scheme, by performing phase compensation and clustering processing on the message data, the noise generated by the queuing delay can be effectively filtered out, the jitter of the delay is greatly reduced, and the synchronization accuracy is improved. In addition, the implementation process does not require setting empirical parameters, which can meet the user's needs for flexible networking and can adapt to various network topologies. After the frequency is stable, there is no need to make major corrections to the frequency and phase, only slow fine-tuning is required, which ensures synchronization accuracy while improving the stability of the synchronization state.

[0159] The sliding time window can be used to store each Sync message received by the slave clock and the clock correction amount corresponding to the Sync message. The construction of the sliding time window adopts the data structure of the circular array queue. In the specific implementation, for the storage of historical clock synchronization message data, the circular array queue can be used to store the historical clock synchronization message data of the most recent n cycles; wherein, the historical clock synchronization message data of each cycle includes the message sequence number, the local timestamp of the message sent by the master clock, the local timestamp of the message received by the slave clock, the correction time, the frequency correction amount, the phase correction amount and the clustering mark bit. The value of n can be set based on actual needs.

[0160] Figure 2 A schematic diagram of the internal architecture of a sliding time window provided in an embodiment of the present application. After capturing the timestamp and clock correction, the sliding time window updates the circular array queue so that the queue stores historical clock synchronization message data of nearly n cycles.

[0161] The longer the sliding time window is, the less interference from random noise in the channel can be, and the frequency after convergence will be more stable. However, correspondingly, the cumulative error of the short stability of the crystal oscillator will be amplified, and the storage space occupied will be larger. If the window is shorter, it will be more sensitive to the frequency change of the crystal oscillator and require less storage space. However, if the window is too short, the performance will deteriorate due to insufficient data volume. Therefore, in the embodiment of the present application, the window length can be configured according to actual needs. For scenarios with higher frequency stability, the time window can be extended as much as possible, and for scenarios with higher requirements for phase synchronization accuracy, a shorter time window can be configured.

[0162] Generally speaking, the window length of the sliding time window can be set in the range of 3 to 30 seconds. In actual use, it can be set in the range of 5 to 10 seconds.

[0163] By setting a sliding time window, the storage of historical clock synchronization message data of multiple cycles can be realized. Based on the storage principle of the sliding time window, the historical clock synchronization message data can be updated, thereby ensuring that the ring data queue stores the latest historical clock synchronization message data of several cycles.

[0164] Figure 3 A flowchart of a method for screening target message data that meets the bottom delay feature provided in an embodiment of the present application, the method comprising:

[0165] S301: When the slave clock is in an unstable state, the initial message data is used as the initial clustering cluster, and all the phase-compensated message data currently cached are clustered according to the initial clustering cluster to filter out the first message data that meets the bottom delay characteristics; and a clustering mark is set for the first message data.

[0166] Clustering is an idea in the field of machine learning, which refers to selecting data with similar characteristics and treating them as a type of data. In the embodiment of the present application, the initial message data can be used as the initial clustering cluster, all the data in the circular data queue can be clustered, and the messages with the bottom delay characteristics can be screened out, and the screened messages are marked with clustering tags and added to the clustering cluster to form a larger clustering cluster.

[0167] In order to facilitate the distinction from subsequently screened message data, the message data that meets the bottom delay feature screened out in the non-stable state may be referred to as the first message data.

[0168] After the first message data is screened, the protocol state machine enters the SLAVE state starting from the next cycle, that is, the slave clock is in a stable state.

[0169] S302: When the slave clock is in a stable state, each time new phase-compensated message data is received, the new phase-compensated message data is clustered using the message data with a clustering mark set to filter out second message data that meets the bottom delay characteristics; and a clustering mark is set for the second message data.

[0170] After entering the SLAVE state, the slave clock can perform online clustering on the message timestamp data each time it receives a Sync message. That is, it uses the existing clustering clusters in the circular data queue, that is, the message data with clustering marks, to cluster the message data of the current cycle, thereby filtering out the second message data that meets the bottom delay characteristics, and setting a clustering mark for the second message data.

[0171] S303: Use the first message data and the second message data as target message data.

[0172] In an embodiment of the present application, the first message data filtered out from the clock in an unstable state and the second message data filtered out from the clock in a stable state can be combined as the target message data.

[0173] The essence of message filtering is denoising. In the process of timestamp generation and transmission and reception, there are three types of noise that affect the accuracy of timestamps: crystal noise, queuing delay, and channel random noise. Among them, queuing delay is the main component of noise. The positive bias of queuing delay also means that unqueued messages have bottom delay characteristics. By performing bottom clustering on message data, messages with bottom delay characteristics can be screened out, greatly reducing delay jitter.

[0174] Figure 4 A flowchart of a method for message data phase compensation provided in an embodiment of the present application, the method comprising:

[0175] S401: Determine the accumulated frequency correction amount corresponding to n periods according to the historical frequency correction amount contained in the historical clock synchronization message within n periods.

[0176] In a specific implementation, the frequency correction formula can be called to process the historical frequency correction amount contained in the historical clock synchronization message within n cycles to determine the cumulative frequency correction amount corresponding to n cycles; the frequency correction formula is as follows:

[0177] Δf ∑ [n] = Δf ∑ [n-1]+Δf s [n];

[0178] Where n represents the set number of cycles, Δf ∑ [n] represents the cumulative frequency correction of the previous n times, Δf ∑ [n-1] represents the cumulative frequency correction of the previous n-1 times, Δf s [n] represents the nth frequency correction amount.

[0179] S402: Determine the accumulated phase correction amount corresponding to n periods according to the accumulated frequency correction amount, the historical phase correction amount contained in the historical clock synchronization message within n periods, and the preset clock nominal frequency.

[0180] In a specific implementation, the phase correction formula can be called to process the accumulated frequency correction amount, the historical phase correction amount contained in the historical clock synchronization message within n cycles, and the preset clock nominal frequency to determine the accumulated phase correction amount corresponding to n cycles; the phase correction formula is as follows:

[0181]

[0182] Among them, k represents the kth period, Indicates the cumulative phase correction amount for the previous n times, f s0 Indicates the preset clock nominal frequency, Δf ∑ [k-1] represents the cumulative frequency correction amount, Δt represents the time interval between two adjacent frequency corrections, Indicates the nth phase correction amount.

[0183] S403: Perform phase compensation on the timestamp of the slave clock received message contained in the historical clock synchronization message according to the accumulated phase correction amount to obtain initial message data.

[0184] In the specific implementation, the timestamp of the Sync message received from the slave clock can be subtracted from the corresponding Phase compensation can be achieved.

[0185] Through the phase compensation method, we can get the timestamp equivalent to the natural increase of the slave clock without correction. On this basis, after the message filtering and denoising, we can get the frequency deviation of the clock, that is, the frequency correction, by the linear fitting method, thus ensuring the accuracy of the frequency correction.

[0186] Figure 5 A schematic diagram of the structure of a clock synchronization device provided in an embodiment of the present application, comprising a compensation unit 51, a clustering unit 52, a fitting unit 53, a determination unit 54 and a correction unit 55;

[0187] The compensation unit 51 is used to perform phase compensation on the time parameters contained in the acquired historical clock synchronization message data of multiple cycles to obtain initial message data;

[0188] The clustering unit 52 is used to cluster the initial message data and the latest acquired phase-compensated message data when the acquired initial message data meets the data volume requirement, so as to filter out the target message data that meets the bottom delay feature;

[0189] The fitting unit 53 is used to perform linear fitting on the target message data to obtain a frequency correction value when the target message data meets a set convergence condition;

[0190] A determination unit 54, configured to determine a phase correction amount according to target message data of the current cycle and a minimum transmission delay determined based on the minimum delay iteration;

[0191] The correction unit 55 is used to perform clock correction on the slave clock according to the frequency correction amount and the phase correction amount.

[0192] Optionally, the clustering unit includes a first screening subunit, a first marking subunit, a second screening subunit, a second marking subunit, and as a subunit;

[0193] A first screening subunit is used for, when the slave clock is in an unstable state, taking the initial message data as an initial clustering cluster, and clustering all the phase-compensated message data currently cached according to the initial clustering cluster, so as to screen out the first message data that meets the bottom delay feature;

[0194] A first marking subunit, used to set a clustering mark for the first message data;

[0195] The second screening subunit is used for clustering the new phase-compensated message data by using the message data with a clustering mark set each time the new phase-compensated message data is received when the slave clock is in a stable state, so as to screen out the second message data that meets the bottom delay feature;

[0196] A second marking subunit, used for setting a clustering mark for the second message data;

[0197] As a subunit, it is used to take the first message data and the second message data as target message data.

[0198] Optionally, the fitting unit includes a judging subunit and an obtaining subunit;

[0199] A judgment subunit, used to judge whether the value and density of the target message data of the current period meet the set convergence conditions; wherein the convergence conditions include value distribution conditions and density conditions;

[0200] The obtaining subunit is used to perform linear fitting on the target message data to obtain the frequency correction value when the value and density of the target message data in the current period meet the set convergence conditions.

[0201] Optionally, the judging subunit is used to count the number of target message data of the current cycle whose value is less than a set threshold;

[0202] The ratio of the number of calculations to the total number of target message data in the current cycle;

[0203] Determine whether the proportion is greater than or equal to the set ratio;

[0204] When the proportion is greater than or equal to the set ratio, it is determined whether the data volume of the target message data in the current cycle is greater than or equal to the data volume of the target message data in the previous cycle;

[0205] When the data volume of the target message data in the current cycle is greater than or equal to the data volume of the target message data in the previous cycle, a step of performing linear fitting on the target message data to obtain a frequency correction amount is performed.

[0206] Optionally, a control unit is also included;

[0207] The control unit is used to control the protocol state machine of the next cycle to enter the unstable state of the slave clock when the proportion is less than the set ratio or the data volume of the target message data of the current cycle is less than the data volume of the target message data of the previous cycle.

[0208] Optionally, it also includes an initial fitting unit and an initial correction unit;

[0209] An initial fitting unit, used to perform linear fitting on the initial message data to obtain an initial frequency deviation when the acquired initial message data does not meet the data volume requirement;

[0210] The initial correction unit is used to perform frequency correction on the slave clock based on the initial frequency deviation.

[0211] Optionally, the fitting unit includes a calculation subunit and an acting subunit;

[0212] A calculation subunit, used for calculating the linear relationship between target message data and time;

[0213] As a subunit, it is used to use the slope corresponding to the linear relationship as the frequency correction amount.

[0214] Optionally, the determination unit is used to perform minimum delay iteration on the transmission delay corresponding to the current cycle and the minimum transmission delays corresponding to multiple historical cycles to determine the minimum transmission delay corresponding to the current cycle;

[0215] The phase correction amount is determined based on the time parameters contained in the target message data of the current cycle and the minimum transmission delay corresponding to the current cycle.

[0216] Optionally, the compensation unit includes a first determining subunit, a second determining subunit and an obtaining subunit;

[0217] The first determination subunit is used to determine the accumulated frequency correction amount corresponding to n periods according to the historical frequency correction amount contained in the historical clock synchronization message within n periods;

[0218] The second determination subunit is used to determine the accumulated phase correction amount corresponding to n cycles according to the accumulated frequency correction amount, the historical phase correction amount contained in the historical clock synchronization message within n cycles and the preset clock nominal frequency;

[0219] The obtaining subunit is used to perform phase compensation on the timestamp of the slave clock receiving message contained in the historical clock synchronization message according to the accumulated phase correction amount to obtain the initial message data.

[0220] Optionally, the first determination subunit is used to call a frequency correction formula to process the historical frequency correction amount contained in the historical clock synchronization message within n cycles to determine the cumulative frequency correction amount corresponding to the n cycles; the frequency correction formula is as follows:

[0221] Δf ∑ [n] = Δf ∑ [n-1]+Δf s [n];

[0222] Where n represents the set number of cycles, Δf ∑ [n] represents the cumulative frequency correction of the previous n times, Δf ∑ [n-1] represents the cumulative frequency correction of the previous n-1 times, Δf s [n] represents the nth frequency correction amount.

[0223] Optionally, the second determination subunit is used to call the phase correction formula to process the cumulative frequency correction amount, the historical phase correction amount contained in the historical clock synchronization message within n cycles, and the preset clock nominal frequency to determine the cumulative phase correction amount corresponding to the n cycles; the phase correction formula is as follows:

[0224]

[0225] Among them, k represents the kth period, Indicates the cumulative phase correction amount for the previous n times, f s0 Indicates the preset clock nominal frequency, Δf ∑ [k-1] represents the cumulative frequency correction amount, Δt represents the time interval between two adjacent frequency corrections, Indicates the nth phase correction amount.

[0226] Optionally, for the storage of historical clock synchronization message data, the device includes a storage unit;

[0227] A storage unit is used to store the historical clock synchronization message data of the most recent n periods using a circular array queue; wherein the historical clock synchronization message data of each period includes a message sequence number, a local timestamp of the message sent by the master clock, a local timestamp of the message received by the slave clock, a correction time, a frequency correction amount, a phase correction amount and a clustering mark bit.

[0228] Figure 5 The description of the features in the corresponding embodiments can be found in Figures 1 to 4 The relevant descriptions of the corresponding embodiments will not be repeated here one by one.

[0229] It can be seen from the above technical scheme that the time parameters contained in the historical clock synchronization message data of multiple cycles obtained are phase compensated to obtain the initial message data; through phase compensation, the influence of the continuous correction of the clock can be offset, thereby restoring the linear relationship of the timestamp. When the initial message data obtained meets the data volume requirements, the initial message data and the latest acquired phase-compensated message data are clustered to filter out the target message data that meets the bottom delay characteristics. The target message data is the valid message data remaining after the message data removes the noise influence. When the target message data meets the set convergence conditions, the target message data can be linearly fitted to obtain the frequency correction amount. According to the target message data of the current cycle and the minimum transmission delay determined based on the minimum delay iteration, the phase correction amount is determined; the clock of the slave clock is corrected according to the frequency correction amount and the phase correction amount. In this technical scheme, by performing phase compensation and clustering processing on the message data, the noise generated by the queuing delay can be effectively filtered out, the jitter of the delay is greatly reduced, and the synchronization accuracy is improved. In addition, the implementation process does not require setting empirical parameters, which can meet the user's needs for flexible networking and can adapt to various network topologies. After the frequency is stable, there is no need to make major corrections to the frequency and phase, only slow fine-tuning is required, which ensures synchronization accuracy while improving the stability of the synchronization state.

[0230] Figure 6 A structural diagram of an electronic device provided in an embodiment of the present application, such as Figure 6 As shown, the electronic device includes: a memory 20 for storing a computer program;

[0231] The processor 21 is used to implement the steps of the clock synchronization method in the above embodiment when executing a computer program.

[0232] The electronic device provided in this embodiment may include but is not limited to a smart phone, a tablet computer, a laptop computer or a desktop computer.

[0233] Among them, the processor 21 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 21 can be implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). The processor 21 may also include a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 21 may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 21 may also include an AI (Artificial Intelligence) processor, which is used to process computing operations related to machine learning.

[0234] The memory 20 may include one or more computer-readable storage media, which may be non-transitory. The memory 20 may also include a high-speed random access memory, and a non-volatile memory, such as one or more disk storage devices, flash memory storage devices. In this embodiment, the memory 20 is at least used to store the following computer program 201, wherein, after the computer program is loaded and executed by the processor 21, the relevant steps of the clock synchronization method disclosed in any of the aforementioned embodiments can be implemented. In addition, the resources stored in the memory 20 may also include an operating system 202 and data 203, etc., and the storage method may be temporary storage or permanent storage. Among them, the operating system 202 may include Windows, Unix, Linux, etc. Data 203 may include, but is not limited to, historical clock synchronization message data, etc.

[0235] In some embodiments, the electronic device may further include a display screen 22 , an input / output interface 23 , a communication interface 24 , a power source 25 , and a communication bus 26 .

[0236] Those skilled in the art will understand that Figure 6 The structure shown in the figure does not constitute a limitation on the electronic device, and may include more or fewer components than shown in the figure.

[0237] It is understandable that if the clock synchronization method in the above embodiment is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium to execute all or part of the steps of each embodiment method of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), electrically erasable programmable ROM, register, hard disk, removable disk, CD-ROM, magnetic disk or optical disk and other media that can store program code.

[0238] Based on this, an embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the clock synchronization method described above are implemented.

[0239] The above is a detailed introduction to a clock synchronization method, device, equipment and computer-readable storage medium provided in the embodiments of the present application. The various embodiments in the specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same and similar parts between the various embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part description.

[0240] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0241] The above is a detailed introduction to a clock synchronization method, device, equipment and computer-readable storage medium provided by the present application. Specific examples are used herein to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of the present invention, several improvements and modifications can be made to the present application, and these improvements and modifications also fall within the scope of protection of the claims of the present application.

Claims

1. A clock synchronization method, characterized in that: include: Performing phase compensation on time parameters contained in the acquired historical clock synchronization message data of multiple cycles to obtain initial message data; In the case that the acquired initial message data meets the data volume requirement, clustering the initial message data and the latest acquired phase-compensated message data is performed to filter out target message data that meets the bottom delay feature; When the target message data satisfies a set convergence condition, linear fitting is performed on the target message data to obtain a frequency correction value; Determine a phase correction amount according to target message data of the current cycle and a minimum transmission delay determined based on minimum delay iteration; The slave clock is corrected according to the frequency correction amount and the phase correction amount.

2. The clock synchronization method according to claim 1, characterized in that: The clustering of the initial message data and the latest acquired phase-compensated message data to screen out target message data satisfying the bottom delay feature includes: In the case where the slave clock is in an unstable state, the initial message data is used as an initial clustering cluster, and all the phase-compensated message data currently cached are clustered according to the initial clustering cluster to screen out the first message data that meets the bottom delay characteristics; and a clustering mark is set for the first message data; When the slave clock is in a stable state, each time new phase-compensated message data is received, the new phase-compensated message data is clustered using the message data with a clustering mark set to filter out second message data that meets the bottom delay feature; and a clustering mark is set for the second message data; The first message data and the second message data are used as target message data.

3. The clock synchronization method according to claim 2, characterized in that: When the target message data satisfies a set convergence condition, performing linear fitting on the target message data to obtain a frequency correction value includes: Determine whether the value and density of the target message data in the current period meet the set convergence conditions; wherein the convergence conditions include value distribution conditions and density conditions; When the value and density of the target message data of the current period meet the set convergence conditions, a linear fitting is performed on the target message data to obtain a frequency correction amount.

4. The clock synchronization method according to claim 3, characterized in that: The step of judging whether the value and density of the target message data of the current period meet the set convergence condition includes: Count the number of target message data whose values ​​in the current period are less than the set threshold; Calculate the ratio of the number to the total number of target message data in the current cycle; Determine whether the proportion is greater than or equal to a set ratio; When the proportion is greater than or equal to the set ratio, determining whether the data volume of the target message data of the current cycle is greater than or equal to the data volume of the target message data of the previous cycle; When the data volume of the target message data in the current cycle is greater than or equal to the data volume of the target message data in the previous cycle, the step of performing linear fitting on the target message data to obtain the frequency correction amount is performed.

5. The clock synchronization method according to claim 4, characterized in that: Also includes: When the proportion is less than the set ratio or the data volume of the target message data of the current cycle is less than the data volume of the target message data of the previous cycle, the protocol state machine of the next cycle is controlled to enter the slave clock unstable state.

6. The clock synchronization method according to claim 1, characterized in that: Also includes: When the acquired initial message data does not meet the data volume requirement, linear fitting is performed on the initial message data to obtain an initial frequency deviation; The slave clock is frequency corrected based on the initial frequency offset.

7. The clock synchronization method according to claim 1, characterized in that: The performing linear fitting on the target message data to obtain a frequency correction value comprises: Calculating the linear relationship between the target message data and time; The slope corresponding to the linear relationship is used as the frequency correction amount.

8. The clock synchronization method according to claim 1, characterized in that: Determining the phase correction amount according to the target message data of the current cycle and the minimum transmission delay determined based on the minimum delay iteration includes: Performing minimum delay iteration on the transmission delay corresponding to the current cycle and the minimum transmission delays corresponding to multiple historical cycles to determine the minimum transmission delay corresponding to the current cycle; The phase correction amount is determined according to the time parameters included in the target message data of the current cycle and the minimum transmission delay corresponding to the current cycle.

9. The clock synchronization method according to claim 1, characterized in that: The performing phase compensation on the time parameters contained in the acquired historical clock synchronization message data of multiple cycles to obtain the initial message data includes: Determine the accumulated frequency correction amount corresponding to n periods according to the historical frequency correction amount contained in the historical clock synchronization message within n periods; Determine the accumulated phase correction amount corresponding to the n periods according to the accumulated frequency correction amount, the historical phase correction amount contained in the historical clock synchronization message within the n periods, and the preset clock nominal frequency; Phase compensation is performed on the timestamp of the slave clock received message contained in the historical clock synchronization message according to the accumulated phase correction amount to obtain initial message data.

10. The clock synchronization method according to claim 9, characterized in that: Determining the accumulated frequency correction amount corresponding to n periods according to the historical frequency correction amount contained in the historical clock synchronization message within n periods includes: The frequency correction formula is called to process the historical frequency correction amount contained in the historical clock synchronization message within n cycles to determine the cumulative frequency correction amount corresponding to the n cycles; the frequency correction formula is as follows: Δf ∑ [n]=Δf ∑ [n-1]+Δf s [n]; Where n represents the set number of cycles, Δf ∑ [n] represents the cumulative frequency correction of the previous n times, Δf ∑ [n-1] represents the cumulative frequency correction of the previous n-1 times, Δf s [n] represents the nth frequency correction amount.

11. The clock synchronization method according to claim 10, characterized in that: Determining the accumulated phase correction amount corresponding to the n periods according to the accumulated frequency correction amount, the historical phase correction amount contained in the historical clock synchronization message within the n periods, and the preset clock nominal frequency includes: The phase correction formula is called to process the accumulated frequency correction amount, the historical phase correction amount contained in the historical clock synchronization message within the n cycles, and the preset clock nominal frequency to determine the accumulated phase correction amount corresponding to the n cycles; the phase correction formula is as follows: Among them, k represents the kth period, Indicates the cumulative phase correction amount for the previous n times, f s0 Indicates the preset clock nominal frequency, Δf ∑ [k-1] represents the cumulative frequency correction amount, Δt represents the time interval between two adjacent frequency corrections, Indicates the nth phase correction amount.

12. The clock synchronization method according to claim 11, characterized in that: With respect to the storage of historical clock synchronization message data, the method includes: A circular array queue is used to store the historical clock synchronization message data of the most recent n cycles; wherein the historical clock synchronization message data of each cycle includes the message sequence number, the local timestamp of the message sent by the master clock, the local timestamp of the message received by the slave clock, the correction time, the frequency correction amount, the phase correction amount and the clustering mark bit.

13. A clock synchronization device, characterized in that: It includes a compensation unit, a clustering unit, a fitting unit, a determination unit and a correction unit; The compensation unit is used to perform phase compensation on the time parameters contained in the acquired historical clock synchronization message data of multiple cycles to obtain initial message data; The clustering unit is used to cluster the initial message data and the latest acquired phase-compensated message data when the acquired initial message data meets the data volume requirement, so as to screen out target message data that meets the bottom delay feature; The fitting unit is used to perform linear fitting on the target message data to obtain a frequency correction value when the target message data meets a set convergence condition; The determining unit is used to determine the phase correction amount according to the target message data of the current period and the minimum transmission delay determined based on the minimum delay iteration; The correction unit is used to perform clock correction on the slave clock according to the frequency correction amount and the phase correction amount.

14. An electronic device, characterized in that: include: Memory for storing computer programs; A processor, configured to execute the computer program to implement the steps of the clock synchronization method according to any one of claims 1 to 12.

15. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the clock synchronization method according to any one of claims 1 to 12 are implemented.

Citation Information

Cited By

  • Endoscope control method and device, electronic equipment and storage medium

    CN119318456A