==== Front Sci Rep Sci Rep Scientific Reports 2045-2322 Nature Publishing Group UK London 37386118 37731 10.1038/s41598-023-37731-8 Article A Monte Carlo algorithm to improve the measurement efficiency of low-field nuclear magnetic resonance Guo Pan guopan@cqnu.edu.cn 1 Zhang Ruoshuang 1 Zhang Jiawen 1 Shi Junhao 1 Li Bing 2 1 grid.411575.3 0000 0001 0345 927X College of Physics and Electronic Engineering, Chongqing Normal University, Chongqing, China 2 grid.433158.8 0000 0000 8891 7315 Urumqi Power Supply Company, State Grid Xinjiang Electric Power Co, LTD, Urumqi, China 29 6 2023 29 6 2023 2023 13 1053325 1 2023 27 6 2023 © The Author(s) 2023 https://creativecommons.org/licenses/by/4.0/ Open Access This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons licence, and indicate if changes were made. The images or other third party material in this article are included in the article's Creative Commons licence, unless indicated otherwise in a credit line to the material. If material is not included in the article's Creative Commons licence and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this licence, visit http://creativecommons.org/licenses/by/4.0/. Nuclear magnetic resonance (NMR) has shown good applications in engineering fields such as well logging and rubber material ageing assessment. However, due to the low magnetic field strength of NMR sensors and the complex working conditions of engineering sites, the signal-to-noise ratio (SNR) of NMR signals is low, and it is usually necessary to increase the number of repeated measurements to improve the SNR, which means a longer measurement time. Therefore, it is especially important to set the measurement parameters appropriately for onsite NMR. In this paper, we propose a stochastic simulation using Monte Carlo methods to predict the measurement curves of T1 and D0 and correct the measurement parameters of the next step according to the previous measurement results. The method can update the measurement parameters in real time and perform automatic measurements. At the same time, this method greatly reduces the measurement time. The experimental results show that the method is suitable for the measurement of the self-diffusion coefficient D0 and longitudinal relaxation time T1, which are frequently used in NMR measurements. Subject terms Energy science and technology Engineering Physics http://dx.doi.org/10.13039/100014717 National Outstanding Youth Science Fund Project of National Natural Science Foundation of China No. 51707028 Guo Pan http://dx.doi.org/10.13039/501100005230 Natural Science Foundation of Chongqing No. cstc2021jcyj-msxmX0470 Guo Pan Science and Technology Funds of Chongqing Municipal Education CommissionKJQN202100533 Guo Pan Innovation and entrepreneurship training program for college studentsS202210637053 Guo Pan issue-copyright-statement© Springer Nature Limited 2023 ==== Body pmcIntroduction Nuclear magnetic resonance (NMR) can be used to explore the structure and properties of substances from the microscopic level through non-destructive methods and is now widely used in the fields of medicine, chemistry, materials, biology, petroleum, geology1, etc. The application of portable NMR sensors and unilateral magnetic resonance devices has attracted the attention of many researchers2–5. However, the low magnetic field strength and uniformity and complex working conditions result in a low signal-to-noise ratio (SNR), long measurement time and low measurement efficiency. These are currently urgent problems that need to be solved. A more effective way is to optimize the measurement process and set the measurement parameters appropriately to improve the efficiency. There are some reports on the parameter optimization algorithm in NMR measurements. Some scholars have noticed the influence of the magnetic resonance measurement parameters on the measurement results, but their research mainly focuses on the frequency domain6–9, that is, exploring the data acquisition method that can reduce the measurement time and ensure that the frequency domain inversion spectrum has sufficient precision10–14. In 2017, Xing D. et al.15 presented an adaptive method for determining an acquisition parameter t0 in a modified CPMG sequence for measuring the internal magnetic field gradient distribution of samples. This method can reduce the difficulties of operating T2-G experiments. In 2018, A. Reci16 proposed an optimization method for the measurement parameters of the NMR liquid self-diffusion coefficient based on the Cramér-Rao lower bound (CRLB) theory, which assumes that the self-diffusion coefficient of the sample satisfies the log-normal distribution. In 2019, A. Reci 17 further improved the sampling method based on CRLB theory, making it also applicable to signal acquisition with double exponential decay. In 2021, Guest et al. studied the relationship between the experimental parameters and SNR for diffusion coefficient measurement18. In recent years, NMR has been widely used in industrial automation19,20, but few studies have provided a more general time-domain sampling strategy for T1 and D0 measurement experiments in on-site NMR. At the same time, some users of NMR instruments may not have background knowledge of the NMR principles, so it is difficult for them to adjust the measurement parameters. Therefore, automatic and intelligent measurement algorithms are wanted by users. In this paper, we introduce a Monte Carlo algorithm-based intelligent search method for NMR measurement parameters. This method can automatically set the key parameters in the T1 and D0 measurements. The experimental results demonstrate that the method could achieve a 3–4 times acceleration effect in the T1 and D0 measurement experiments, and the systematic error between the results and the accurate value was less than 5%. Algorithm introduction Introduction to the Monte Carlo method The Monte Carlo method, also known as the statistical simulation method, is a numerical calculation method guided by probabilistic statistical theory21–29. The characteristic of this method is the random sampling of the measurement variable, and an approximate result is calculated in real time for the NMR measurement constrained with the available dataset. In this paper, an intelligent search method for NMR measurement parameters based on the Monte Carlo algorithm is proposed to achieve the measurements of T1 and D0. Measurement sequence Figure 1 shows the static gradient spin echo (SGSE) sequence 1 for D0 measurement in low-field NMR when a static gradient magnetic field is present30. where the time interval between the 90° and 180° pulses (Td) is variable. When measuring the diffusion properties, Td is increased at each Td point, and the spin echoes are recorded. Therefore, the diffusion decay curve of a liquid molecule under a gradient magnetic field can be fitted. To improve the SNR, the sequence shown in Fig. 1 needs to be repeated several times and superimposed, and it is therefore quite time-consuming.Figure 1 SESG-CPMG measurement of D0 sequences and their parameters. Currently, the common way to increase the Td value is uniform stepping, if N signals need to be measured to fit the curve of D0. Td is set at a uniformly increasing step rate. The diffusion curve is estimated by using these measured values, which consumes considerable time. At the same time, some users of NMR instruments may not have background knowledge of the NMR principles, so it is difficult for them to adjust the measurement parameters. Therefore, automatic and intelligent measurement algorithms are wanted by users. The inversion recovery (IR) sequence used to measure T1 is shown in Fig. 2. Similar to the SGSE sequence and variable Td, Ti is varied to measure the T1 recovery of the sample.Figure 2 IR-CPMG measurement of T1 sequences and their parameters. Method In T1 and D0 measurements, adjusting Td and Ti during the measurement needs to be performed. In our method, many diffusion curves and T1 decay curves are randomly generated by Monte Carlo simulations, and then the unreasonable curves are excluded according to the data already measured, and the remaining curves can be used to estimate the measurement parameters for the next step. The detailed steps of the algorithm are as follows. First, the initial range of B and D0 are determined in Eq. (1), and the two-dimensional space determined by the initial ranges of these two parameters is called the initial parameter space. The initial parameter space is set to B ∈ [0, 2], D0∈[10–6 mm2/s, 10–2 mm2/s]. The D0 range can cover most of the self-diffusion coefficients of the tested samples. The variation range is [2 ms, 180 ms], which can reflect the attenuation curve of all samples in the above D0 range. A Monte Carlo sampling method is used to randomly select a specified number of data points in this initial parameter space and thus draw a cluster of t-f(t) curves to calculate the uncertainty of the model at this point (expressed as the product of the variance of B and D0 in this space). f(t) is the diffusion decay curve, and t is the abscissa of the measured data points. The most divergent time point t1 in this curve cluster is selected as the first sampling point, and the actual corresponding measurement value f(t1) is obtained by measurement. From this measurement dataset, (t1, f(t1)) constitutes the first data point of the dataset, and the initial parameter space of B and D0 is constrained under the constraints of this data point (i.e. only the parameter space that matches the (t1, f(t1)) data point is retained), which in turn yields the B and D0 parameter subspaces. Similarly, the t-f(t) curve cluster is plotted in this parameter subspace, and the model uncertainty is calculated, while the point t2, which makes the curve cluster most divergent, is still selected as the next sampled data point, and the measurement is performed. At this time, the data space is expanded to ((t1, f(t1), (t2, f(t2))), and the parameter space of B and D0 will be further reduced under the constraint of these two measurement data points. The above steps are repeated until the model uncertainty no longer significantly decreases; then, the parameter space of B and D0 under the data space constraint consisting of all measured data will be close to the true B and D0 values. The diffusion decay curve ft satisfies the following form30:1 ft=B∗e-tD03, This equation is correct for the constant gradient case, where the parameter vector A =D0,B is to be determined. t is the abscissa of the measured data points. Considering the form of Eq. (1), if there is no measurement error, B should be equal to the peak of the measured echo, and the maximum Maxy˙i, y˙i is the real measurement data. Considering the measurement error, the parameter search range can be set to Maxy˙i±5σ; and the D0 of common samples is between 0 and 10-8cm2·s-1. Therefore, D0 and B are set to obey the uniform distribution in their respective intervals:2 D0∼U0,10-8B∼UMaxy˙i-5σ,Maxy˙i+5σ, Multiple random sampling according to the above distribution is performed.3 ∑i=1Ny˙i-B∗e-tD032