Thank you for visiting nature.com. You are using a browser version with limited support for CSS. To obtain the best experience, we recommend you use a more up to date browser (or turn off compatibility mode in Internet Explorer). In the meantime, to ensure continued support, we are displaying the site without styles and JavaScript.

# Online adaptive quantum characterization of a nuclear spin

## Abstract

The characterization of quantum systems is both a theoretical and technical challenge. Theoretical because of the exponentially increasing complexity with system size and the fragility of quantum states under observation. Technical because of the requirement to manipulate and read out individual atomic or photonic elements. Adaptive methods can help to overcome these challenges by optimizing the amount of information each measurement provides and reducing the necessary resources. Their implementation, however, requires fast-feedback and complex processing algorithms. Here, we implement online adaptive sensing with single spins and demonstrate close to photon shot noise limited performance with high repetition rate, including experimental overheads. We further use fast feedback to determine the hyperfine coupling of a nuclear spin to the nitrogen-vacancy sensor with a sensitivity of $$445\,{\mathrm{nT}}{\sqrt{\mathrm{Hz}}}^{- 1}$$. Our experiment is a proof of concept that online adaptive techniques can be a versatile tool to enable faster characterization of the spin environment.

## Introduction

Quantum sensing uses the readout of quantum systems to obtain information about the physical world. The accuracy depends on the sensor response to the parameter of interest and the ability to collect and process classical information. The ultimate limits to the sensitivity of quantum sensors can be obtained from the maximum speed that a quantum state can be driven to an adjacent state in response to the signal1,2 and the information content of probabilistic readout3,4.

In general, attaining the ultimate sensitivity limits requires prior knowledge about the parameter to be measured, for example, the range of values it can take. Protocols that utilize adaptive measurements can optimize the acquisition of supportive prior information5 and thus improve the performance of quantum sensors6 by operating them in their most sensitive regime. An improvement in nonadaptive (NA) techniques is obtained by updating each sensing sequence based on the results of previous measurements, in concert with classical processing algorithms. In particular, adaptiveness allows sensing to be performed in environments with changing conditions and features higher noise resilience7,8,9,10.

In the context of measuring optical phases in interferometry, experiments using NA11 and adaptive12 phase estimation algorithms (PEAs) have demonstrated nearly Heisenberg-limited sensitivity. Likewise, for magnetic field sensing, similar techniques have been transferred to solid-state spins. The negatively charged nitrogen-vacancy (NV) center in diamond13 has raised particular attention as atomically sized sensor14,15 with potential application as a quantum register element for information processing16. For the characterization of larger registers that incorporate nearby nuclear spins, it is key to efficiently exploit the available resources, for example, the measurement time, which can exceed days17. However, until now, the focus of optimized algorithms has been on improved estimation of the phase response of single spins to constant (direct current (DC)) magnetic fields5,18,19,20. Here, we extend upon previous work to implement multiparameter estimation with adaptive measurements and use this methodology for fast characterization of the sensor’s quantum environment. We measure the parallel hyperfine coupling of a single NV center to a single 13C nucleus with 4.4 kHz uncertainty in 16.0 s. Recently, a one-dimensional (1D) parameter estimation technique has been used for characterization of nuclear spins21 near to an NV center. However, this experiment required prior knowledge on the hyperfine coupling in order to perform conditional two-qubit gates. Our work is complementary as we require less pre-characterization but only measure one of the hyperfine tensor components.

The experiments described here are performed with single NV centers in diamond. Optical readout of the NV spin state (eigenstates are denoted here as |0〉, |1〉) allows induced shifts in the spin population to be detected as a highly sensitive probe of magnetic fields22. For sensing of static (DC) magnetic fields, a Ramsey sequence is used to map the sensor-phase response to a magnetic field intensity $$B = |{\mathbf{Be}}_{Z}|$$ into the population, which is subsequently read out optically. The symmetry axis eZ of the NV determines the projection of the magnetic field vector. The accuracy of Ramsey interferometry for estimating B within a total measurement time Tm is limited by the photon shot noise to

$$\sigma _B = \frac{{\sqrt {2e}}}{{C\gamma \sqrt {T_{2}^{\ast} \,T_{\mathrm{m}}} }}$$
(1)

where C ≤ 1 is a dimensionless parameter describing the readout efficiency, $$\gamma = 2{\pi} \times 2.8\,{\mathrm{MHz}}\,{\mathrm{G}}^{ - 1}$$ is the NV’s gyromagnetic ratio and $$T_2^ \ast$$ is the phase coherence time of the NV. However, this accuracy is only reached when using a Ramsey sequence with a phase evolution time in which the sensor interacts with the magnetic field for a duration of $$\tau \sim T_2^ \ast {\mathrm{/}}2$$23. By normalization to $$\sqrt {T_{\mathrm{m}}}$$ and considering experimental overheads, the standard measurement sensitivity (SMS) limit $$\eta _{\mathrm{SMS}} = {e}^{\frac{\tau }{{T_2^ \ast }}}\frac{{\sqrt {\tau + t_{{\mathrm{ov}}}} }}{{\gamma C\tau }}$$ is obtained where $$t_{{\mathrm{ov}}} = T_{\mathrm{m}} - \tau$$ is the time of all overhead associated with the experiment (details in “Methods” section).

Due to phase wrapping of the sensor, measuring at a fixed, maximum τ creates an ambiguity because multiple magnetic fields result in the same sensor output. Only if the field is known before hand to fall within $$[B - \frac{{\pi }}{{2\gamma \tau }},B + \frac{{\pi }}{{2\gamma \tau }}]$$ can it be measured uniquely. This fixes the dynamic range of the measurement to $${\mathrm{DR}} = \frac{{2{\pi}}}{{\sqrt {2{e}} }}C\sqrt {T_{\mathrm{m}}{\mathrm{/}}T_2^ \ast }$$. Without prior information on the magnetic field, the accuracy of an unambiguous Ramsey measurement with a requisite shortened interaction time decreases drastically, as can be seen from Methods Equation (2).

Recently, a class of sensing protocols based on quantum-phase estimation24 has been suggested18,19,20,24 to overcome the trade-off that standard approaches for sensing DC magnetic fields suffer: either high sensitivity but limited dynamic range or vice versa. So far, the best-known protocols adapt the measurement settings conditioned on earlier results of the sensing sequence. These require either cryogenic readout conditions5,25 or, at room temperature, have used post-processing on offline experimental datasets26. We implement a recently proposed magnetic field learning (MFL) algorithm26 that changes the Ramsey sensing sequence applied to a single NV center online and based on results of previous measurements (Fig. 1a). Each updated Ramsey pulse sequence is selected from a list of 256 unique sequences that are applied with an arbitrary waveform generator (AWG).

The algorithm is implemented as follows. An underlying Bayesian model encodes the probability of different magnetic field values in a prior distribution P(B) (Fig. 1a, top middle). In every epoch, a Ramsey experiment and sensor readout are performed multiple times before a subsequent Bayesian update. According to Bayes’ rule, the likelihood function $$L(E = \{ 0\;{\mathrm{or}}\;1\} |B,\tau )$$ describing the probability given the observed experimental outcome (E = |0〉 or E = |1〉, only the two NV eigenstates are considered) is multiplied to P(B) in order to obtain a posterior P(B|E). Thus, one of two possible likelihood functions is chosen determined by comparing the number of detected photons against a known threshold value (majority voting)27, as illustrated in Fig. 1a (top right). Due to inefficiencies in the optical readout, on average a photon is recorded only every ~17 experiments ( average photon number in the NV superposition state per readout I ~ 0.059). We repeat each Ramsey experiment with the same experimental parameters nphot/I times, obtaining on average nphot photons per epoch. The Ramsey sequence for the next epoch i + 1 is chosen by calculating the desired phase evolution time based on the heuristic rule $$\tau _{i + 1} \approx 1/\sigma _{{{P}}_i}$$ to ensure that the period of the likelihood function is in the same order as the current uncertainty $$\sigma _{{P}_i}$$ of the posterior in epoch i. The selection, switching, and loading from one of the 256 sequences has no associated overhead (<100 ns duration); however, the feedback loop including calculation of the Bayesian update, performed on a computer, takes ~1 ms.

Importantly, MFL allows magnetic field determination over a large range without a trade-off in sensitivity. This behavior follows from a heuristic that selects evolution times that optimize the Fisher information extracted from a typical MFL run. The choice of a τ that maximizes the Fisher information of a single measurement depends on the actual magnetic field value to find the steepest slope of the Ramsey fringe23. Consequently, the choice of exactly $$\tau = T_2^ \ast {\mathrm{/}}2$$ might be unfavorable, if the slope is as low as illustrated in Fig. 1b (middle) or if environmental conditions change28. While our algorithm does not perform optimization for each individual magnetic field value, statistically our heuristic enables us to obtain a sensitivity close to the Crame–Rao bound averaged across all magnetic field values28.

## Results and discussion

### DC magnetic field estimation

In Fig. 2 we show results of adaptive measurements to estimate the DC magnetic field as a single parameter. In Fig. 2a, we plot four single runs of the algorithm at different DC magnetic fields, illustrating the high dynamic range. In every epoch, a Bayesian update is iteratively applied. Hence, the uncertainty of the magnetic field decreases and convergence to the correct field is reached.

Qualitatively, the increased dynamic range of MFL allows unambiguous estimation of magnetic fields over a range of 1.8–169 μT, while maintaining a sensitivity close to the theoretical SMS. We quantify this behavior in Fig. 2b, where the final sensitivity reached for averaged runs at different magnetic fields is shown. As expected, the sensitivity is nearly constant over the whole accessible magnetic field range and we reach sensitivities close to the SMS over the whole dynamic range. In this measurement, we demonstrate a dynamic range of 110× (lowest field B = 1.43 μT), or at the maximum magnetic field of 153.6 μT, an improvement in sensitivity of 17× over an unambiguous Ramsey experiment with fixed phase evolution time and no prior knowledge of the magnetic field range. Details of the sensitivity calculations for these Ramsey experiments can be found in the “Methods” section. We confirm the dynamic range by simulations in Supplementary Fig. 1, showing only weak modulation of sensitivity with the magnetic field. In our experiment, the maximum detectable magnetic field is limited due to the restricted memory of the AWG as the number of storable experiments with distinct τ is finite. We store 256 Ramsey sequences with linearly spaced τj, where τj + 1 = τj + Δτ. This implies a Shannon–Nyquist sampling limit of fmax = 1/(2Δτ), also shown in Fig. 2b. When choosing magnetic fields close to or bigger than 2πfmax/γ, the MFL fails to obtain correct estimates. Neglecting the memory constraints of the AWG, the limiting property of the dynamic range is the Rabi frequency Ωrabi of the π/2 pulses. If the magnetic field saturates $$\gamma B_{\max} > \Omega_{\mathrm{rabi}}$$, it is not possible to resonantly control the NV spin anymore. For reported Rabi frequencies of ~100 MHz with NV sensors, Bmax ~ 3500 μT would be expected. Controlling the frequency and phase of the microwave pulses in addition to the Ramsey phase evolution time could be used to further increase the dynamic range. On the other hand, the smallest detectable signal for both classical Ramsey experiments and phase estimation-based protocols is given by Eq. (1), placing the maximum reachable dynamic range for our experimental conditions to $$\sim 4.2 \times 10^4 {\sqrt{\mathrm{Hz}}}^{ - 1}$$. We note that measuring such small fields is frequently challenging due to stability requirements on the test field.

For many applications, the sensor readout rate is an important device characteristic since this defines how quickly information is obtained from the device. While PEAs for magnetic field sensing6,18,19,20 have combined a sensitivity close to the SMS with a high dynamic range, the experiments differ in how quickly the final sensitivity can be reached. To obtain a comparable metric, in Fig. 2c we plot the magnetic field uncertainty against the accumulated phase evolution time. Three different regimes can be observed: At the beginning, the MFL acquires coarse knowledge by choosing short phase evolution times in the Ramsey sequence. Thus, the magnetic field uncertainty decreases only slowly. Subsequently, after the field range has been narrowed, longer τ is chosen and the uncertainty decreases sharply. When the MFL starts to request phase evolution times close to the dephasing time of the NV, a scaling kink is observed. As τ cannot be increased anymore, the magnetic field uncertainty improves only with statistical $$\propto 1/ \sqrt {t_{\Phi}}$$ behavior. We define the time Trep of the scaling kink as the repetition time of the protocol and plot its dependence against the average number of photons nphot in Supplementary Fig. 2a. Clearly, fewer photons per epoch allow faster repetitions rates and we achieve a minimal Trep = 0.24 s for nphot = 6.

Reaching sensitivities close the SMS over a high dynamic range is a distinct benefit of the MFL. In Fig. 2d we observe that sensitivity improves with the accumulated running time (accumulated phase evolution time plus all overheads), as expected. The statistical $$\propto \sqrt {t_{\Phi}}$$ scaling after the kink translates into a constant sensitivity reached at longer sensing times. For photon numbers on the order of nphot ~ 10, we approach the SMS. The best observed sensitivity is η = 132 $${\mathrm{nT}}{\sqrt{\mathrm{Hz}}}^{ - 1}$$ after a total runtime of ~1.5 s including all experimental overheads. This sensitivity is a factor 1.46 higher than the ηSMS = 90.5 $${\mathrm{nT}}{\sqrt{\mathrm{Hz}}}^{ - 1}$$ for the employed NV. The discrepancy is mainly explained by the overhead of the feedback loop, which becomes considerable compared to the phase evolution time per epoch at low nphot. For instance, the computational overhead makes up for 45% of the total runtime for an MFL run with nphot ~ 6 (see Supplementary Fig. 3). Including this additional dead time in the analysis, the relative difference between sensitivity and the theoretical limit decreases to only 8%. These results yield a figure of merit $$\frac{{B_{\mathrm{max}}}}{\eta} = 1803\sqrt{\mathrm{Hz}}$$, which is to the best of our knowledge a record for a single NV room-temperature experiment.

Not reaching the SMS at higher nphot is an expected behavior: In every epoch the shape of the likelihood function that is multiplied to the current prior distribution is fully determined by the phase evolution time and the binary outcome of the measurement. In the case of our averaged optical readout, higher photon numbers increase the (photon shot noise limited) signal-to-noise-ratio (SNR) and thus lead to less mistaken outcomes. If the error probability is already low, increasing the SNR only changes the outcomes in few epochs but adds uninformative measurement time to all epochs. Equivalently, the majority voting is discarding more and more information for higher average photon numbers. Hence, the overall sensitivity is decreased. In Supplementary Fig. 2b, we characterize the trade-off between reduced precision (ps ≤ 1, defined as the fraction of complete MFL runs that yield correct magnetic field results) and sensitivity. To this end, we define an effective sensitivity $$\eta _{\mathrm{eff}} = \eta /\sqrt {p_{\mathrm{s}}}$$ that accounts for the fact that wrong magnetic field attribution due to poor SNR needs to be balanced by additional MFL repetitions. For our experimental conditions, an optimal photon number nphot ~ 40 exists, where $$\eta _{{\mathrm{eff}}} = 204\,{\mathrm{nT}}{\sqrt{\mathrm{Hz}}}^{ - 1}$$ is minimized. This effective sensitivity is a factor of 2.25 higher than the SMS, even considering all experimental overheads. Arguably, this effective sensitivity is our most relevant result for application as a DC magnetic field sensor. A possible route to mitigate sensitivity loss at elevated photon numbers would be to increase the extracted information per epoch by considering the exact number of detected photons in the likelihood function or even their time of arrival27.

Previously, it was shown that NA phase estimation protocols can perform nearly as well as adaptive algorithms. However, this requires careful parameter optimization depending on the readout efficiency of the experiment5,29 (often referred to as G, F, and R in the literature). It is an advantageous property of the MFL that except for determination of the average photon number I, no further tuning is required, since adaption to the readout is implicitly performed by choosing phase evolution times according to the current width of the posterior distribution. In Fig. 2b, c we also plot simulations of a parameter optimized NA-PEA5 with the same experimental parameters. An increased noise resilience of MFL is reflected by the fact that NA-PEA requires significantly higher average photon numbers of nphot ~ 180 and delivers a worse overall sensitivity ($$\eta = 259\,{\mathrm{nT}}{\sqrt{\mathrm{Hz}}}^{ - 1}$$) than MFL, even comparing with its effective sensitivity defined above. NA-PEA performs best if the predetermined phase evolution times optimize the extracted Fisher information, which can be hindered by fixed values of $$T_2^ \ast$$ and targeted dynamic range. In terms of repetition rate, one could expect an advantage for NA-PEA due to the nonexisting computational overhead as the MW sequence in the AWG is never altered after an optimized set of parameters has been found. We observe, however, that MFL operated with moderate photon numbers nphot = 62 can reach a sensitivity of $$\eta \sim 260\,{\mathrm{nT}}\,{\sqrt{\mathrm{Hz}}}^{ - 1}$$ equally fast even considering our current overhead. Optimized hardware allowing for shorter computation and communication times would lead to a further advantage for MFL.

### Nuclear spin |AII| characterization

Next, we extend our adaptive protocol from sensing a classical DC magnetic field to multiparameter estimation of the quantum environment of the sensor. This capability is required for learning about complex environments. In particular, we use MFL to determine the parallel component of the sensor’s hyperfine coupling to a 13C nuclear spin in the diamond lattice. As evidenced by a splitting in the sensor’s energy spectrum, coupling to the carbon spin increases the Hilbert space of the sensor/environment interaction, thereby increasing the parameter space of our estimation. A Ramsey experiment with a single nuclear spin coupled to the NV yields a result as sketched in Fig. 3b. The oscillation in the time domain now consists of two single frequencies, which correspond to the offset of the microwave frequency to the NV-13C resonances that could be observed in a pulsed optically detected magnetic resonance experiment. The parallel hyperfine coupling is given by the difference of both frequencies $$|A_{||}| = |f_1 - f_2|$$. We apply the same methodology as in the one-dimensional (1D) case to estimate both frequencies of the Ramsey experiment. As the parameter space grows, the prior P(B1, B2) and the posterior P(B1, B2|E) of the MFL become two dimensional (2D). The decoherence-free likelihood function $$L_{2{\mathrm{D}}}^\prime = 0.5\left[ {\cos \left( {\frac{{\gamma B_1\tau }}{2}} \right)^2 + \cos \left( {\frac{{\gamma B_2\tau }}{2}} \right)^2} \right]$$ (full case in “Methods” section) is constructed from equally weighted frequency components. We show exemplary priors and likelihood functions in Fig. 3a. In complete analogy to the 1D case, the MFL picks short τ for early epochs where a flat prior represents poor knowledge about the frequencies $$f_{1,2} \equiv \gamma B_{1,2}{\mathrm{/}}2\pi$$. For the multiparameter estimation, the corresponding likelihood function shows multiple broad peaks that are symmetric in either dimension. As the prior becomes single-peaked during the evolution of the MFL, the choice of τ ensures that the likelihood function at later epochs is multiplying a single peak of the likelihood to non-zero parts of the prior.

In Fig. 3c the result of a single 2D MFL run is depicted. In the inset a trace of the differences of the resulting frequencies of subsequent repetitions of the 2D MFL is plotted. A linear fit to these frequency differences directly yields the parallel component of the hyperfine coupling $$|A_{||}| = \left( {59.10 \pm 0.36} \right)\,{\mathrm{kHz}}$$, whereas the frequency average gives the background magnetic field strength. Although the perpendicular hyperfine coupling A is unknown, it is possible to deduct the possible position of the nuclear spin as an isosurface around the NV from |A|||30. In Fig. 3a we plot this localization at the beginning and end of a single MFL run.

For 1D parameter estimation, Heisenberg-limited scaling behavior (η2T−1) has been observed26 for MFL. In our experiments, the scaling in learning a 2D model is less favorable than learning a single parameter like the DC magnetic field. In Fig. 3d the slope in the middle part is reduced for approximately a quarter when comparing to a simulated 1D case with the same experimental parameters. Hence, we assume that the heuristic (see “Methods” section) for multiparameter estimation could be further optimized. Note that it is not possible to directly compare experimental data, since we would need to employ distinct NVs for both cases with different coherence times and fluorescence count rates.

Our experiment operates in a regime where, due relaxation of the carbon spin during readout, multiple incoherent nuclear spin flips occur during the course of a single MFL epoch that averages over multiple (nphot/I) readouts of the NV. Thus, the nuclear spin will be in one of its eigenstates approximately half of the time, motivating the choice of equal contribution of the frequency components in the likelihood function. As each component of the recorded Ramsey fringe has half the contrast compared to the 1D likelihood, a lower sensitivity bound of $$\eta _{{\mathrm{SMS}}^ \ast ,2{\mathrm{D}}} = 2\eta _{{\mathrm{SMS}},1{\mathrm{D}}}$$ is theoretically expected. Generally, the SMS for 2D parameter estimation is $$\eta _{{\mathrm{SMS}},2{\mathrm{D}}} = \sqrt 2 \eta _{{\mathrm{SMS}},1{\mathrm{D}}}$$, assuming that we measure two distinct Ramsey fringes depending on the state of the nuclear spin. The theoretical limit, assuming a perfect readout, for estimating M independent parameters is $$\eta _{{\mathrm{SMS}},M{\mathrm{D}}} = \sqrt M \eta _{{\mathrm{SMS}},1{\mathrm{D}}}$$.

From the data in Fig. 3d, we calculate a finally obtained experimental phase acquisition sensitivity which is a factor of $$\eta _{2{\mathrm{D}}} = 2.09\, \eta _{1{\mathrm{D}}}$$ higher than the 1D simulation, indicating that our experiment operates reasonably close to the optimum achievable at the given readout conditions. Our best experimental sensitivity for a 2D MFL is extracted to be $$\eta _{2{\mathrm{D}}} = 445$$ $${\mathrm{nT}}{\sqrt{\mathrm{Hz}}}^{ - 1}$$ ($$\Delta B_{{\mathrm{avg}}} = 3.1\,{\mathrm{kHz}}$$ after 16.0 s including overheads, Fig. 3d). This is a factor of 2.4 higher than the 2D limit $$\eta _{{\mathrm{SMS}}^ \ast ,2{\mathrm{D}}}$$, a fact that is due to the relatively high average photon numbers (nphot ~ 90) in this experiment. As in the 1D simulation, which shows an offset from the theoretical limit of $$\eta _{1{\mathrm{D}}} = 1.9\,\eta _{{\mathrm{SMS}},1{\mathrm{D}}}$$ (see Fig. 3d), the use of majority voting when high numbers of photons are collected results in a reduced sensitivity. At high photon numbers, sensitivity and effective sensitivity coincides closely, η ~ ηeff, which allows the factor of 2.4 to be compared to the 1D MFL case (factor 2.25 in terms of ηeff). We attribute the additional sensitivity impairment to the increased overhead of the computationally more intensive 2D MFL. Likewise to the 1D case, a route to improved sensitivity is the replacement of majority voting to yield a more informative likelihood function.

Our value can be translated to a spatial sensitivity if A is known. For example, the spatial sensitivity yields 76 $${\mathrm{nm}}{\sqrt{\mathrm{Hz}}}^{ - 1}$$, if we were to determine the location a 13C spin in 5 nm distance ($$|A_ \bot | = 0.15 \, {\mathrm{kHz}}$$, $$|A_{||}| = 0.26\,{\mathrm{kHz}}$$ for an 13C with average A). We do not expect this sensitivity to improve compared to A|| determination by dynamical decoupling (DD) techniques, since the photon shot noise limit for the latter is limited by T2. However, DD techniques typically need to sweep the phase evolution time axis first, before varying the number of decoupling pulses Nπ31,32. Thus, there is substantial overhead spent for pre-characterization in the total measurement. As a consequence, we find our technique to be a valuable tool for characterizing strongly coupled ($$> 1/ T_{2}^{\ast}$$) external spins, not hidden in the spin bath. When measuring hyperfine couplings via the nuclear Lamor precession, measurement back action from the NV can introduce broadening of the nuclear linewidth33,34. For the estimation of A|| that we perform, however, we do not expect a detrimental influence on our estimation sensitivity as our measurement does not rely on tracking the evolution of a coherent superposition of the nuclear spin state, but only probes the projection of the nuclear spin in the measurement basis.

As an important remark, we note that multidimensional parameter estimation can be combined with arbitrary sensing sequences, as long as an expression for the likelihood function can be given. Analytic expressions exist for the coherence in Hahn echo modulation and DD experiments31,32,35,36,37, which both can be used for determination of the perpendicular hyperfine component A. Since for this purpose two parameters (τ, Nπ) need to be controlled, this requires more addressable AWG memory than available in our current experiment. We anticipate that recent methods for full characterization of a multi-qubit register38 or spatial reconstruction of the spin environment17,30 may benefit from online adaptive sensing. To this end, high-dimensional likelihood functions encoding all involved coupling constants and the according computing power to evaluate the large parameter space will be required.

If a complete MFL run could determine γB to an accuracy <2πA|| within the relaxation time of a coupled nuclear spin, effectively providing a single-shot measurement of the nuclear state, our method would be extendable to allow for quantum feedback techniques39 conditioned on the nuclear spin state. This will require implementation of MFL on microcontrollers, field programmable gate arrays, or other devices with improved real-time processing capabilities.

## Conclusion

We have demonstrated an online adaptive MFL algorithm in a room-temperature quantum sensing experiment. Using fast-feedback conditioned on measurement of a single spin sensor, we reached a magnetic field sensitivity of $$204\,{\mathrm{nT}}{\sqrt{\mathrm{Hz}}}^{ - 1}$$, which is by a factor of 2.25 above the SMS, while simultaneously increasing the dynamic range by a factor of one hundred when compared to measuring at $$\tau = T_{2}^{\ast} /2$$. By extending the estimation to two parameters, we measured the parallel hyperfine coupling to a nearby 13C nucleus, allowing estimation of the hyperfine coupling with an uncertainty of 4.4 kHz in 16.0 s without requiring any pre-characterization.

We anticipate that by combining with sensing protocols beyond Ramsey interferometry, adaptive measurements can become a powerful tool for imaging and chemical analysis on the nanoscale and the characterization of complex quantum systems. Since other sequences generally imply more complex likelihood functions, it remains as an open question how an optimal heuristic for choosing the next set of experimental parameters can be derived. For nanoscale magnetic resonance imaging, the slow data rate of measurements, obtained by the readout of a single bit sensor, limits the timescale/speed of experiments. Thus, such adaptive protocols will be of immense importance. Beyond improved sensing and characterization, we envision the techniques developed here to allow for quantum feedback and control methods not achievable with classical feedback methods to have applications in emerging quantum technologies.

## Methods

### Sample

All experiments were carried out with two single NVs ($$T_{2}^{\ast} = 18.7$$ μs, no coupled 13C and $$T_{2}^{\ast} = 19.0$$ μs with coupled 13C; data from classical Ramsey experiments), which are located ~1 μm below the surface in an isotopically enriched (99.8% 12C) diamond sample grown by chemical vapor deposition. An external bias magnetic field of B0 ~ 500 G was applied along the NV axis by a permanent magnet to ensure polarization of the nitrogen nuclear spin inherent to any NV. For the sake of easier notation throughout the main text, we discuss applied magnetic fields defined as B := Babs − B0 denoting the absolute magnetic field as Babs.

### Setup

We control and read the NV state with a standard home-built confocal microscope. Initialization and readout laser pulses of 750 ns at a wavelength of 532 nm are generated by a continuous wave laser and an acousto-optical modulator. Photon counts are gated by a switch to only consider the beginning 600 ns of the laser pulse. This value is obtained by optimizing the SNR of the optical readout. All laser pulse shapes and microwave waveforms are sampled on an AWG (Tektronix AWG70000A) amplified and applied to the NV through a copper wire of 20 μm diameter placed on top of the diamond. Photoluminescence photons of the NV in the >650 nm band are collected through an oil objective lens (Olympus, ×60, NA 1.35), counted by an avalanche photodiode (APD Excelitas SPCM), and digitized by a counting card (National Instruments 6323). The experiment is controlled by a custom measurement software40.

### Feedback loop

After the waveform for an epoch has been played, the AWG outputs a trigger signal that is received by the counting card. An interrupt handler implemented in Python is invoked, which creates a timestamp on leave of the handler function. The running time per epoch used for sensitivity calculation is defined as the difference between two of those timestamps. Before creating the timestamp, the photon counting register of the counting card is read out to obtain a binary measurement result by comparing it to a pre-characterized threshold photon number. Then, the Bayesian update is performed by multiplying the likelihood function according to the prior sampled at 1000 (1D MFL) or 2000 (2D MFL) positions. Depending on the width of the posterior distribution, a new phase evolution time is calculated. To reduce computational complexity, we use a particle guess heuristic that samples two positions {B1, B2} in parameter space and choses $$\tau = 1/(\gamma |B_{2} - B_{1}|)$$ with |·| denoting the 1-norm. For 2D estimation, the heuristic is simply translated by calculating the norm in the 2D space. Then, the memory address of the sequence with the closest τ is output to the AWG. As our addressable AWG memory is limited, it is possible that the MFL requests τ longer than present in memory. Choosing the closest τ would then lead to uninformative repetition of the same sequence. In order to mitigate, we randomly reshuffle those cases such that on average $$\langle\tau\rangle = \frac{3}{4}T_{2}^{\ast}$$. By oscilloscope measurements, we confirm that the computational overhead between the trigger signal and new address issued is ~1 ms (1D MFL) per epoch. Due to the increased computational complexity, the feedback loop takes ~3 ms for 2D estimation. Omitting all computationally intensive code in the interrupt handler and outputting a static address takes ~0.2 ms, limited by the notification time, which the Windows operating system requires to invoke the handler on receipt of the AWG trigger signal.

### Standard measurement limit

The photon shot noise limited SMS of a single NV sensor reads23

$$\eta _{{\mathrm{SMS}}} = {e}^{\frac{\tau }{{T_2^ \ast }}}\frac{{\sqrt {\tau + t_{{\mathrm{ov}}}} }}{{\gamma C\tau }}$$
(2)

where $$C = ( {1 + ( {\frac{2}{{\vert {1 - \frac{{I_1}}{{I_0}}} \vert \sqrt {I_{\mathrm{o}}} }}} )^2} )^{- 1/2}$$ is the readout efficiency defined by the number of photons per readout pulse in |0〉 and |1〉 state of the NV and tov = Tm − τ is the time of all overhead associated with the experiment. For the SMS given in this work, we consider tov = 1.75 μs, which is the length of the readout and laser pulse plus a waiting time for initialization thereafter.

In Fig. 2b we compare against the sensitivity of an unambiguous Ramsey experiment. Assuming prior knowledge on the bounds as {B ± Bmax} = $$\{ B - \frac{{\uppi }}{{2\gamma \tau }},B + \frac{{\uppi }}{{2\gamma \tau }}\}$$, around a bias point B = 0, the dynamic range of a Ramsey experiment is defined by [−Bmax, Bmax]. Thus, we calculate the phase evolution time $$\tau = \frac{\pi }{{2\gamma B_{{\mathrm{max}}}}}$$ that yields an unambiguous result. Inserting into Eq. (2) gives the according unambiguous sensitivity.

### Data averaging

Since MFL is a probabilistic algorithm, the magnetic field uncertainty reached in a single run underlies statistical fluctuations. To this end, we give results averaged over ~50 independent runs. Due to the irregular spacing of the data points in the time domain, we use a moving average filter that calculates median values over a filter window of 100 ms.

### Likelihood functions

For 1D estimation of a DC magnetic field, the likelihood function is $$L = {e}^{ - \tau /T_2^ \ast }L^\prime + 0.5(1 - {e}^{ - \tau /T_2^ \ast })$$ with $$L\prime = \cos \left( {\frac{{\gamma B\tau }}{2}} \right)^2$$. The likelihood function $$L_{2{\mathrm{D}}} = {e}^{ - \tau /T_2^ \ast }L_{2{\mathrm{D}}}^\prime + 0.5(1 - {e}^{ - \tau /T_2^ \ast })$$ with $$L_{2{\mathrm{D}}}^\prime = 0.5\left[ {\cos \left( {\frac{{\gamma B_1\tau }}{2}} \right)^2 + \cos \left( {\frac{{\gamma B_2\tau }}{2}} \right)^2} \right]$$ used in 2D parameter estimation is symmetric under exchange of the estimated coupling parameters B1 and B2. A priori and given the true values {B1,t, B2,t}, this leads to a nonvanishing prior probabilities p(B1,t, B2,t) > 0 as well as p(B2,t, B1,t) > 0. To ensure a meaningful outcome for τ from the heuristic, we restrict the MFL to solutions where B2 > B1 by setting in every epoch the prior p(B1, B2 < B1) = 0. The coherence decay of a single qubit under influence of magnetic noise by a surrounding spin bath in a Ramsey experiment is frequently given by a factor of $${e}^{ - ( {\frac{\tau }{{T_2^ \ast }}})^2}$$. In our experiments, we found phenomenological agreement with $${e}^{ - \tau /T_2^ \ast }$$ and adopted it, which also matches the theoretical work28 proving the optimality of the 1D heuristic.

### Simulations

The simulated MFL data shown in Figs. 2c and 3c are obtained by running the same algorithm and averaging employed for the experiments. An experimental outcome is generated by evaluation of the likelihood function pz = L(τ, B) at given τ while B is constant. We approximately replicate the limited readout fidelity by randomly adding an offset sampled from a normal distribution $$p_{{z},{\mathrm{noisy}}} = p_{z} + N\left( {\mu = 0} \right.,\sigma = \sqrt {I{\mathrm{/}}(4C^2n_{{\mathrm{phot}}})}$$ and obtain a datum for a single MFL epoch by majority voting as E = |0〉 if pz,noisy < 0.5 and E = |1〉 otherwise. NA-PEA simulations are computed accordingly except for omitting the moving average filter, since τ is not irregularly spaced.

## Data availability

The datasets in this study are available from the corresponding authors on reasonable request.

## Code availability

The code used in this study is available from the corresponding authors on reasonable request.

## References

1. Margolus, N. & Levitin, L. B. The maximum speed of dynamical evolution. Phys. D 120, 188–195 (1998).

2. Wootters, W. K. Statistical distance and Hilbert space. Phys. Rev. D 23, 357–362 (1981).

3. Helstrom, C. W. Quantum detection and estimation theory. J. Stat. Phys. 1, 231–252 (1969).

4. Holevo, A. S. Information-theoretical aspects of quantum measurement. Probl. Inform. Transm. 9, 110–118 (1973).

5. Bonato, C. et al. Optimized quantum sensing with a single electron spin using real-time adaptive measurements. Nat. Nanotechnol. 11, 247–252 (2016).

6. Said, R. S., Berry, D. W. & Twamley, J. Nanoscale magnetometry using a single-spin system in diamond. Phys. Rev. B 83, 1–7 (2011).

7. Wiebe, N. & Granade, C. Efficient Bayesian phase estimation. Phys. Rev. Lett. 117, 1–6 (2016).

8. Paesani, S. et al. Experimental Bayesian quantum phase estimation on a silicon photonic chip. Phys. Rev. Lett. 118, 1–6 (2017).

9. Hincks, I., Granade, C. & Cory, D. G. Statistical inference with quantum measurements: Methodologies for nitrogen vacancy centers in diamond. N. J. Phys. 20, 013022 (2018).

10. Cappellaro, P. Spin-bath narrowing with adaptive parameter estimation. Phys. Rev. A 85, 1–5 (2012).

11. Higgins, B. L. et al. Demonstrating Heisenberg-limited unambiguous phase estimation without adaptive measurements. N. J. Phys. 11, 073023 (2009).

12. Higgins, B. L., Berry, D. W., Bartlett, S. D., Wiseman, H. M. & Pryde, G. J. Entanglement-free Heisenberg-limited phase estimation. Nature 450, 393–396 (2007).

13. Doherty, M. W. et al. The nitrogen-vacancy colour centre in diamond. Phys. Rep. 528, 1–45 (2013).

14. Staudacher, T. et al. Nuclear magnetic resonance spectroscopy on a (5-nanometer)3 sample volume. Science 339, 561–563 (2013).

15. Balasubramanian, G. et al. Nanoscale imaging magnetometry with diamond spins under ambient conditions. Nature 455, 648–651 (2008).

16. Bradley, C. E. et al. A ten-qubit solid-state spin register with quantum memory up to one minute. Phys. Rev. X 9, 31045 (2019).

17. Abobeih, M. H. et al. Atomic-scale imaging of a 27-nuclear-spin cluster using a quantum sensor. Nature 576, 411–415 (2019).

18. Waldherr, G. et al. High-dynamic-range magnetometry with a single nuclear spin in diamond. Nat. Nanotechnol. 7, 105–108 (2012).

19. Nusran, N. M., Momeen, M. U. & Dutt, M. V. G. High-dynamic-range magnetometry with a single electronic spin in diamond. Nat. Nanotechnol. 7, 109–113 (2012).

20. Puentes, G., Waldherr, G., Neumann, P., Balasubramanian, G. & Wrachtrup, J. Efficient route to high-bandwidth nanoscale magnetometry using single spins in diamond. Sci. Rep. 4, 1–6 (2014).

21. Hou, P. Y. et al. Experimental Hamiltonian learning of an 11-qubit solid-state quantum spin register. Chin. Phys. Lett. 36, 100303 (2019).

22. Maze, J. R. et al. Nanoscale magnetic sensing with an individual electronic spin in diamond. Nature 455, 644–647 (2008).

23. Degen, C. L., Reinhard, F. & Cappellaro, P. Quantum sensing. Rev. Mod. Phys. 89, 1–41 (2017).

24. Berry, D. W. et al. How to perform the most accurate possible phase measurements. Phys. Rev. A 80, 1–22 (2009).

25. Danilin, S. et al. Quantum-enhanced magnetometry by phase estimation algorithms with a single artificial atom. npj Quantum Inf. 4, 29 (2018).

26. Santagati, R. et al. Magnetic-field learning using a single electronic spin in diamond with one-photon readout at room temperature. Phys. Rev. X 9, 021019 (2019).

27. Dinani, H. T., Berry, D. W., Gonzalez, R., Maze, J. R. & Bonato, C. Bayesian estimation for quantum sensing in the absence of single-shot detection. Phys. Rev. B 99, 1–7 (2019).

28. Ferrie, C., Granade, C. E. & Cory, D. G. How to best sample a periodic probability distribution, or on the accuracy of Hamiltonian finding strategies. Quantum Inf. Process. 12, 611–623 (2013).

29. Hayes, A. J. F. & Berry, D. W. Swarm optimization for adaptive phase measurements with low visibility. Phys. Rev. A 89, 1–8 (2014).

30. Zopes, J. et al. Three-dimensional localization spectroscopy of individual nuclear spins with sub-Angstrom resolution. Nat. Commun. 9, 1–8 (2018).

31. Zhao, N., Ho, S. W. & Liu, R. B. Decoherence and dynamical decoupling control of nitrogen vacancy center electron spins in nuclear spin baths. Phys. Rev. B 85, 1–18 (2012).

32. Taminiau, T. H. et al. Detection and control of individual nuclear spins using a weakly coupled electron spin. Phys. Rev. Lett. 109, 137602 (2012).

33. Pfender, M. et al. High-resolution spectroscopy of single nuclear spins via sequential weak measurements. Nat. Commun. 10, 594 (2019).

34. Cujia, K. S., Boss, J. M., Herb, K., Zopes, J. & Degen, C. L. Tracking the precession of single nuclear spins by weak measurements. Nature 571, 230–233 (2019).

35. Rowan, L. G., Hahn, E. L. & Mims, W. B. Electron-spin-echo envelope modulation. Phys. Rev. 137, A61–A71 (1965).

36. Smeltzer, B., McIntyre, J. & Childress, L. Robust control of individual nuclear spins in diamond. Phys. Rev. A 80, 1–4 (2009).

37. Zhao, N. et al. Sensing single remote nuclear spins. Nat. Nanotechnol. 7, 657–662 (2012).

38. Gentile, A. A. et al. Learning models of quantum systems from experiments. Preprint at arXiv http://arXiv.org/abs/2002.06169 (2020).

39. Lloyd, S. Coherent quantum feedback. Phys. Rev. A 62, 022108 (2000).

40. Binder, J. M. et al. Qudi: a modular python suite for experiment control and data processing. SoftwareX 6, 85–90 (2017).

## Acknowledgements

We acknowledge the following support: T.J. by the Foundation of German Business (sdw). A.L. from EPSRC (EP/N003470/11). C.B. from EPSRC (EP/S000550/1) and Leverhulme Trust (RPG-2019-388). L.P.M. from the Australian Research Council Future Fellowship (FT180100100) funded by the Australian Government. F.J. from ERC Synergy Grant HyperQ, the German Federal Ministry of Education and Research (BMBF), DFG (excellence cluster POLIS and CRC1279), VW Stiftung, and EU via ASTERIQS. R.S., A.A.G., and A.L. from the Engineering and Physical Sciences Research Council (EPSRC) Hub in Quantum Computing and Simulation (EP/T001062/1).

## Funding

Open Access funding enabled and organized by Projekt DEAL.

## Author information

Authors

### Contributions

T.J., L.P.M., and F.J. conceived the experiment. T.J., S.S., A.A.G., and R.S. wrote the MFL code for the experiment. T.J. and S.S. prepared the sample and performed the experiment. T.J., C.B., and A.A.G. performed the simulations. T.J., S.S., and L.P.M. analyzed the data. T.J. and L.P.M. wrote the manuscript. All authors read and commented on the manuscript.

### Corresponding authors

Correspondence to Timo Joas or Liam P. McGuinness.

## Ethics declarations

### Competing interests

The authors declare no competing interests.

Publisher’s note Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

## Rights and permissions

Reprints and Permissions

Joas, T., Schmitt, S., Santagati, R. et al. Online adaptive quantum characterization of a nuclear spin. npj Quantum Inf 7, 56 (2021). https://doi.org/10.1038/s41534-021-00389-z

• Accepted:

• Published:

• DOI: https://doi.org/10.1038/s41534-021-00389-z