Optimal frequency measurements with quantum probes

Precise frequency measurements are important in applications ranging from navigation and imaging to computation and communication. Here we outline the optimal quantum strategies for frequency discrimination and estimation in the context of quantum spectroscopy, and we compare the effectiveness of different readout strategies. Using a single NV center in diamond, we implement the optimal frequency discrimination protocol to discriminate two frequencies separated by 2 kHz with a single 44 μs measurement, a factor of ten below the Fourier limit. For frequency estimation, we achieve a frequency sensitivity of 1.6 µHz/Hz2 for a 1.7 µT amplitude signal, which is within a factor of 2 from the quantum limit. Our results are foundational for discrimination and estimation problems in nanoscale nuclear magnetic resonance spectroscopy.


INTRODUCTION
Quantum sensing uses platforms such as photons, ions, solidstate defects, and their quantum properties as resources to estimate physical quantities as precisely as possible 1,2 . The performance depends on the sensing and readout protocols, which should optimize the ratio of the sensor response for the parameter of interest 3,4 to readout noise 5 . Thus, finding optimal protocols is crucial to enabling efficient estimation. One of the major applications of quantum sensing is nanoscale nuclear magnetic resonance (NMR) spectroscopy in which a nanoscale quantum sensor replaces the macroscopic inductive coil and interacts with a sample of nuclear spins [6][7][8][9] . Pioneering work with the nitrogen-vacancy (NV) center in diamond 10,11 , has demonstrated nanoscale spatial resolution 6,7,[12][13][14] with single spin sensitivity 9 . Understanding and realizing the limits of quantum measurements is particularly important in spectroscopy wherein frequency encodes energy, spatial, and structural information.
Here we determine the quantum limit for discriminating known frequencies, develop a protocol that saturates it, and prove that this protocol achieves the minimal possible error probability as a function of time. After deriving the theoretical limits, we experimentally demonstrate this protocol by discriminating two known frequencies separated by 2 kHz, with a single 44 µs (Fourier limit 1/T~23 kHz) coherent measurement. We extend our studies by explicitly analyzing the influence of imperfect readout of our sensor qubit and perform a detailed comparison between two readout strategies.We show that these results can also be applied to find the optimal protocol for frequency estimation [15][16][17][18][19] and we use this protocol to experimentally estimate the value of a single unknown frequency. The relevance of the estimation protocol for realistic nano-NMR scenarios and the implications of the imperfect NV readout is further analyzed. Our results are important when one is faced with a decision on how to allocate finite resources to construct better sensors.

RESULTS
Optimal frequency discrimination using a quantum probe As a diagnostic tool, NMR can be used to answer "yes-no" questions such as whether a certain toxin or metabolite is present in the sample. As sketched in Fig. 1a, the task is then to discriminate between two known spectra based on their frequency components. We define discrimination error as the error to decide on the wrong spectrum and our goal is to obtain a minimal discrimination error or equivalently a minimal discrimination time. A typical method compromises sampling the signal with consecutive, synchronized measurements and correlating the individual outcomes, e.g., by applying Fourier analysis, to obtain a spectrum. For sufficient recording time, the resolution can be high enough for an almost error-free discrimination. To illustrate, consider a simplified problem in which one wishes to discriminate between two spectra, each containing only a single frequency (ω 1 or ω 2 ) with the same amplitude B (in units of angular frequency). Naively, the method described above is Fourier limited, i.e., the time required for discrimination is T ¼ 1 jωΔj , where ω Δ = ω 2 − ω 1 . Using a more sophisticated data analysis, such as Bayesian interference or machine learning, which can be applied for known B, the discrimination time lowers to T $ 1 Supplemen-tary Note 1 and ref. 20 ) However, we show in the following that, given a sufficient coherence time, the discrimination time can be further reduced to: The key idea is to drive the sensor such that the angle between the states, jψ ω 1 ð Þi and jψ ω 2 ð Þi, is maximal, to guarantee a minimal error probability. Once orthogonality is achieved, quantum projection noise can theoretically be eliminated by measuring in the appropriate basis and it is possible to determine, with a certainty limited by readout fidelity, which frequency is present. Assuming a perfect readout, we show that this method is in general optimal, even if orthogonality cannot be achieved. 1 Given free evolution of the sensor, the discrimination time is T $ ω BωΔ (see Supplementary Note 1), which is basically the same scaling as the Fourier limit. As sketched in Fig. 1b, the phases φðω 1 Þ and φðω 2 Þ, accumulated by the sensor under ω 1 and ω 2 , move apart and get closer to each other such that their difference φ Δ ¼ φðω 1 Þ À φðω 2 Þ oscillates and only slowly increases. However, T can be significantly reduced by applying a suitable control, which is also shown in Fig. 1b: whenever the states start to get closer to each other (φ Δ reduces), a control π-pulse can be used to change the direction of motion such that their distance increases instead. Formally, the distance between two states can be described by the angle φ Δ =2 def α ω 1 ; ω 2 ð Þ, which evolves as: Þσ Z are the corresponding signal Hamiltonians, θ is the initial signal phase, and σ Z is the Pauli spin-z operator. As a consequence, maximizing α ω 1 ; ω 2 ð Þimplies applying a π-pulse whenever H 1 t ð Þ À H 2 t ð Þ changes sign and it follows (see Supplementary Note 1): where μ max and μ min are the maximal and minimal eigenvalues of H 1 À H 2 . Application of a series of π-pulses with a spacing 2π ω1þω2 constitutes optimal control in this scenario. As orthogonality requires α ω 1 ; ω 2 ð Þ¼π=2, the minimal discrimination time is For an illustrative explanation, one can think of ψ ω 1 ð Þ j i; ψ ω 2 ð Þ j i as two runners, where the goal is to maximize the gap between them (see Fig. 1c). As long as the same runner (suppose ψ ω 2 ð Þ j i) is faster (speed proportional to the current amplitude), their separation gets larger as desired. However, once ψ ω 1 ð Þ j i starts to be faster than ψ ω 2 ð Þ j i, we prevent a reduction of the gap by flipping the direction they run (equivalent to a π-pulse).
The phase acceleration in Eq. (4) coincides with the fundamental speed limit derived in ref. 21 and this implies a minimal discrimination error for every t. Hereafter, for all error analysis, we assume that the prior probability for both frequencies is 1/2, namely symmetric hypothesis testing. Given any two Hamiltonians H 1 t ð Þ and H 2 t ð Þ, we prove in Supplementary Note 1 that the error probability when distinguishing between these Hamiltonians, optimized over all possible strategies, is lower bounded by: dt 0 . This lower bound can always be saturated with a suitable control. Hence, even if α max π 2 at t, the strategy that minimizes the error probability is to apply the above discussed control and perform a measurement at t, which implies that even multiple correlated measurements at times shorter than t 19,22 cannot beat this fundamental limit, as shown in Fig. 1d (see Supplementary Note 1).

Experiments
The experiments are performed using a single NV center in ultrapure diamond (Fig. 2a). Here we use a 400 G magnetic field, Fig. 1 Quantum-frequency discrimination. a The sensor state is tailored to depend on each frequency so that the sensor is driven in orthogonal directions. Readout of the state provides a "Yes/No" answer. The task is to correctly identify the frequency with highest fidelity in the shortest time. b Phase accumulation for frequency discrimination. For each Hamiltonian the sensor accumulates a different phase. Left: without control, the phase difference φ Δ oscillates and increases only slowly. Right: optimal control in this scenario implies applying π-pulses whenever the sign of H 1 -H 2 changes, leading to a monotone phase increase with t 2 . c Geometrical picture of the optimal protocol. The states of the sensor can be thought of as two runners, where the aim is to maximize the gap between them, which is equivalent to the angle between the states. The speed of each runner is proportional to H i t ð Þ. As soon as the initially slower runner becomes faster, we change their direction of motion to ensure an increasing gap. Note that the sketch just demonstrates the idea and the runners actually move on circular orbits. d Error probability as a function of time for three different strategies: optimal control and a single measurement (solid blue), this strategy is optimal and sets the fundamental error limit (see Eqs. 3 and 4). Correlated measurements (dashed red), in this illustration measurement is applied every 2π ω1þω2 . No control (dotted green). More details on this comparison are found in Supplementary Note 1.
aligned along the NV symmetry axis, to lift the degeneracy of the three ground spin states and we use two of these states (here denoted as 0 j i; 1 j i) as a qubit. We initialize our qubit into a coherent superposition state and map the sensor phase φ = 2α (compare Eq. (3)), acquired during interaction with the control sequence and the signals, into a population difference (such that the probability for the sensor to be projected to 0 j i reads P ¼ 0:5 Á 1 À sin φ ð Þ ð Þ , which is subsequently read out optically. In Fig. 2b, φ Δ is plotted, when a magnetic field of frequency ω 1 ¼ ð2πÞ Á 0:999 MHz or ω 2 ¼ ð2πÞ Á 1:001 MHz, in the range of frequencies typical for nano-NMR experiments with NV centers and was measured with an XY8-N sequence with an interpulse spacing of 500 ns. The interaction time was extended by increasing the pulse number. A logarithmic plot of φ Δ shows the expected t 2 increase until 44 µs when φ Δ ¼ π, at which time the quantum sensor has been evolved into one of two orthogonal states, as jP ω 1 ð Þ À P ω 2 ð Þj ¼ 1. By using a 90°phase-shifted π 2pulse (compared to the initialization basis), the sensor phase can be mapped into a population difference and the resulting NV population as a function of interaction time is plotted (Fig. 2c). In Supplementary Note 4, we show that this balanced readout is also optimal. Experimental data for the dependency of the discrimination time on ω Δ and B are provided in the Supplementary Note 5. If the coherence of the sensor is not sufficient to achieve orthogonality, the described protocol still remains optimal (see detailed discussion in Supplementary Note 1).

Complex frequency discrimination
This method can be extended for complex spectra consisting of more than one frequency or amplitude component. Consider a Hamiltonian that takes the general form 2 σ Z such that the two frequency distribution functions f 1;2 ω ð Þ are known, but we do not know which of the Hamiltonians, H 1 or H 2 , is present. As an illustrative example, we consider the 13 C nuclear magnetic spectrum produced by either a sample of ethanol or propanol, both of which contain two chemically distinct carbon groups (Fig. 3a, b). A similar speed bound for discrimination applies to this case (see Supplementary Eq. 1) and is achievable with an analogous protocol. We can again define H Δ ¼ H 1 À H 2 , where optimal control is achieved by applying π-pulses whenever H Δ switches sign (Fig. 3c). Importantly, for NMR detection of a polarized sample, the initial signal phase is known, as it is defined by a π/2pulse applied to the sample. As a result, a sensor phase difference of π can be tailored to perform optimal discrimination. Of note, the sensor phase difference also increases according to t 2 , until the signals become completely out of phase with each other.

Implications of imperfect readout
Above, we showed that in principle, it is possible to discriminate two frequency distributions within a single measurement by eliminating projection noise. As perfect measurements are not possible in an experimental realization, additional readout noise Fig. 2 Quantum-frequency discrimination. a Experimental setup: the spin state of a single nitrogen-vacancy (NV) center in diamond responds to magnetic fields by a Zeeman shift of the spin levels, which can be optically initialized and readout with a confocal microscope. b Experimentally measured quantum phase difference φ Δ as a function of coherent interaction time and as log-log plot (inset). Solid lines are a fit to c Measured spin population as a function of coherent interaction time. The probability to be in state 0 . For φ Δ ¼ π, the sensor is driven to one of two orthogonal eigenstates. All error bars correspond to SD of several independent repetitions.

Fig. 3
Optimal frequency discrimination of complex signals. a, b Calculated magnetic field experienced by the NV center exposed to a solution of ethanol (red) or propanol (blue) in frequency (a) and time (b) domains, where a π/2 pulse is applied to the thermally polarized sample at zero time. c Calculated optimal control sequence of π-pulses applied to the NV sensor (purple) overlayed on the signal difference (green). d Sensor phase accumulation in presence of ethanol (red), propanol (blue), and the phase difference (green), showing quadratic scaling at short times.
has to be taken into account. For optical readout of NV centers, e.g., photon shot noise has to be considered. As a result, noise analysis is important to obtain a meaningful discrimination error. The readout of the NV center is performed by detecting the spindependent fluorescence emitted during a laser pulse (see "Methods"). The recorded photons are well described by a Poisson distribution with an average photon number of λ 0 ¼ 0:084 Þfor the 0 j i 1 j i ð Þ spin state (compare Supplementary Note 2). With this small contrast, the error of a single measurement, assuming again a symmetric hypothesis testing, is 0.49, even for orthogonal states (see Supplementary Note 4), i.e., we have a nearly 50-50 chance to assign the frequency incorrectly.
The probability to make an incorrect decision can be reduced in two ways: first, by increasing the number of measurements, which we refer to as ensemble averaging. Then, the difference in the number of emitted photons increases, which leads to better discriminability. The second approach is based on improving the readout process itself by increasing the contrast between the states. This can be achieved by introducing an ancilla qubit, which acts as a quantum memory and stores the state of the NV center 23,24 . This method is usually referred to as single-shot readout (SSR). We experimentally implement these two methods and compare their performance using the error probability as figure of merit. We show that by benchmarking against the number of detected photons, ensemble averaging always performs at least as good as SSR, but when compared in terms of measurement time or number of coherent interaction periods, SSR has particular advantages.
Temporal ensemble averaging was performed using a 1.35 NA oil objective, to collect the NV fluorescence and repeating the sensing and readout N ens times (compare Fig. 4a). Hence, given the orthogonal states and N ens repetitions of the measurement, the discrimination between the states reduces to discrimination between two Poissonian distributions: Poi N ens λ 0 ð Þand Poi N ens λ 1 ð Þ. Assuming small contrast, namely λ0 λ1 is close to 1, we observe that the error probability scales as expðÀN ens 0:5 ffiffiffiffi ffi plementary Note 4). For non-orthogonal states, the error probability also decays exponentially with N ens to 0 and the error where α is the angle between the states. Hence, given that the duration of a single ensemble average is τ (including the overheads for readout and initialization), the discrimination time with this strategy goes as $ τ 4 λ0þλ1 SSR is implemented by using a weakly coupled 13 C spin that forms a memory qubit and allows repetitive readout of the NV state with a quantum non-demolition (QND) experiment 25 (compare Fig. 4b and Supplementary Note 2). The ancilla qubit allows more photons to be scattered before its state is destroyed and here we perform N RR repetitive readouts after one sensing time. The larger N RR , the closer we get to a perfect quantum measurement, limited ultimately by the lifetime of the ancilla. For N RR = 10 4 , the photon statistics manifest digital step jumps, which allows high-fidelity readout of the nuclear spin state (see Supplementary Note 2). The discrimination between orthogonal states using this method is, in theory, a discrimination between Poi N RR λ 0 ð Þand Poi N RR λ 1 ð Þ, and thus given as N RR ¼ N ens , precisely the same as for ensemble averaging. Then, the only difference is the time required to perform readout of the nuclear spin and that SSR requires only one sensing period, which is discussed in more detail below. For non-orthogonal states however, this strategy is inferior as the error probability does not reduce to 0 in the limit of large N RR due to quantum projection noise. This additional uncertainty inherent to quantum measurements results in a scaling as 0:5 1 À j sin α ð Þj ð Þ(see Supplementary Note 1). We experimentally investigated the performance of both strategies by performing ensemble averaging and SSR for discrimination of the same signals described earlier. The error as a function of different parameters is plotted in Fig. 5a-e. In Fig. 5a, it is shown that for any angle α between the states (or equivalently, for any coherent interaction period), ensemble averaging performs better than SSR. However, in contrast to the theoretical expectation, we see that ensemble averaging yields a lower error than SSR also for orthogonal states (44 μs, φ Δ ¼ π). The reason for this is that, although the nuclear state can be readout with high fidelity in our experiments, imperfect initialization of the NV center into the correct charge state and the finite ancilla T 1 lifetime, limits the sensor readout fidelity to 0.8 (see Supplementary Note 2 and refs. 26,27 ). In Fig. 5a (red line), we plot the expected error achievable with SSR under perfect sensor initialization and control, which demonstrates the equivalence between the two readout methods when orthogonality is achieved. Figure 5b shows the discrimination error as a function of the number of photons detected with each readout technique, for a fixed interaction time of 44 μs (Δφ = π, dotted line in Fig. 5a). As the sensor is driven to an eigenstate, each photon should convey the same information about which frequency is present regardless of whether it was obtained from ensemble averaging or SSR. We observe that imperfect initialization reduces the information carried by each photon using SSR, resulting in the error converging to an offset of 0.2. By using charge-state detection to improve the sensor initialization, it is expected that a convergence in the two readout strategies would be observed.
However, SSR may still be useful if the total measurement time is taken into account. For ensemble averaging, every repetition cycle requires a duration of initialization t init ð Þ, interaction (t), and readout t read ð Þ; thus, the total measurement time is T ens ¼ N ens t init þ t þ t read ð Þ . For our experiments, t init þ t read % 1:5 μs. For SSR, only one initialization and interaction period are required, while readout is performed N RR times. The initialization and readout time for SSR are different to ensemble averaging, however, as manipulation of the ancilla is required; thus, the total Fig. 4 Experimental realization of the two readout strategies-ensemble averaging and SSR. a Ensemble averaging. The complete sequence of sensor initialization, sensing period, and optical readout is performed N ens times. b Single-shot readout (SSR). After one sensing duration, the sensor state is mapped onto the ancilla readout qubit ( 13 C nucleus). Optical readout of the ancilla spin is weakly perturbing, allowing its population to be probed N RR times with a quantum non-demolition measurement.
For our experiments, t anc init % 100 μs and t anc read % 17 μs, so for N RR > 10, most of the temporal overheads for SSR arise from readout of the ancilla spin via repeated mapping onto the NV electron spin (see "Methods"). For long interaction times (⪎17 µs), this overhead is less costly than repeating the interaction and SSR is faster than ensemble averaging, as shown in Fig. 5c.
In addition to performing only a single SSR measurement, we investigate the discrimination error when performing multiple SSR measurements. In Fig. 5d, the discrimination error is plotted as a function of the total time required by each readout strategy, including all measurement overheads. For SSR, the time is incremented by performing additional measurements, each using N RR = 10 4 repetitive readouts, which we in the following refer to as hybrid strategy, as many individual SSR are averaged, while for ensemble averaging just N ens is increased. Although about twice the number of photons is recorded for the hybrid strategy within the same time, ensemble average still performs better. The reason for this is that N RR is too large; we observe that by reducing N RR , the hybrid strategy can yield a smaller error as a function of time. For N RR = 10 3 , we find a slightly better scaling for the hybrid strategy using simulations, taking our measurement parameters into account (see Supplementary Note 4), as projection noise is sufficiently reduced. By further reducing to N RR = 10 2 , we find that the error exponent with the hybrid strategy is almost twice as large as the error exponent of ensemble averaging and there is a reduction of the overall error by a factor of 40 after measuring for 1 s. A more detailed analysis and optimization over N RR can be found in Supplementary Note 4. In addition to benchmarking against the total measurement time, we also compare in terms of the number of trials, (i.e. the number of times the signal is queried), which becomes critical if many interrogations are prohibited, e.g. due to sample contamination or degradation. As expected, the hybrid strategy performs significantly better, as a high confidence can be obtained from a single trial (Fig. 5e). In Fig. 5d, e the error decays exponentially with the total time (or equivalently number of queries) as expected, the error exponent for both methods is calculated explicitly in Supplementary Note 4.
It should be noted that these results apply to any problem with the aim to discriminate between two NV center states.
Qptimal frequency estimation using a quantum coherent probe A related task is to estimate a single unknown frequency ω of a signal H ω ð Þ ¼ B sin ωt þ θ ð Þ σ Z ¼ HðωÞσ Z with minimum uncertainty Δω. The variance Δω ð Þ 2 is lower bounded by the inverse of the quantum Fisher information (QFI) IðωÞ 28 : Notably, the QFI has a clear geometric meaning, as I(ω) can be written using the Bures distance d B between quantum states: where α ω À ωΔ 2 ; ω þ ωΔ 2 À Á is the angle between jψ ω ± ω Δ =2 ð Þ i . Hence, maximizing the QFI is equivalent to optimizing the discrimination of lim ωΔ!0 ψ ω ± ωΔ 2 À Á . As shown above, this means maximizing the accumulation of dH , which is achieved by applying π-pulses whenever dH dω changes sign. This optimal strategy is illustrated in Fig. 6a, where π-pulses The ideal SSR curve corresponds to perfect sensor initialization and mapping to ancilla. b Experimental frequency discrimination error as a function of detected photons for a single SSR measurement (orange) and ensemble averaging (lilac), for an interaction time of 44 µs φ Δ ¼ π ð Þ . Imperfect sensor initialization limits the error achievable with a single SSR measurement. c Frequency discrimination error as a function of total measurement time for a single SSR measurement (orange, N RR = 10 4 ) and ensemble averaging (lilac, N ens = 10 4 ). Each data point corresponds to a different interaction time. d Frequency discrimination error as a function of total measurement time, with a fixed interaction time of 44 µs φ Δ ¼ π ð Þ . Although for SSR (orange) the total time is incremented by performing additional measurements (each using N RR = 10 4 ), for ensemble averaging N ens is increased. Expected errors obtained from simulations for N RR ¼ 10 2 ; 10 3 ; 10 4 are included (solid blue, green, and yellow lines, see Supplementary Note 4). e Frequency discrimination error as a function of number of trials, i.e., number of times the signal is interrogated, with a fixed interaction time of 44 µs using many SSR (each using N RR = 10 4 , orange) or ensemble averaging (lilac). Error bars are 1 SD.
are applied at the antinodes of the signal with a spacing close to π ω . According to Eq. (3), it follows: The minimal uncertainty obtainable in a single experiment reads 16 : (8) and scales again as 1/t 2 due to the phase acceleration of the sensor. This is a special case of the analysis performed in refs. [16][17][18][19] and partially realized in ref. 15 without taking readout noise into account.
A further peculiarity is that the π-pulses should be applied close to the signal antinodes where dH dω changes sign, which is in contrast to amplitude estimation. We demonstrate the underlying intuition by recording spectra for the two edge cases-control started close to a signal node θ ¼ π 2 À Á or antinode θ ¼ 0 ð Þ. We again used XY8 sequences and chose the readout basis such that the final NV population reads P ¼ 0: Þ . When the π-pulses are placed at the signal nodes (Fig. 6b blue), the NV population P is maximal, but ∂P ∂ω vanishes; thus, although the sensor acquires maximal phase, it is insensitive to changes in the signal frequency. In contrast, for θ = 0 (Fig. 6b green), the sensor acquires minimal phase; however, small frequency changes lead to large population deviations (here, ∂P ∂ω À Á max % 10 7 Hz À1 , which corresponds to 2 4π À Á Bt 2 ). Assuming perfect quantum measurements, any measurement basis in the X-Y plane would be optimal, as they all saturate the QFI (see Supplementary Note 7). The imperfect readout of the NV center not only worsens the estimate, but also provokes a dependency on the measurement basis 29 . When using conventional readout of single NV centers, the fluorescence contrast is very low and the measurement noise barely varies with the measurement basis (see Supplementary Note 8). As a consequence, it is optimal to measure (approximately) in the basis that yields the maximal slope. In our case, assuming an initialization in the X basis, a maximal slope is obtained by measuring in the Ybasis and it follows (in the limit of small contrast, see Supplementary Note 8): Taking our experimental values of λ 0 , λ 1 into account, a factor of 40 in SD is lost. We realize experimental frequency estimation by measuring an unknown frequency ω (=999.3 MHz) oscillating close to 1 MHz with known amplitude (1.7 µT). Applying XY8 sequences with a pulse spacing of 500 ns and locking θ = 0, we use ensemble averaging N ens % 1000 ð Þ to estimate the frequency several thousand times for a variety of interaction times t (controlled by tailoring the π-pulse number). By computing the SD and assuming shot noise ffiffiffi T p -scaling, we are able to extract an estimate for the uncertainty Δω for a single measurement, which is plotted in Fig.  6c. As expected, there is a significant difference between X and Y readout (for initialization in X). Measurements in the Y basis saturate the bound in Eq. (9) and, in particular, Δω scales as t −2 . In contrast, measuring in the X basis leads to much higher uncertainties, due to the very small slope ∂P ∂ω . Interestingly, using SSR (here N RR = 10 4 ), the results almost coincide with the theoretical limits of perfect projective measurements (Fig. 6c  lower), namely a close agreement in uncertainty using X/Y measurements and an SD of 1.6 µHz/Hz 2 within a factor of 2 to the limit, 0.9 µHz/Hz 2 set by the QFI (Eq. (8), red line in Fig. 6c).
Estimation: consequences of short coherence time Finally, we address the relevance of this method to practical frequency estimation scenarios in NMR and communication.
Although the described protocol is optimal if both, the signal and the sensor, are perfectly coherent, any deviations require further analysis of the estimation strategies.
For signals with short coherence time, which are especially relevant in nanoscale NMR where influences of molecular diffusion Fig. 6 Optimal quantum-frequency estimation. a Maximal sensitivity to amplitude changes is obtained for π-pulses at the signal nodes θ ¼ π 2 À Á , resulting in a linear accumulation of φ. Maximal sensitivity to frequency changes is obtained for π-pulses at the signal antinodes (θ = 0). b Experimental data of the phase difference for a 1 µT change in amplitude (red) and 10 kHz change in frequency (black). Frequency estimation results in a quadratic increase of φ, whereas amplitude estimation produces a linear increase. c Measured NV population as a function of π-pulse spacing τ π , given θ ¼ π 2 (blue) and θ = 0 (green). Fits correspond to Supplementary Eq. 39. d Measured derivative of the NV population as a function of π-pulse spacing τ π , given θ ¼ π 2 (blue) and θ = 0 (green). Fits correspond to Supplementary Eq. 41. e Measured frequency uncertainty as a function of interaction time, for X (dark purple) or Y (light purple) measurement basis. Red line corresponds to Eq. (8) and pink line to Eq. (9). f Measured frequency uncertainty as a function of interaction time, for X (dark orange) or Y (light orange) measurement basis using a single SSR measurement. Red line corresponds to Eq. (8). g Frequency estimation for short coherence signals (for ensemble averaging): measured frequency uncertainty given θ ¼ π 2 (blue), θ = 0 (green), and unknown initial phase (gray) for a single measurement with interaction time shorter than the signal coherence time (200 µs). For longer times, the sensitivity is obtained from averaging multiple measurements, each with an interaction time of 97 µs. and nuclear couplings limit the coherence of the NMR signal 6,30 , the described protocol remains optimal, as it provides the most information per individual measurement (and correlations are not possible). As shown in Fig. 6d, the frequency can be estimated with an SD improving as t −2 during one sensing period, where a timing of θ = 0 (green) provides three orders of magnitude improvement in SD compared to θ = π/2 (blue). The estimate can be further improved by performing multiple measurements up to a total measurement time T, albeit with a reduced T −1/2 scaling, typical for incoherent averages. We compute sensitivities, which are here defined as η ¼ Δω ffiffiffi T p of 58 Hz/Hz 0.5 for θ = 0 and 23 kHz/ Hz 0.5 for θ = π/2. If the signal phase is not known a priori, we cannot apply pulses at the right timing. Nevertheless, using adaptive measurements, the t −2 uncertainty scaling can be preserved, albeit with a higher uncertainty Δω. In Fig. 6d (gray), the frequency SD is plotted where the spacing τ π was updated for each interaction time and the measurement was averaged over all signal phases (see Supplementary Note 10). Using this strategy, the frequency can be estimated with an order-of-magnitude reduction in uncertainty and sensitivity (here η = 630 Hz/Hz 0.5 ), but without the need to know the starting phase.
In the other limit, the coherence time of the sensor is much shorter than the coherence time of the signal. It has recently been shown that applying a chain of consecutive, correlated, measurements can enhance frequency estimation in this case 19,22,31,32 . Due to the stability of the phase of the signal, the amount of information gained from late measurements is much larger than the information gained from early ones. Hence, by employing the signal coherence, the T 4 scaling of the QFI, which relies on the coherence of the sensor, degrades to T 3 . Without any control, the QFI in this regime reads (compare ref. 19 ): where the decay prefactor: sinc ωt=2 ð Þ 2 cos ωτ þ ωt 2 þ φ À Á 2 stems from the oscillations of the signal slope. This term can be suppressed by applying π-pulses close to the antinodes and the ultimate limit of the QFI in this regime reads (compare Supplementary Note 11): Hence, the scaling is the same as without control B 2 T 3 t ð Þ; however, there is a difference of $ 0:56ωt, which can be significant for high frequencies (taking relevant experimental values, ωt $ 20, it follows that a factor of~10 is lost in the absence of control). Here again, the timing of the pulses is crucial. Applying resonant pulses generally leads to: ð Þ 2 (see Supplementary Note 11). As a consequence, IðωÞ vanishes for θ = π/2 and is maximal for θ = 0. More generally, applying pulses with a general timing (θ) and a general detuning δ (defined as ω À π=τ π , where τ π is the spacing between the π-pulses), leads to: It is noteworthy that in the limit of δt ( 1; δT ) 1 (which was implemented in ref. 19 ), only a factor of 1/2 is lost, compared to the optimum, due to the detuning. Hence, in this regime, the maximal achievable advantage, compared to the results in ref. 19 , is a factor of 2.

DISCUSSION
We introduced a quantum mechanical detection scheme, which achieves a quadratic increase in the sensor phase, while simultaneously reducing measurement noise, to allow frequency discrimination with a single measurement. We derived the fundamental error limit in Hamiltonian discrimination and achieved it experimentally with a suitable control. This method can provide a significant speed-up in diagnostic tests based on single quantum sensors, such as nano-NMR. In addition, we have described optimal frequency estimation strategies dependent on the readout method, and using near-ideal measurements, we obtain a frequency uncertainty near the quantum limit. If the signal phase is known, the best frequency estimate is obtained when control is started close to a signal antinode, in contradiction to methods that optimize amplitude sensitivity. These findings should prove useful in NMR, where a π/2-pulse on the sample defines the signal phase 30,31 . When the signal phase is unknown, an improved scaling can be maintained using an adaptive approach. Applications for these techniques include quantum spectroscopy and spectrum analyzers 33 , characterization of quantum systems, search for dark matter, and construction of improved frequency standards.

Experimental setup
An arbitrary waveform generator (Tektronix AWG70001A) with 20 ps timing resolution and 8 bit amplitude resolution was used for microwave control of the NV center and to generate signals of well-defined frequency and phase. Before every measurement, possible phase shifts due to different cable lengths and microwave switches and combiners were compensated for. The signal amplitude at the NV center was calibrated prior to every measurement with a standard XY8 measurement. For the fluorescence detection, we used only the first 350 ns, as we found that this duration optimizes the signal-to-noise ratio for our experimental setup.

Diamond samples
All QND measurements were performed on a diamond with 0.1% 13 C content 25 . NV centers in this diamond have long-phase memory times (~50 µs), while maintaining a high probability to find weakly coupled 13 C spins. For all other experiments, a hemispherical diamond polished into a solid immersion lens provided a higher photon detection efficiency. On the flat surface, an isotopically enriched diamond layer (99.999% 12 C) containing NV centers was grown by a plasma-enhanced chemical vapor deposition process, as in ref. 34 . The diamond was boiled in a 1 : 1 : 1 tri-acid mixture (H 2 SO 4 : HNO 3 : HClO 4 ) for 4 h at 130°C before experiments.

Readout statistics
For ensemble averaging, a single measurement was defined as a single interaction time followed by a single laser pulse, repeated N ens times. The readout noise, δ SN was determined by performing a few thousand subsequent, identical measurements and recording fluctuations from the average fluorescence intensity. For SSR statistics, a single projective measurement was performed after each interaction time. The nuclear spin state was measured with N RR repetitive mapping operations which, based on the overlap of the photon intensities, results in a readout fidelity higher than 99% for N RR = 10 4 . Fluctuations in the readout state from a few thousand subsequent identical measurements was used to determine the SD, respectively.

Discrimination analysis
For y-basis readout, the probability P for the NV to remain in its initial 0 j i state is P ¼ sin 2 π 4 À φ 2 À Á (see Fig. 2d). This formula was also used to calculate the phase accumulation as shown in Fig. 2c. For ensemble measurements, detection of a fluorescence level above or below a threshold value determined the frequency assignment. For SSR, the frequency was assigned dependent on the readout state, which was determined from a normalized fluorescence measurement (see Supplementary Note 2).

DATA AVAILABILITY
The data that support the findings of this study are available from the corresponding author upon reasonable request.

CODE AVAILABILITY
Codes are available upon request from the authors.