Accurate magnetic field imaging using nanodiamond quantum sensors enhanced by machine learning

Nanodiamonds can be excellent quantum sensors for local magnetic field measurements. We demonstrate magnetic field imaging with high accuracy of 1.8 \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\upmu $$\end{document}μT combining nanodiamond ensemble (NDE) and machine learning without any physical models. We discover the dependence of the NDE signal on the field direction, suggesting the application of NDE for vector magnetometry and the improvement of the existing model. Our method enhances the NDE performance sufficiently to visualize nano-magnetism and mesoscopic current and expands the applicability of NDE in arbitrarily shaped materials, including living organisms. This accomplishment bridges machine learning to quantum sensing for accurate measurements.

Local detection of magnetic fields is crucial for characterizing nano-and micro-materials and has been implemented using various scanning techniques [1,2] or even diamond quantum sensors [3][4][5][6][7].Diamond nanoparticles (nanodiamonds) offer an attractive opportunity to achieve high spatial resolution because they can easily be close to the target within a few 10 nm simply by attaching them to its surface [8].A physical model for such a randomly oriented nanodiamond ensemble (NDE) is available [8], but the complexity of actual experimental conditions still limits the accuracy of deducing magnetic fields.Here, we demonstrate magnetic field imaging with high accuracy of 1.8 µT combining NDE and machine learning without any physical models.We also discover the field direction dependence of the NDE signal, suggesting the potential application for vector magnetometry and improvement of the existing model.Our method further enriches the performance of NDE to achieve the accuracy to visualize mesoscopic current and magnetism in atomic-layer materials [9][10][11][12][13] and to expand the applicability in arbitrarily shaped materials [7], including living organisms [14,15].This achievement will bridge machine learning and quantum sensing for accurate measurements.
The nitrogen-vacancy (NV) center in diamond [Fig.1(a)] is a point defect where a nitrogen atom replaces a carbon atom in the lattice accompanied by a neighboring vacancy.
By measuring its photoluminescence intensity while irradiating the laser and microwaves, NV's electron spin resonance can be detected, which is called optically detected microwave resonance (ODMR) [16].As the NV's spin level splits against the magnetic field in the direction of the NV symmetry axis (111) due to the Zeeman effect [17], the determination of the ODMR frequency serves as quantum sensing of the field [3].To obtain a nanoscale spatial resolution, we must attach the NV centers close to the sample within a few 10 nm [18].For this purpose, scanning techniques using diamond probes [4,19] or attachments of micro-fabricated diamond pieces [20,21] are used.
The nanodiamonds (ND) could be an alternative to realize a similar adjacency [8].ND is a diamond crystal with a diameter of 5-200 nm harboring NV centers [14].Since it enables us to adhere NV centers to any materials with arbitrary shapes by simply dropping NDs dispersed in a liquid, it has been applied to the measurement of electronic devices [8].
Figure 1(b) shows our setup [22] to precisely measure the magnetic field dependence of the ODMR spectrum of NDE.A three-axis Helmholtz coil is used to adjust the magnetic field with a precision of ±0.12 µT.After the ODMR measurement, the magnetic field exactly at the sample location is determined with a tesla meter (Lake Shore Cryotronics F71).
Hereafter, this field value is referred to as the true magnetic field.
The magnetic field dependence of the ODMR spectrum of NDE (Method) on a cover glass is shown in the image plot of Fig. 1(c).This result is obtained from a total of one million NV centers contained in about 30,000 NDs.The spectrum is measured at 751 points from 6 µT to 2286 µT with a field applied in the optical (z-axis) direction.The spectrum shape becomes broadened with two dips as the field increases due to Zeeman splitting, and the ODMR contrast degrades.This behavior reflects the fact that the crystal axes of each ND are random, resulting in different resonance frequencies of NV centers.
The spectrum is deformed for many reasons, such as the excitation efficiency, the light collection efficiency, the direction of the microwave and light polarization, etc., making it difficult to build an effective model for accurate magnetic field determination.For example, we fit the spectrum obtained at the true magnetic field of 547.1±0.12 µT with an existing physical model that considers the experimental configuration (Method) [8], which yields an estimated field of 582.2±4.4 µT, a statistically inaccurate value.This observation exemplifies the problem of hindering accurate local magnetometry using NDE.While NV centers are known to show very high sensitivity to the magnetic field -how sensitive the signal changes depending on the field modulation-, the relevance of the accuracy achieved by them, that is, trueness of the measured value, has been less emphasized.In this work, we focus on accuracy.
We solve this problem using Gaussian process regression (GPR), a model-free machine learning method.Our idea is shown in Fig. 1(d).The ODMR spectrum and the true magnetic field in Fig. 1(c) are used for training as the input variable x i and output variable y i , respectively, and the function f (x) is obtained to estimate the magnetic field from an arbitrary spectrum x.GPR is a flexible and nonparametric machine-learning protocols commonly applied to function estimation [23][24][25].It is characterized by the kernel function k(x, x ′ ), which represents the degree of agreement between two input variables x, x ′ .We adopt the most widely used kernel function which is known as the squared exponential kernel.The only two hyperparameters are the variable θ and the noise of the acquired data β −1 (Method).For a robust analysis, we normalize the contrast of the ODMR spectrum and use the data after taking the first derivative for frequency as the input variable.
The red curve in Fig. 2(a) shows the prediction of the magnetic field using the training data itself as the input variable x ′ for checking the regression process.The vertical axis is the difference between the repredicted magnetic field and the true magnetic field.The light purple area is the standard deviation of the reprediction, which indicates the uncertainty of the GPR prediction of the magnetic field from the ODMR spectrum.The repredicted field agrees with the true field within a standard deviation range of approximately ±10 µT.
To confirm that GPR can work for quantum sensing, we deduce the estimation accuracy for a test data set not used for training.The procedure corresponds to the evaluation of generalization performance in machine learning.Figure 2(b) shows the magnetic field predicted by the GPR from the test data reacquired by the NDE on the cover glass as the red circle, indicating that the predicted field is perfectly consistent with the true one regarding the z-direction.Figure 2(c) shows the difference between predicted and true values as red circles more quantitatively.The predicted values encompass the true values within their statistical uncertainty for a wide magnetic field range.Taking the case mentioned above as an example, when the true value is 547.1±0.12 µT, machine learning yields 556.1±9.5 µT.
On the other hand, the fields estimated from the model fitting (blue cross) deviate from the true ones statistically and systematically.These results demonstrate our approach's robust and superior accuracy compared to the model-based method.
We then verify whether GPR works for NDE on different materials.As the training data, we use the data of the NDE on the cover glass as before.Figure 2(d) shows the corresponding result obtained from the NDE on the silicon wafer.Again, the GPR yields a statistically more reliable estimation than the model.We note that the magnetic field derivation is more subtle in this silicon case than in the above glass case because the frequency dependence of the microwave antenna, which is difficult to be determined experimentally, is more delicate (Supplementary Information).This confirms that GPR is applicable even when it is impossible to prepare training data, such as NDE spread over magnetic materials.
So far, we have discussed only the case of applying a magnetic field in the z-direction.
Despite the isotropic distribution of NDs over the surface in the xy plane, the ODMR spectrum can be anisotropic concerning the field direction for several reasons, such as the numerical aperture of the objective lens (Supplementary Information).Figure 2(b) also depicts the predicted magnetic field when applying the magnetic field in the x-, y-, and z-directions.The data with the magnetic field applied in the z-direction is used as the training data for all predictions.The results systematically deviate from the true magnetic field when applying the field in the x-and y-directions, different from the training data.
The observed anisotropy is profitable because it suggests vector field sensing with NDE.In principle, the contribution of each directional component is tunable by changing the objective lens' numerical aperture or the direction of the excitation light's linear polarization; The magnetic field vector can then be determined by combining these data.Importantly, our finding directly points to improving the existing model.
We can easily suppress this direction dependence to a negligible amount by applying a bias magnetic field in the z-direction.We measure the magnetic field generated by the current flowing through the copper wire under the cover glass as a demonstration.Figure 3(a) shows the magnetic field distribution when 800 mA is applied to the copper wire with a bias field of 912.8 µT in the z-direction.We observe that the magnetic field becomes larger as the position gets closer to the copper wire, consistent with Ampere's law.For a more quantitative evaluation, the average value of the magnetic field in the y-direction is shown in Fig. 3(b).The fitting results based on Ampere's law plus the bias field are consistent with the experimental results within the error bars.
Finally, we evaluate the accuracy and sensitivity achieved in our method when the field is applied in the z-direction.We calculate the difference between the true magnetic field and the predicted value from the test data for each pixel (17×22 pixels, 1 pixel ≈ 18 µm 2 ), as well as the standard deviation σ.The integration time t dependence is also obtained for each field.In this analysis, the integration time of both training and test data is varied similarly.
As shown in Fig. 4 In summary, we demonstrate the accurate local magnetometry by the machine-learningenhanced NDE method.The obtained high accuracy and sensitivity are sufficient for the magnetic imaging of a few layers of the van der Waals materials [9][10][11][12][13] and topological materials [27,28].This method applies not only to such topics in condensed matter physics but also to arbitrary-shaped objects such as living organisms [14,15].The present idea is further promising in applying temperature, electric field, and pressure measurements by using NDE [26,[29][30][31].

METHOD Experimental setup
A laser beam (515 nm, 150 mW) is output through a multimode fiber and a collimator into the free space.It is expanded by a lens pair before entering the objective lens (Mitsutoyo M-PLAN APO 100X, numerical aperture NA=0.7, magnification 100x).The irradiated area of the excitation beam at the focal point is approximately 400 µm in diameter.The NV center's fluorescence is acquired by a CMOS camera (basler acA720-520um, 12-bit resolution) after passing through an objective lens, a dichroic mirror, a 514 nm notch filter, a 650 nm longpass filter, an 800 nm short-pass filter, and an imaging lens.The magnetic field generated in the three-axes Helmholtz coil, including the geomagnetic field, is calibrated with a tesla meter (LakeShore Cryotronics F71) to an accuracy of ±0.12 µT.
The NDE spread on the cover glass is fixed with carbon tape on the resonator microwave antenna [32].ODMR measurements are performed by inputting 25 dBm microwave power to the antenna.
The ODMR spectra are acquired with a frequency resolution of 141 points equally spaced between 2720 and 2990 MHz.The exposure time is set to 8 ms, and the frequency sweep is repeated 70 times (8 ms×141×70 in total).
In the measurement shown in Fig. 4, a copper wire with a diameter of 50 µm is placed along the y-axis direction.A magnetic field is generated by applying a current [Fig.4 GPR is a process that estimates a function for input and output variables [33].As training data, we prepare n pairs of input variable vector x i and output scalar variable y i .When the input data is x ′ , the predicted output value f (x ′ ) is given by, where I is an identity matrix, y is a column vector with y i as its i th entry, k(x ′ ) is a column vector with k(x i , x ′ ) as its i th entry, and K is an n × n matrix with K i,j = k(x i , x j ) as its (i, j) th entry, β −1 is the noise intensity on the output variable y.In this case, standard deviation v(x ′ ) [confidence area of Fig. 2(a)] is given by In this study, x i and y i are the ODMR spectra shown in Fig. 1(c) and the magnetic field strength obtained with a tesla meter, respectively.The optimization of the hyperparameters is performed by the minimization of five-fold cross-validation loss using the MATLAB Statistics and Machine Learning Toolbox.According to Eq. ( 2), the magnetic field f (x ′ ) is predicted by calculating the similarity between the ODMR spectrum x ′ and each training data.

Fitting Model
We use an existing model of the direction dependence of the ODMR spectrum of the NV center [8].The electron spin Hamiltonian of the NV center is given by, Ĥ = D Ŝ2 z + E( Ŝ2 x − Ŝ2 y ) + γB Ŝz , where Ŝx,y,z is the x,y,z component of the spin-1 operator, D is the zero-field splitting, E is the lattice strain, γ is the gyromagnetic ratio of an electron spin, B is the magnetic field strength.At a magnetic field strength of about a few mT, the two resonance frequencies of the NV center can be approximated as f ± = D± E 2 + (γB) 2 .The resonance shape of each NV center is approximated as the Lorentzian , where f mw is the applied microwave frequency, f ± , δν ± , C ± are the resonance frequencies, linewidths, and ODMR contrasts, respectively.obtain ODMR spectrum S(f mw ) as, where, ) is the light absorption efficiency.Equation ( 4) is used to obtain "model" in Figs.2(c) and (d).tenna.We use a broadband, large-area microwave antenna [32] to apply a spatially uniform microwave.The frequency characteristics are affected by the conductivity and dielectric constant of the surrounding material.S11 for each measurement condition is shown in Fig. S2.
A low S11 indicates less antenna reflection and stronger microwave radiation.The smallest S11 frequency corresponds to the resonance frequency.The resonance frequency on the glass is 2.88 GHz, almost the same as the center of the ODMR spectrum.The further away from the center of the ODMR spectrum is, the weaker the microwaves become.This leads to an underestimate of the Zeeman splitting and reduces the accuracy of the physical model.
Actually, as shown in Fig. 2(c) in the main text, the physical model gives a lower field value than the true value at high fields (> 1500 µT).On the other hand, the resonance frequency on silicon is 2.97 GHz, which is higher than that on glass.Due to this effect, the ODMR spectrum is shifted to the high-frequency side than it should be.Since the shift depends on frequency, it also affects the estimation of magnetic field strength.
For example, Fig. S3(a) presents the ODMR spectrum obtained in a true magnetic field of 1920 µT.The spectrum of NDE on silicon has a larger contrast on the high-frequency side than that on glass, being consistent with the characteristics of S11.The result on glass shows that the center of the spectrum is on a lower frequency than that on silicon.In the present experiment, black tape is placed underneath the substrate (glass or silicon) for fixing and reducing laser reflection.The different thermal conductivity of glass and silicon contributes differently to the heating, resulting in different spectrum shifts.
We can easily correct the frequency shift caused by these sources.Figure S3(b) depicts the result of the analysis by incrementally adding a shift to the frequency of the training data.Without any correction (0 MHz), the prediction error is as large as about 150 µT.
When the shift of about +6 MHz is incorporated, the prediction error decreases to about 50 µT.The silicon data in Fig. 2(b) in the main text results obtained by applying this appropriate correction.

Physical model for the ODMR spectrum
We describe the physical model for describing the ODMR spectrum of NDE following Ref.[8].We consider the resonance frequency, the shape of the resonance, the light absorption efficiency, and the photon collection efficiency.
When the magnetic field is parallel to the NV center's symmetry axis (NV axis), the electron spin Hamiltonian of the NV center is given by, where Ŝx,y,z are the x,y, and z components of the spin-1 operator, respectively, D is the zero-field splitting, E s is the lattice strain, γ is the gyromagnetic ratio of an electron spin, and B is the magnetic field strength.At a magnetic field strength of a few mT, the two resonance frequencies of the NV center can be approximated as , where f mw is the applied microwave frequency, C is the contrast, and δν is the linewidth.
We carefully define the experimental situation to account for absorption and collection efficiency.Figires S4(b) and (c) define the unit vector parallel to the NV axis e NV with the polar angle θ NV and the azimuthal angle ϕ NV in the Cartesian coordinate system with the optical axis in the z-axis.For simplicity, we only show the case where the magnetic field is applied in the z-axis [Fig.S4(a)], as in previous study [8] and training data measurements.
The light absorption efficiency is proportional to the square of the inner product of the optical transition dipole moment of the NV center and the electric field of the excitation light.The optical transition dipole of the NV center originates from the mixed orbital [26] and has components parallel to the two orthogonal unit vectors p 1 and p 2 .Hereafter, we treat the case as a classical electric dipole moment for simplicity.Despite the C 3υ symmetry of the NV center, the NV center exhibits an axisymmetric response to linear polarization [34].
Assuming that dipole moments are equivalent in the any perpendicular direction to the NV axis, we define them as [Fig.S4(c)], where e x , e y , and e z are the unit vectors parallel to x-, y-, and z-axis, respectively.The electric field E only in the x and y directions is applied to the NV center with the Köfler type illumination [Fig.S4(a)].We get the absorption efficiency κ as, where E = E x e x + E y e y .The absorption efficiency is higher when the NV axis is parallel to the optical axis.This means that photons coming from the direction of the NV axis are absorbed better.
The photon collection efficiency is also determined by the electric dipole moment [35].The energy of light emitted from a point dipole p to a position r well away from its wavelength is, where r = re r = r(cos φ r sin θ r e x + sin φ r sin θ r e y + cos θ r e z ).The light is more likely to be emitted perpendicular to p, i.e., in the direction of the NV axis.The measurable angle of an objective lens is determined by NA= sin θ max [Fig.S4(d However, this is not the case at a high field (B = 2103 ± 0.12 µT) [Fig.S5(b)].This difference indicates that the complexity of the experimental conditions is not fully reflected in the model.Specifically, we describe two contributions as follows.First, as mentioned in the previous section, the frequency dependence of the microwave strength radiated from a resonator-type microwave antenna exists.Since the resonance spectrum of an NDE is continuous over a wide range, even a small frequency dependence of the antenna distorts the spectral shape.Second, microwave absorption is dependent on the directions [Fig.S4(e)].
It is easy to absorb the microwave field of the component perpendicular to the NV axis.The contrast of the NV center, which is oriented in the same direction as the microwave field, is reduced, resulting in inaccurate magnetic field estimation.
In this physical model, the magnetic field direction is assumed to be in the optical (z-axis) components and an additional one cause of the difference in the x-and y-directions.We explain these four causes in order below.
The first is the absorption efficiency of the NV center.Due to Köfler type illumination, the NV symmetry axis in the z-direction (θ N V = 0) is easily excited.
The second is the light collection efficiency [35].The objective lens has a better light collection efficiency in the z-direction, and the NV has a high photon emission probability in the direction of the NV symmetry axis.
The third is the angular dependence of the microwave absorption efficiency, as shown in Fig. S4(e).The microwave field perpendicular to the NV symmetry axis drives the NV center's magnetic resonance [34].In our experiment, we apply linearly polarized microwaves in the z-direction, so it is easy to obtain ODMR contrast of the NV center in the x and y directions.This is the opposite contribution to the first and second causes.
The fourth is the difference in the absorption efficiency due to the linearly polarized component of the excitation light.The NV center is more easily excited when its symmetry axis is perpendicular to linear polarization than in the parallel case.Since the excitation (a), as the integration time for the test data increases, the standard deviation decays.The accuracy ζ and sensitivity η are obtained by fitting σ(t) = ηt −0.5 + ζ, taking into account the shot noise due to photon counting.Note that the accuracy ζ is less than the above uncertainty of the function estimation (∼ 10 µT ), since ζ = lim t→∞ σ(t).The magnetic field dependence of the accuracy and the sensitivity are shown in Figs.4(b) and 4(c), respectively.The better the accuracy and sensitivity are, the lower these values are.The accuracy [Fig.4(b)]degrades at low field (< 500 µT) and high field (> 2000 µT).These behaviors are inevitable due to the nature of the NV center.There is only a tiny change in the spectrum at low fields [see Fig.1(c)] because splitting the ODMR spectrum due to the lattice strain obscures the magnetic field dependence[26].The accuracy is not good at high fields due to the decrease in the ODMR contrast because of the random distribution of NV axes in NDE.The sensitivity [Fig.4(c)] also shows this tendency at high fields.The sensitivity at low fields is almost zero, which is simply an artifact due to the low resolution for integrated time [see Fig.4(a)].As a result, we achieve the best accuracy of about 1.8 µT under the field of 1000-1500 µT with a sensitivity of ∼ 70 µT/ √ Hz.
NDs with a standard particle size of 50 nm (NDNV50nmHi10ml, Adámas Nanotechnologies) containing about 30 NV centers per particle are used.5 µg of NDs in 5 µL of water are dispersed by ultrasonication and then dropped onto cover glass (130 µm thick, Matsunami Glass Ind.,Ltd.) and dried with a spin coater rotating at 500 rpm for 2000 seconds.The thickness of NDE is obtained to be 200 nm (about 4 layers) by measuring with a profilometer (KLA-Tencor P-7).This value corresponds to about 30,000 NDs and about 1 million NV centers per image pixel (18 µm 2 ).The fabricated NDE looks like a white film due to light scattering under an ambient light.The NDE on silicon is spread with the spin coater at Gaussian Process Regression

FIG. 1 .FIG. 2 .
FIG. 1. Application of machine learning to diamond quantum sensors.(a) Schematic of a nitrogen-vacancy (NV) center in diamond.(b) Experimental setup.The optical axis is the z-axis, and the NDE is spread on the surface in the xy-plane.(c) Experimentally obtained ODMR spectra of NDE as functions of the microwave frequency and the magnetic field.The true magnetic field is measured using a tesla meter.(d) Schematic of our machine learning method.The ODMR spectrum and the true magnetic field of (c) are used as the input vector x i and output scalar y i for training.Using GPR, a function is obtained from the training data to predict the magnetic field strength |B| = f (x ′ ) from an unknown spectrum x ′ .

( a )
Benchmark of reprediction by GPR.The horizontal axis is the true magnetic field, and the vertical axis is the difference between the repredicted field and the true field.The light purple region is the standard deviation interval.(b) Dependence of the predicted magnetic field on the magnetic field directions.The black line is the ideal value where the predicted and true magnetic fields perfectly match for the z-direction.(c)(d) The detail of the prediction accuracy for the NDE on the cover glass (c) and on the silicon.We use only the training data when the field is applied to the z-direction.The difference between GPR predicted and true field shows as Red circle.The fitting result using the physical model shows as blue cross.These errorbars depict 68% confidential interval.Note that we have corrected the data for NDE on silicon regarding the heating of the material (see Fig.S2for detail).

FIG. 3 .
FIG. 3. Machine-learning-enhanced magnetic field imaging.(a) Magnetic field distribution when a current of 800 mA is applied to the copper wire, which is placed along the y-direction.The horizontal axis is the distance to the x-direction when the copper wire is placed at x = 0 µm.(b)The average magnetic field value against the y-axis direction in (a).The solid curve is the result of the fitting based on Ampere's law.(inset) Measurement configuration, where the bias field applied in the z-direction and the field generated by the current through the wire are simultaneously felt by the NDE.

|S|r 2
Figures S5 (a) and (b) show two examples of the fitting to the physical model.While the estimated magnetic field deviates from the true value, the model seems to reproduce the experimental spectrum at a low field reasonably (B = 547.1 ± 0.12 µT) [Fig.S5(a)].
direction.If the magnetic field direction deviates from the z-axis [Fig.S4(f)], the dependence on the azimuth angle needs to be considered [Fig.S4(g)].The light absorption efficiency and photon collection efficiency must be integrated against the azimuth angle at the same time with the resonance shape, making the analytical calculation more difficult.The actual effects that can occur are discussed in the next section.Directional dependence of predicted magnetic fieldWe observe three-dimensional field direction dependence of ODMR spectra [see Fig. 2(b) in the main text].There are three causes of the GPR prediction difference in the z-and xy- FIG. S1.Standard deviation of the difference between the true and the predicted magnetic field at all pixels.The measurement accuracy increases as the histogram shifts to the left of the graph.The magnetic field ranges are (a) 0-500 µT, (b) 500-1000 µT, (c) 1000-1500 µT, (d) 1500-2000 µT, and (e) 2000-2500 µT.
FIG. S6.Magnetic field distributions at currents of (a) 200 mA, (b) 400 mA, and (c) 600 mA.Scale bar is 20 µm.(d) Photoluminescence intensity distribution.(e) Magnetic field distribution averaged in the y-direction for 200 mA, 400 mA, 600 mA, and 800 mA.The data for 800 mA is the same as shown in Fig. 3(b) in the main text.The colored solid lines are the fitting based on Ampere's law.The horizontal black solid line indicates the bias field strength.(inset) Measurement configuration, where the bias field applied in the z-direction and the field generated by the current through the wire are simultaneously felt by the NDE.