## 2 Method  
As shown in Figure 1a, the output intensity of the MZM is distorted by the phase (bias) drift \(\theta_{drift}\), which is mainly caused by temperature changes and the photorefractive effect [30; 50]. This negatively affects the performance of a QKD system that requires precisely defined pulse intensities. In this study, we propose a bias control method that compensates for it in the post-processing step after real-time bias drift estimation using \begin{table}
\begin{tabular}{l l l l} \hline \hline
**Abbreviation** & **Description** & **Symbol** & **Description** \\ \hline BS & Beam splitter & \(\theta_{drift}\) & Practical phase drift \\ CIR & Circulator & \(\theta_{drift}^{T}\) & Theoretical phase drift, \(\left[0^{{}^{\circ}},\,360^{{}^{\circ}}\right)\) \\ CW & Continuous-wave & \(p_{i}\) & Practical detection probability \\ DC & Direct-current & \(p_{T}\left(\theta_{drift}^{T}\right)\) & Theoretical detection probability \\ DFB & Distributed feedback & \(\mathrm{Err}\left(\theta_{drift}^{T}\right)\) & Error between \(p_{i}\) and \(p_{T}\left(\theta_{drift}^{T}\right)\) \\ DL & Delay line & \(\theta_{mod}\) & Phase modulation \\ DWDM & Dense wavelength division multiplexer & \(\theta_{mod}^{T}\) & Phase modulation of the \(i\)-th diagnostic pulse \\ ER & Extinction ratio & \(I_{cut}^{T}\) & Output intensity \\ FM & Faraday rotator mirror & \(L_{in}\) & Insertion loss \\ FPGA & Field-programmable gate array & \(I_{in}\) & Input intensity \\ MCU & Microcontroller unit & \(C_{i}\) & Count for the \(i\)-th diagnostic pulse \\ MZM & Mach–Zehnder modulator & & \\ PBS & Polarization beam splitter & & \\ PD & Photodiode & & \\ PID & Proportional–integral–derivative & & \\ PINPD & P-i-n photodiode & & \\ PM & Phase modulator & & \\ QBER & Quantum bit error rate & & \\ QKD & Quantum key distribution & & \\ SL & Storage line & & \\ SPD & Single-photon detector & & \\ TLD & Tunable laser driver & & \\ VOA & Variable optical attenuator & & \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Nomenclature of the symbols and abbreviations used in this article. diagnostic pulses. Figure 1b shows the block diagram of the method applied to a decoy-state BB84 QKD system [7; 27]. The detailed procedure is as follows. Here, the transmitter and receiver are indicated as [PERSON] and [PERSON], respectively, similar to conventional QKD systems. 1. During the QKD protocol, [PERSON] prepares \(N\) (\(\geq\)2) types of diagnostic pulses whose MZM phases are modulated by \(\theta_{mod}^{i}=\frac{2\pi}{N}(i-1)\) with uniformly distributed probabilities for \(i=\{1,\dots,N\}\). Thereafter, [PERSON] sometimes transmits them to [PERSON] as substitutes for the decoy pulses. Similar to the signal and decoy pulses, the diagnostic pulses are attenuated to single-photon levels. This method does not weaken the security of the QKD significantly because nobody except [PERSON] can distinguish between the decoy and diagnostic pulses. Conventionally, the MZM output intensity can be described as [34; 35; 39; 51; 52]: \[I_{out}=L_{in}I_{in}\cos^{2}\left(\frac{\theta_{mod}+\theta_{ drift}}{2}\right)\] (1) where \(\theta_{mod}\) and \(\theta_{drift}\) are the phase modulation and phase drift, respectively, \(L_{in}\) is the insertion loss and \(I_{in}\) is the input intensity. 2. [PERSON] receives and measures the incoming pulses using single-photon detectors (SPDs). After measuring, he publicly announces the time indexes where the signals are detected. Thereafter, [PERSON] and [PERSON] perform the remaining protocols, such as key sifting, error correction and privacy amplification. 3. Simultaneously, [PERSON] accumulates the detection results of the diagnostic pulses unless there are no significant phase drifts. The optimal accumulation time strongly depends on the ambient environment, channel loss, detection efficiencies and pulse intensities. 4.