# Qubit-Based Clock Synchronization for QKD Systems Using a Bayesian Approach
## 2 Qubit-Based Synchronization Algorithm
#### Synchronization Probability
Because the synchronization task is most difficult in low-signal regimes, we use this approximation going forward. Thus,  
\[p(D|\tilde{S})=\prod_{i=1}^{N+M}p(B_{i}|\tilde{S}) \tag{9}\]  
and  
\[p(B_{i}|\tilde{S})=\prod_{\ell=1}^{4}p(b_{\ell}|\tilde{S}). \tag{10}\]  
For a given input from [PERSON], each of [PERSON]'s four detectors has an opportunity to detect a photon above the detection clicks arising from non-ideal behaviors. Naturally, we will use our knowledge of the system (the state fidelities, the quality of the polarization sorting, the dark count rates, the detector efficiencies, and the signal and decoy received mean photon number) to estimate the detection probabilities as accurately and efficiently as possible. Using a lookup table of the detection probabilities for the different inputs from [PERSON], these likelihoods can be calculated using standard statistical methods. However, the likelihood of generating \(D\) from [PERSON]'s published string is not the same as the probability that [PERSON]'s published string is the one that generated \(D\), which is given by \(p(S|D)\) and is the most relevant quantity to determine synchronization. [PERSON] theorem allows us to rewrite this quantity, called the posterior, as  
\[p(S|D)=\frac{p(D|S)p(S)}{p(D)}. \tag{11}\]  
In addition, we must also include the information that we expect exactly one correct synchronization offset (not just one on average). To formulate the problem as an exclusive synchronization, we must find the probability that some discreet timing offset, given by the time-bin index \(j\), is the correct synchronization offset, and that all the other offsets are incorrect. In other words, the probability that, for a given string of length \(N\) published by [PERSON], all the measurements before the \(j\)th bin are generated randomly, the measurements from \(j\) to \(j+N\) are generated from [PERSON]'s published string, and the measurements after \(j+N\) are generated randomly. Under these assumptions, we can write \(p(B_{1},...,B_{M+N}|S_{j})\) as a product of the likelihoods of these three sections as  
\[D=\{B_{1},D^{\prime}\}, \tag{3}\]0  
Here we introduce \(\mathcal{S}_{j}\), the assumption that the data is produced by a random string other than the synchronization string in question, but one with the same phase (i.e., the signal arrives at the same time bin in each period as it does for \(S_{j}\)). We can find the conditional probability for matching [PERSON]'s string to [PERSON]'s string at a potential synchronization index \(j\) in this framework using Equation (11), which gives  
\[D=\{B_{1},D^{\prime}\}, \tag{3}\]1  
Equation (13) is our main result and is the quantity of interest to identify clock synchronization between [PERSON] and [PERSON]. We determine the optimum synchronization index based on the value of \(j\) that maximizes this quantity, and the quantity itself gives us our confidence in that choice. The denominator in Equation (13) can be written in terms of known quantities using marginalization. Marginalization consists of rewriting a probability as a sum of the comprehensive conditional probabilities; in this case, the different possible synchronization indices written as  
\[D=\{B_{1},D^{\prime}\}, \tag{3}\]2  
where the \(i\) denotes the other potential synchronization indices. To evaluate Equation (13), the likelihoods \(p(B_{1},...,B_{M+N}|S_{j})\) and \(p(B_{1},...,B_{M+N}|S_{i})\) can be determined using Equations (7), (9) and (12). The quantity \(p(S_{j})\), called the prior, is the ad hoc probability that \(D\) corresponds to [PERSON]'s published string. That is, \(p(S_{j})\) is the probability that we are at the correct synchronization index.