Application of an Improved Seeds Local Averaging Algorithm in X-ray Spectrum

As an element content analysis technology, X-ray fluorescence spectrometry can be used for quantitative or semiquantitative analysis of the element content in the sample, which is of great significance for mineral census and spent fuel reprocessing. Due to the limitation of the inherent energy resolution of the detector itself, the accuracy of X-ray fluorescence analysis is difficult to be greatly improved. In some applications, even if the semiconductor detector with the best energy resolution is used, the characteristic peaks of different elements cannot be completely separated. ,erefore, greatly improving the energy resolution of the detection system is a hot issue in the existing research field. To solve these problems, this paper analyzes the advantages and disadvantages of the traditional MCA (multichannel analyzer) and SLA (seeds local averaging) algorithm and proposes an ISLA (improved seeds local averaging) algorithm based on mathematical statistics. In the section of theoretical derivation, the principle of ISLA algorithm is described, whose theoretical characteristics and spectral results with different parameters are derived and simulated. In the application effect evaluation, the spectrum obtained by each method is analyzed in detail. Simulation and experimental results show that the spectrum obtained by SLA algorithm has a smaller full width at half maximum than that obtained byMCA, but the seed average process in SLA algorithm also reduces its counting rate.,e optimized ISLA algorithm can not only effectively reduce the full width at half maximum of the spectral line and sharpen the spectrum peak but also compensate for the loss of the count rate of SLA algorithm.


Introduction
With the development of mineral exploration technology, X-ray fluorescence spectrometry, an element content analysis technology, can be used for quantitative or semiquantitative analysis of element content in samples. Semiconductor detectors are widely used for their high energy resolution. At present, most of the detectors commonly used in XRF (X-ray fluorescence) analysis are electric cooled semiconductor detectors, such as Si-PIN detector, SDD (Silicon Drift Detectors), and fast SDD. Driven by electronic technology and nuclear signal processing technology, the energy resolution of the measurement system has been close to the intrinsic resolution of the detector. In some specific applications, the detector with the best energy resolution is still not enough to complete the screening of various elements in the sample let alone calculate the content of each element effectively [1][2][3].
To further improve the measurement accuracy and more effectively identify the elements in the X-ray fluorescence spectrum, many scholars and researchers have studied the improvement of counting rate and spectral line energy resolution and achieved the corresponding research results. Digital pulse shaping is an effective pulse processing method for both counting rate and energy resolution, which can effectively improve the accuracy of measurement results.
Digital pulse shaping is a preprocessing method in the process of spectrum generation. In the study of improving energy resolution, deconvolution is often used to process the obtained spectral lines, and then the postprocessing method is needed to model the acquired spectral lines as functions of the input spectral line and the detector response function. e detector response function was determined by the probability distribution of the input pulse and the output pulse amplitude. Several common postprocessing methods include spectral smoothing [20,21], maximum likelihood estimation [22], and maximum entropy derivation [23], all of which involve a very complex mathematical modeling process of deconvolution, large amount of calculation, and weak generality. When a new detector is used, it needs to be remodeled and analyzed [24].
To solve these problems, the author's team members have achieved corresponding research results in pulse elimination [25], pulse impairment [26], digital filtering [27][28][29], and pulse shaping [30], to reduce the statistical fluctuation of measurement results. On this basis, this work regards the MCA (multichannel analyzer) and the SLA (seeds local averaging) [31] algorithm as the comparison object, an improved ISLA (improved seeds local averaging) algorithm has been proposed, and the theoretical derivation and application effect evaluation of the algorithm have been carried out, too.
e results show that the optimized spectrum processing method has a greater improvement in energy resolution compared with the traditional MCA method and makes up for the loss of the counting rate of SLA method. e application effect is good.

Spectrum Analysis Method
MCA, as a traditional spectral analysis method in X-ray fluorescence spectrometry, can clearly show the counting rate of each channel address, which is convenient for the implementation of element screening and element content analysis. When MCA cannot meet our requirements for energy resolution, a SLA algorithm was proposed to optimize the energy resolution of spectral lines by the foreign research team, which has the defect of counting loss [32]. In XRF analysis, the composition of the actual sample is very complex; not only does it contain a variety of elements, but also the content of many elements is very weak. For the content analysis of these weak elements, not only is high energy resolution needed to distinguish different characteristic peaks, but also the counting rate of each characteristic peak is not allowed to have too much loss. e loss of counting rate will directly affect the accuracy of element content calculation. erefore, the research team of the author proposes an ISLA algorithm on the basis of SLA algorithm, to improve the energy resolution and ensure that the count rate is not lost.

MCA.
MCA adopts the method of single pulse spectrum generation. Every pulse amplitude received is stored in FIFO. e key part of the spectrum generation process is the corresponding relationship between the pulse amplitude and the channel address. e limitation of this algorithm is that it can only make simple mathematical statistics of pulse amplitude and cannot optimize the energy resolution nor change the final count rate. Taking the 2048 channels as an example, the pulse amplitude 0∼2000 mv corresponds to the channel address 1∼2048. erefore, we approximately think that 1 mv corresponds to a channel address, and its spectral principle is shown in Figure 1.

SLA.
SLA algorithm is a kind of seeds local averaging algorithm based on MCA and probability density conversion, which includes the average window parameter R and the number of seeds in the active window N. When the average window parameter is R, the window size is 2 * R + 1, and its spectral principle is shown in Figure 2. First, the pulse amplitude obtained is regarded as a seed, and then the range of the active window is determined according to the value of the current seed, as shown in the red area in Figure 2. When the number of seeds in this area reaches the maximum number of seeds, N, the average seeds in this area, SLA algorithm will update the count of the corresponding channel address through the pulse amplitude average value. Finally, the average seeds and the number of seeds in the active window are cleared. Figure 2 shows the average window, whose key parameters N is equal to 3 and R is equal to 1 during SLA spectrum generation. erefore, it is not difficult to see that MCA method can actually be regarded as a special SLA algorithm, in which the value of parameter R is 0 and the value of parameter N is 1.
rough the implementation principle of SLA algorithm, we can see that the algorithm can effectively improve the energy resolution through the local average method in a small window, but this average method also causes the loss of counting rate, which is the limitation of SLA algorithm.

ISLA.
After optimizing the SLA algorithm, this paper proposes an improved seeds averaging (ISLA) algorithm, whose spectral principle is shown in Figure 3. e similarity between ISLA algorithm and SLA algorithm is that pulse amplitude is used as a seed to sow in the local window. When the number of seeds reaches the threshold set by the algorithm, the average value of pulse amplitude is used to update the count of the corresponding channel address. e advantage of ISLA algorithm over SLA algorithm is that the former will calculate the number of pulses taking the average value in the local window when updating the count on the channel address and update the count value according to the value of the number of pulses N, while the latter will simply add one to the count on the channel address, thus resulting in the loss of the count rate.
Similar to SLA algorithm, ISLA algorithm involves two variable parameters: one is the average window size, which is represented by 2 * R + 1, and the other is the number of seeds in the average window, which is represented by N. In the principle description of ISLA algorithm, we take the average window parameter R equal to 1, and the number of seeds is 3 in each averaging process. During the algorithm execution, firstly, each pulse amplitude obtained is considered as a seed, and then determine the range of the active window according to the current seed value, as shown in the red area in Figure 3. When the number of seeds in this area reaches N, the maximum number of seeds set by ISLA algorithm, the algorithm execution unit averages the seeds in this area and updates the count of the corresponding channel address through the average value of pulse amplitude. e increment of count on the channel address is equal to N, the seeds number of participating averaging. Finally, clear the seeds and the seeds number in the active window, and start reading the next pulse amplitude for a new round of seeding.

Theoretical Derivation and Simulation
As mentioned above, the essence of MCA is SLA algorithm, whose parameter R is equal to 0 and parameter N is equal to 1. Each pulse amplitude corresponds to a count value in the final measured spectrum. erefore, MCA represents the probability density of the pulse amplitude, and ISLA averages this probability density within a specified range, to obtain a new probability density. For a single peak, the mean value μ represents the peak position, while the variance determines the FWHM (full width at half maximum). In the following, we will discuss the peak position and FWHM of ISLA algorithm from the two indexes of mean value and variance. Before that, the number of amplitude samples required for the algorithm simulation is calculated. Compared with SLA algorithm, ISLA algorithm only corrects each increase of count by a mathematical method, to compensate the counting loss caused by the seed average process, but the algorithm does not further improve the energy resolution.

Number of Amplitude Samples.
In the process of algorithm simulation, we usually use the normal distribution sequence generated randomly as pulse amplitude samples. According to the number of samples, we can calculate the probability of taking a pulse amplitude information from the sample pool in the same sampling time. It can be estimated that the larger the number of samples, the more similar the probability of extracting any pulse amplitude information in the same sample time. When the probability of taking out any pulse amplitude information tends to be stable, the number of samples at this time can be considered as the best value.
Below we describe an algorithm (i.e., Algorithm 1) for computing the best number of amplitude samples. Here, AE is the acronym of the phrase "average error." e calculation process is as follows: the simulation range of sample number is 200∼80000, and the interval is 50. After the sample number C is determined, 2048 random numbers are generated by a uniform distribution function, whose value range is 1∼C. at is to say, a sample, whose capacity is C, will be randomly sampled 2048 times. If the number of samples is less than 2048, some samples will appear more times, while some samples appear less. e specific frequency of each sample can be counted by the tabulate function, to get the difference between the actual  probability and the average probability of each pulse amplitude sample. en, the average error is obtained by dividing the squaring sum of the errors that occur for each random variable by the total number of samples; the results are shown in Figure 4.
It can be seen from Figure 4 that when the number of samples is less than 20000, the average error decreases with the increase of the number of samples. However, when the number of samples is more than 60000, the impact of the continuous increase of sample size on the average error is not obvious. It is concluded that to maximize the random sampling of large samples and reduce the correlation of calculation, the average error of each random number can be reduced as much as possible by increasing the number of samples.
However, if the static sample pool is large, it will also lead to waste of resources and limited efficiency. erefore, 65536 amplitude samples are selected in this paper. In practice, due to the limited hardware resources, the real-time updated dynamic samples are usually used, and the sample size is 4096. Figure 5 shows the MCA spectral results obtained with different sample sizes. It is easy to see that the larger the number of samples, the closer the probability of each sample to be sampled, and the smoother the final probability density map.

Peak Position.
In the ISLA algorithm simulation, the average window size is represented by 2 * R + 1, and the average number of seeds is N. We use X 0 to represent the original pulse amplitude sequence, which determines that the range of the average window is [X 0 −R, X 0 + R], its probability density function is f(x), and its cumulative distribution function is F(x). If X A is the average pulse amplitude of seeds in the local window, X A and X 0 have the same probability distribution function, but its range is limited to [X A −R, X A + R]. When the number of seeds in the average window reaches the threshold N (N � 5 in this paper), the average pulse amplitude X A is shown in the following equation: If the probability density function of the original pulse amplitude sequence f (x) is symmetric with respect to the mean value μ, which represents the peak position of the probability density function, and then (2) can be obtained for any value b.
e probability density function of X A is determined by X i (i � 0∼4) participating in the average. Both X A and X i have the same probability density function; therefore, it can be concluded that X A processed by ISLA algorithm is also determined by the probability density function of X i .
Regardless of the parameter settings, the symmetry of the original distribution will not be changed after ISLA transformation. It is worth noting that if the original distribution is an independent Gaussian peak, the distribution obtained after ISLA transformation will have the same mean value, which means that the ISLA algorithm can keep the peak position unchanged, while the symmetry is maintained. e spectrum obtained by different algorithms is shown in Figure 6.

FWHM.
As mentioned above, if the probability density function of the original pulse amplitude sequence f(x) is symmetric, and it approaches to μ on both sides of the average value μ, the variance of X A obtained by ISLA transformation must be smaller than that of the original pulse amplitude sequence. e derivation process is as follows.
e above theory can be simplified as shown in inequality (3) by ordering the average value μ � 0 without losing generality.
To simplify the calculation, N � 2 is taken here. Inequality (3) can be further simplified as follows: e left side of inequality (4) can be further expanded as shown in formula (5).
Replace (5)   Mathematical Problems in Engineering Inequality (6) can be reduced as follows: erefore, in order to prove inequality (4), we only need to prove inequality (7), whose left side can be expanded as shown in the following: Since f (x) is symmetric and always increases towards the mean value (here we assume the mean value is 0), we can conclude that if (7) can be derived from the following equation: e above inference shows that the ISLA algorithm does not change the probability density distribution or destroy the symmetry of the original distribution regardless of the parameter value of ISLA. For a single Gaussian peak, the FWHM of the spectral line is positively correlated with the variance of the distribution. erefore, we can conclude that the ISLA algorithm reduces the variance, thus reducing the FWHM of the spectral line and sharpening the spectral peak.
In the simulation of ISLA algorithm, 65536 pulse amplitude samples are taken, and three different parameters of ISLA algorithm are used for spectrum generation, and the spectral results are compared with those of traditional MCA. Because the performances of SLA algorithm and ISLA algorithm are consistent in energy resolution, this section only compares the FWHM of ISLA algorithm and MCA algorithm. Considering the fairness of the comparison, the data source used in FWHM comparison is the same, and only one parameter is changed each time. e comparison results are shown in Figure 7.
It can be seen from Figure 7 that the FWHM improvement effect of ISLA algorithm with different parameters is different. Because the essence of FWHM is the full width of the half peak position, and the width of each peak can be quantified by the channel address, therefore, the channel address is also used to quantify the FWHM value in the simulation results. e FWHM obtained by each parameter is shown in Table 1.
Regardless of the parameters taken by ISLA algorithm, its FWHM is always smaller than that obtained by MCA algorithm. erefore, it is concluded that ISLA algorithm not only effectively reduces the FWHM of spectral lines but also ensures that the count rate is not lost. At the same time, according to the measurement results of different seed average N, when the average window size is fixed, it can be seen Mathematical Problems in Engineering that the larger N is, the better the improvement effect of FWHM is.

Result.
In the application evaluation of different spectral methods, fast SDD with resolution of 122 eV-129 eV is used as the detector, KYW2000A X-ray tube is used as the excitation source, and self-made powder iron ore sample is used as the measurement object. In the back-end electronics circuit, different spectrum generation algorithms are called to generate multichannel spectrum, and the measured spectrum is analyzed and compared.
With the development of nuclear pulse processing technology, the energy resolution obtained by MCA is gradually approaching the intrinsic energy resolution of the detector itself. erefore, the FWHM MCA of the spectrum is mainly restricted by the inherent energy resolution of the detector. Taking iron ore samples as an example, the spectrum obtained from the measurement is shown in Figure 8.
In the experiment, taking the iron ore sample as the measurement object, and the measurement results obtained by the traditional MCA and SLA algorithm are shown in the black and red spectral lines of Figure 8, respectively. It can be seen from Figure 8 that the FWHM of the spectral line obtained by SLA algorithm is clearly smaller than that obtained by MCA, and the loss of the counting rate caused by the local average process of seeds in SLA algorithm is also indeed shown. As mentioned above, ISLA algorithm is an optimization of SLA algorithm, and its fundamental purpose is to keep good energy resolution and ensure that the counting rate is not lost. e measurement results after ISLA algorithm are shown in the blue spectral lines of Figure 8. In contrast, the spectrum processed by ISLA algorithm not only reduces the FWHM but also ensures that the counting rate is not lost. e purpose of this paper is to emphasize that SLA algorithm is an improvement of SLA algorithm, which is only reflected in the counting rate. erefore, we emphasize the optimization of ISLA algorithm compared with SLA algorithm in counting rate. Take the K-α and K-β peaks of iron elements as the analysis objects, and use MCA, SLA, and ISLA algorithm to acquire spectrum. e spectrum analysis results are shown in Table 2, where C k-α represents the sum of the counting rates in k-α peak area, and C k-β represents the sum of the counting rates in k-β peak area. It is easy to see that the sum of counting rates obtained by SLA algorithm is smaller than that by MCA algorithm, regardless of the k-α peak or k-β peak of iron, while the sum of counting rates obtained by ISLA algorithm is approximately equal to that obtained by MCA algorithm. at is to say, although the SLA algorithm reduces the FWHM of the spectral line, it indeed results in the counting loss, which is effectively compensated by the ISLA algorithm. In the SLA algorithm and ISLA algorithm, the parameter N � 3, R � 1 is taken, which is equivalent to obtaining the increase of one count through the average of three pulse amplitudes. erefore, the sum of the counting rates obtained by SLA algorithm is about onethird of that of MCA algorithm, while ISLA algorithm updates the count by seed average N, which makes up for the counting loss caused by SLA algorithm.

Cost-Effectiveness.
e three spectral methods mentioned in this paper, MCA, SLA, and ISLA, have been verified by simulation and experiment. To further evaluate the cost-effectiveness of different algorithms, this paper will analyze and discuss from the aspects of computational complexity and running time. e analysis results are shown in Table 3. Here, we use the main operations to evaluate the computational complexity of each spectral method, and the running time can be approximately considered as the execution time of the main operations. e core processor STM32F103VET6 is used in the experiment, which adopts three-stage pipeline design and whose average instruction cycle given by the official datasheet is 1.25 Mips/MHz.
As mentioned above, the execution process of MCA algorithm mainly includes two parts: the location of channel address and self-increase of counting rate, whose execution time can be regarded as two instruction cycles. Compared with MCA algorithm, the execution process of SLA algorithm and ISLA algorithm are more complex, including not only the location of channel address and self-increase of counting rate, but also an averaging operation in the local  Mathematical Problems in Engineering window, whose implementation includes multiple additions and one multiplication, and the execution time of each operation is shown in Table 3.
To sum up, among the three spectral methods introduced in this paper, MCA has the lowest computational complexity and short running time.
erefore, the costeffectiveness of the algorithm is the highest, but whose energy resolution is the lowest. In some applications where the requirement for energy resolution is not high, MCA is applicable. e calculation process of SLA algorithm and ISLA algorithm are roughly the same, so they have the same computational complexity and running time. Under the same cost-effectiveness, ISLA algorithm can not only obtain high energy resolution but also ensure that the counting rate is not lost. erefore, the performance of ISLA algorithm is better than SLA algorithm.

Conclusion
is paper has presented three kinds of spectral methods and describes the spectral principle of each method in detail. In addition, theoretical derivation and software simulation of ISLA algorithm are carried out. In the application effect evaluation, the spectrum obtained by each spectral method was analyzed in detail. Simulation and experimental results show that the spectrum obtained by SLA algorithm has smaller FWHM than that obtained by MCA, but the seed average process in SLA algorithm also reduces its counting rate. After optimizing SLA algorithm, ISLA algorithm not only effectively reduces the FWHM of the spectral line and sharpens the spectral peak but also does not cause the counting loss. It is undeniable that ISLA algorithm provides a real-time, efficient, and universal processing method for reducing the noise of detectors and has a proven theoretical guarantee, which is of great significance in improving the energy resolution of detectors.
Data Availability e original data involved in the article already exists in the pictures in the article. All the pictures are produced by the original data and can be edited.

Conflicts of Interest
e authors declare that they have no conflicts of interest.