Near-field microwave sensing technology enhanced with machine learning for the non-destructive evaluation of packaged food and beverage products

In the food industry, the increasing use of automatic processes in the production line is contributing to the higher probability of finding contaminants inside food packages. Detecting these contaminants before sending the products to market has become a critical necessity. This paper presents a pioneering real-time system for detecting contaminants within food and beverage products by integrating microwave (MW) sensing technology with machine learning (ML) tools. Considering the prevalence of water and oil as primary components in many food and beverage items, the proposed technique is applied to both media. The approach involves a thorough examination of the MW sensing system, from selecting appropriate frequency bands to characterizing the antenna in its near-field region. The process culminates in the collection of scattering parameters to create the datasets, followed by classification using the Support Vector Machine (SVM) learning algorithm. Binary and multiclass classifications are performed on two types of datasets, including those with complex numbers and amplitude data only. High accuracy is achieved for both water-based and oil-based products.


Microwave sensing in-line inspection scanner
The MW sensing system, illustrated in Fig. 1, includes six antennas mounted on an arch-shaped support that enables the sample to pass through without any interruption or delay.The antennas are connected to a six-port vector network analyzer (VNA) 26 that captures the transmitted signal from the radiating antenna in complex numbers format at the operating frequency band.The antenna array setup is enclosed within a shielding box made up externally of metal to mitigate interference originating in the industrial environment, and internally of a layer of MW absorber that limits MW signal reflections.The speed of the conveyor belt in the food industry is around 20 meters per minute (that corresponds to 33 cm/s ): this speed must be compatible with the measurement and data processing time.Moreover, initiating the measurement process as the jar approaches, the antenna array involves employing a photocell to trigger the VNA.The system counts with the photocell, and the measurement is triggered when the jar is in the desired position (through an automatic adapted delay).Variations on the speed of the belt are already considered by the control of the encoder.The measurement system is adapted to suit the measurement of lossy and low-loss mediums by using a custom-mode wide-band PCB-printed monopole antenna.In the following sections, we provide a detailed analysis of the frequency bandwidth selection, numerical investigation, and evaluation of the antenna in its near-field region.

Frequency selection
The selection of the operating frequency bandwidth is a balance between the penetration depth of the electromagnetic (EM) waves, the dimensions of the food jar, and the desired resolution to be able to detect intrusions such as PolyTetraFluoroEthylene (PTFE, that is a kind of plastic common in packaging) and soda-lime glass (SLG) of millimeter size (detailed in Table 1).Different frequencies may be appropriate for detecting different types of contaminants within food and beverage products.Shorter wavelength waves are more accurate in detecting smaller objects, because they have a higher spatial resolution that is inversely proportional to the wavelength, whereas longer wavelengths are more effective in lossy media due to their higher penetration capability.The dielectric property of the materials plays an important role in allowing these waves to go through these media or not.This property is frequency-dependent, which makes the selection of the frequency ranges for conducting the measurements very important.Hence, it is important to evaluate the dielectric characteristics of the two considered food materials, oil and water, along with the possible contaminants.For the measurements of the dielectric properties of oil and water, we use a 2-ports P9375A Keysight VNA 27 along with 85070D Keysight dielectric probe together with the keysight software suite 28 .The results are shown in Fig. 2a, b.The relative permittivity of water significantly exceeds that of oil, resulting in a more pronounced dielectric contrast with respect to the contaminant materials shown in Table 1 compared to the contrasts between the permittivity of oil and the contaminants.This heightened contrast facilitates the detection of intrusions in water as opposed to oil.On the other hand, the conductivity values are notably higher in the case of water, indicating a reduced penetration depth within water compared to oil.High-loss materials present challenges for wave penetration.However, a good selection of the frequency operating bandwidth can solve this problem.The penetration depth, δ , is reported in Fig. 2c, d and it is evaluated as follows: in which k is the propagation constant, k 0 = ω √ ε 0 µ 0 is the free space propagation constant, ω is the angular frequency, ε 0 and µ 0 are the free space permittivity and permeability respectively, ε r and σ are the medium relative permittivity and conductivity respectively.The penetration depth plots for water and oil indicate that is essential to fix an upper limit to avoid the very low penetration depth of the propagating waves inside the medium, particularly with water.Taking into account the considered diameter of the jar under analysis, which is around 8 cm , the dotted lines in Fig. 2c, d represent the upper limit for selecting frequency bands for both materials.On the other hand, the lower limit of the frequency bands should consider the necessary resolution for detecting millimeter-sized intrusions, considering the different dielectric permittivities of oil and water.Taking all these parameters into consideration, we set the operating frequency bandwidth from 6 GHz to 10 GHz for the oil-based food jars, and from 1.5 GHz to 3.5 GHz for the water-based food products.
Considering the minimum size of the contaminants (that is equal to 4 mm), we choose this dimension because it corresponds to the minimum size contaminants used to test detection systems in food industries, and the wavelength of the EM waves being used, the number of antennas required in MW sensing application is determined.In general, a higher number of antennas can lead to better sensing performance, as it provides more information about the object being radiated.However, a higher number of antennas increases the system complexity and cost.Therefore, it is important to find a trade-off between the number of antennas, sensing performance, and implementing considerations such as system size and cost.In the references 29,30 , it is estimated that the optimal configuration for this system involves the use of six antennas arranged in an arch shape.This  arrangement has been proposed considering also the presence of the conveyor belt, the supporting structure for the belt and the dimensions of the food jar samples.Due to these constraints, it is not feasible to position any antenna directly facing the lower part of the jar, so we ultimately deploy six antennas arranged in an arch configuration, as illustrated in Fig. 1.

The measurement procedure
The jars are actual commercial products.They are of elliptical cylindrical shape, whose minor axis is equal to 6.6 cm , a major axis of 8 cm , and a height of 10.5 cm .The contaminants exhibit a spherical shape with a diameter of 4 mm .We select plastic and glass as contaminants because they are expected to be present post-packaging in the food industry in case of contamination, and are hardly detectable with other systems 31 .We follow the same approach to conduct the measurements for both food materials, water, and oil.We arrange four plastic jars that shared the same shape and dimensions as the one illustrated in Fig. 1.Out of these four jars, we select two to be used as uncontaminated samples, while the remaining two are utilized to introduce various contaminants.The measurement process begins when the jar, carried by the conveyor belt, enters the area where our antenna array effectively emits radiation.The elements of the antenna array emit signals sequentially and receive them simultaneously as the jar is in motion.This operation enables the collection of signals at various positions of the jar and across different frequency points.

Antenna design and testing
This section is a comprehensive description of the antenna design and operation.It includes the description of the design parameters, the impedance matching performance, and the experimental near-field evaluation.Furthermore, we evaluate the capability of detecting contaminants using the electric field (E-field) spatial coverage analysis and the time domain reflectometry.www.nature.com/scientificreports/

Antenna design parameters
Selecting the appropriate antenna type is pivotal in designing an effective MW sensing system.Exploring the role of antennas in this context involves considering factors such as bandwidth, polarization, radiation pattern, and gain; however, given our focus on applying the sensing technique in the near-field region, our concern lies not on the gain.As stated in the system description section, we are using a PCB-printed monopole antenna with a flower shape, derived from 32 .Omni-directional antenna has a wide angular coverage, enabling it to emit and collect the retrieved scattering parameters from all directions.This capability facilitates the detection of contaminants at different positions within the jar.The simplicity and omnidirectional nature of the monopole antennas make them well-suited for close-range applications, however, obtaining a wide bandwidth antenna is a challenge in terms of radiation power stability across the entire bandwidth, impedance matching, and electrical size constraints.Taking into account all these parameters, we optimize the antenna to adapt to our specific application requirements, focusing on achieving the desired stability in the radiation pattern, the required bandwidth, and the impedance matching.The antenna is designed according to the following standards: the metallic flower structure of the antenna and the ground plane have a thickness of 0.03 mm and are printed on a standard sub- strate of FR-4 ( ǫ r = 4.1 ) with a thickness of 1.55 mm .The antenna primarily consists of four ellipses as shown in Fig. 3, each with a larger radius (R1) of 24 mm and a smaller radius (R2) measuring 12 mm .The primary ellipse is aligned with the transmission line at a zero-degree angle relative to the line.and length of the transmission line, with values of 3 mm and 15 mm , respectively.The ground plane has a semi- ellipsoidal shape with an optimal triangular cut, as illustrated in Fig. 3b.L3 and L4 are equal to 3 mm and 5.2 mm respectively and denote the optimal dimensions of the V-cut, which are determined for the best performance in terms of the impedance matching in the frequency band of interest.
The limit of the near-field region is determined by where D = 6.7 cm is the maximum dimension of the antenna (the diagonal), and is the wavelength.In the selected frequency bands, we compute the near-field radiating radius (r) using Eq. ( 2) at 1.5 GHz and 10 GHz , resulting in values of 4.5 cm and 30 cm respectively.In our setup, the antenna is about 5 cm away from the jar.This implies that our measurements are conducted in the near-field region for oil-based products in the 6 to 10 GHz bandwidth.While for water-based products, at lower frequencies within the 1.5 to 3.5 GHz bandwidth, the jar is positioned at the edge of the near-field region.However, at the higher frequencies in this bandwidth, it falls within the near-field region.For a comprehensive understanding of the performance of the antenna array elements integrated with our sensing system, we conduct simulations and measurements to obtain the near-field.
The upcoming subsections provide a thorough analysis and assessment of the propagation of the E-field radiated by the antenna in the region of interest.

Impedance matching and near-field measurements
The near-field measurement system, which is also used for impedance matching evaluation, is shown in Fig. 4. It comprises the network analyzer, the transmitting antenna employed in our study, and the receiving antenna, which is a wide-band horn antenna operating starting from 2 GHz .For the near-field measurements and later for the time-domain analysis, which are useful to fully understand and analyze the addressed problem, we conduct measurements and simulations across a broad bandwidth ranging from 2 to 12 GHz.
For the impedance matching analysis, we measure the reflection coefficients at the antenna port.We investigate three scenarios that are reported in Fig. 5.The first one displays the impedance matching of the antenna in the absence of any jar (blue curve).This plot displays good matching performance in the bandwidths of interest except at the lowest frequencies of the lower bandwidth, as highlighted in green and orange shaded areas in Fig. 5.However, the real system operates in the presence of a jar, which is why we investigate two additional scenarios, one with a jar filled with oil (green curve), and the other with a jar filled with water (red curve).The three curves are almost superimposed, showing that the presence of the jar does not significantly affect the impedance matching.The antenna is overall well matched, except below 2.5 GHz.However, mismatching does not mean that no power is transmitted into the jar especially for water-based products, while the penetration depth is 6 cm at 2 GHz (from Fig. 2c).So it is too early to exclude the frequencies between 1.5 and 2.5 GHz at this stage, but we will investigate this frequency band during the analysis of the experiments and the classification results.
Next, we measure the near-field of the antenna.For this, we make use of the mechanical stepper motor connected to the receiving horn antenna for aim scanning.The two antennas are centered with respect to each other and positioned 17 cm apart.The horn antenna captures the radiated waves within a scanning area that extends 20 cm in the vertical y-direction and 25 cm in the horizontal x-direction with an incremental step of 2.5 mm in both directions.Since we aim to measure the near-field of the antenna, measurements are conducted without the jar.The results are displayed in Fig. 6.The plots illustrate the magnitude of the near-field (normalized to the maximum magnitude value across all frequency points), illustrating a reduction in field strength with increasing www.nature.com/scientificreports/frequency, especially beyond 8 GHz .This will be confirmed by the overall system measurements as described in the dataset construction section.

E-field spatial coverage
The E-field spatial coverage can be analyzed as an indicator of how effectively an antenna array illuminates a specific point within the radiated volume.In simpler terms, it assesses how thoroughly the electromagnetic waves emitted by the antenna array reach and interact with a particular point within the tested space.For a better interpretation of E-field spatial coverage, we simulate the system in its real dimensions, as illustrated in Fig. 7.We choose the water case due to the challenge that high losses imply.The simulations are conducted at a frequency equal to 2.5 GHz , which is the center frequency in the selected bandwidth for testing water jar samples.The E-field spatial coverage is defined as follows:  where r is the positioning vector, T is the number of antennas, and E α n with α = i, t and s, is the incident, total, and scattered E-fields, respectively.Each E i n is obtained with the n-th antenna radiating with the jar filled with water only, instead, the E t n is the E-field radiated by the n-th antenna with contaminants inside the filled jar.Finally, E s n = E t n − E i n represents the E-field scattered by the contaminants.When the n-th antenna is radiating, all the others are matched to 50 .Hence, T = 6 different simulations are performed to get the E-field spatial coverage with each time a different radiating antenna.
Figure 8a shows the C i E (r) and it is evident that we got the lowest E-field coverage at the bottom of the jar.Hence, to consider the worst scenario, the contaminants, which are five plastic spheres with 2 mm in diameter, are placed in the bottom of the jar.Then, Fig. 8b shows the C t E (r) , which is the coverage when the contaminants are present: the total coverage appears very similar to the incident one.However, the scattered coverage shown in Fig. 8c clearly shows the presence of the contaminants at the accurate location, which are clearly distinguishable.

Time-domain analysis
The time domain reflectometry is commonly used in non-destructive evaluation, showing that the reflection coefficients carry relevant information about the object under test; hence we use here to investigate our simulated and measured data.The objective of examining the time-domain response of the reflection coefficient parameters, obtained from both simulations and measurements, is to study the reflections of the signal emanating from the radiated region.This analysis can be conducted through direct time-domain measurements or by first performing a frequency-domain measurement followed by the Inverse Fast Fourier Transform (IFFT).To identify discontinuities within the system, a large time-domain observation window with a small interval is required.The reflection coefficients are measured across a frequency range of 2 GHz to 12 GHz at intervals of 10 MHz for both the measurements and simulations.By comparing the electrical distance in both measurements and simulations across various media, along with evaluating the distance line ( dx ) obtained from the time domain analysis, we successfully detect the key reflection points within our system.These points include the antenna's feeding port, its phase center, the jar filled with water, and most crucial the contaminant inside the jar.
In Fig. 9 we present the simulated system.The labels (a-f) within this figure correspond to the following points: (a) the waveguide port, (b) the feeding port of the antenna, (c) the center of the antenna structure, (d) the center of the face of the water jar opposite to the antenna, (e) the position of the contaminant inside the water, and (f) the edge of the jar from the second side.Four simulations are performed to analyze the time domain behavior under different scenarios.The first simulation is used as a reference, involving a jar filled with water without intrusions.In two of the remaining three simulations, a plastic cube contaminant is introduced, each with a different position within the jar.The last simulation involved changing the contaminant material to metallic (copper).The IFFT operation is applied to the simulated reflection coefficient data, and the distance line, dx , is calculated according to: where dx represents the distance line in centimeters, c is the speed of light in free space, dt is the time interval between consecutive points in the time domain, and df is the frequency resolution.
For more accurate calculations, it is important to define the range resolution as the antenna's capability to distinguish between closely spaced targets.Discussing range resolution is important for addressing discontinuities in the antenna and the system.For example, to detect these reflection points accurately, the range resolution must be smaller than the distance between any two consecutive points in Fig. 9. Therefore, we need to consider the value of the range resolution in our calculations in determining the positions of these discontinuity points.The range resolution is defined as follows: where R is the range resolution, and BW = 10 GHz is the bandwidth of the conducted simulations and meas- urements.According to Eq. ( 5), the range resolution is calculated to be 1.5 cm. Figure 10a shows the IFFT results for the simulated reflection coefficients obtained at point a in Fig. 9.The labels (1), (2), and (3) within this subfigure correspond to the reflection points b, c, and e indicated in Fig. 9, respectively.The positions of these peaks on the IFFT plots are determined by calculating the electrical distance by multiplying the geometrical distance (obtained from the simulated design or the measurement system) by the  www.nature.com/scientificreports/square root of the relative permittivity of the propagating medium, as shown in Table 2.This allows us to discern which part of the conducted simulation or real measurements corresponds to each peak in the IFFT plot.In Fig. 10a, we are unable to detect the presence of the contaminant inside the jar, as the plots are superimposed with the reference curve (the one without the contaminant).To address this issue, we subtract the recorded reflection coefficients simulated when the intrusion is present from that of the reference simulation.Then, we perform the IFFT on the remaining values to see if we can identify the positions of the contaminants along the distance line.Figure 10b displays the outcomes of this approach, and it is evident that the peak obtained at x = 46.5 cm is a result of the contaminant presence within the water.This peak is notably more pronounced when the contaminant is metallic.The displacement of the contaminant within the jar influences the location of the reflection point indicated by a peak at x = 61.4cm , while the peak at x = 77.9cm arises from the reflection of the rear side of the jar.This peak appears as a result of the presence of the contaminant within the water, influencing the propagation path of the wave within the medium.This deviation from the reference scenario, where no contaminant is present inside the jar, causes the observed difference at the third peak in Fig. 10b.
Comparing the data in the final two columns of Table 2 reveals a good coherency between the theoretically estimated reflection points positions and those evident in the IFFT plot illustrated in Fig. 10a, b, taking into Table 2. Analysis of the distance X as illustrated in Fig. 10.The second column displays the relative permittivity of the medium along the specified distance; the third column shows the corresponding geometrical distance; the fourth column represents the corresponding electrical distance (theoretical); and the fifth column shows the electrical distance (simulation) that appears in Fig. 10a, b.To further investigate the system's ability to detect changes in the reflection coefficients based on the jar contents through measurements, we record the antenna's reflection coefficient parameters using the same system previously employed in the near-field study (shown in Fig. 4).We explore three distinct scenarios: one without any jar, another with a jar filled with oil, and a third with the same jar filled with water, but this time without the need for scanning.In Fig. 11, the labels displayed on the curve represent the estimated reflection points.The peaks marked with (1) and (2) correspond to the feeding port and the phase center of the antenna, respectively.The three curves overlap until reaching the peak at point (3), which indicates the reflection point originating from both the support holding the jar and the jar itself, as shown in Fig. 4. The reflections at this point distinctly demonstrate the influence of the entire medium within the jar on the reflection intensity.Specifically, it is more pronounced when the jar is filled with water (the red curve) compared to when it contains oil (the green curve) or the scenario where reflections are only due to the support without the presence of a jar (the blue curve).It is noteworthy to mention the consistency of the three highlighted peaks (1), (2), and (3) in both plots, the simulation in Fig. 10a, and the measurements in Fig. 11.However, the position of these points is shifted by the length of the coaxial cable ( X a,b ) in Fig. 10a.

Measurements and settings
After determining the two frequency bands of interest, we have to set up the number of frequency points within these bands.This directly depends on the speed of the conveyor belt, which is equal to 33 cm/s, and on the maximum allowed acquisition time, required for the measurement of one sample jar, which corresponds to around 50 ms, and is indicated with t total in Fig. 12.This acquisition time includes the starting time of the measurements, and six periods of t f , where each period represents a frequency ramp, which is the time needed for a gradual frequency increase between the minimum and maximum frequency points within the selected frequency bands.Additionally, there are 5 t switch periods, which corresponds to the switching time between the 6 transmitting antennas, and finally, the time needed to collect the data.Choosing the number of frequency points is a trade-off between having frequency diversity from the measurements and the time based on the moving jar carried by the conveyor belt.A higher number of frequency points provides more detailed information but may require longer measurement times, which makes the process inapplicable.t f is defined as: where N f is the number of the frequency points and t IF is the time taken by the VNA to sweep through the speci- fied frequency bandwidth and collect data points, and it is inversely proportional to the intermediate frequency filter of the VNA (IF).We aim for a small value of IF for achieving measurements with low noise.However, a small IF value leads to a large t IF value, indicating a preference for a reduced number of frequency points ( N f ).Based on this analysis, we have found that recording data at N f = 11 frequency points in the two bands with IF = 1 kHz is compatible with our requirements.In Fig. 12, it is evident that the transition between antennas ( Tx i ), where i represents the index of the radiated antenna, occurs once the preceding antenna has completed its operation over the 11 frequencies in the bands.At each time when an antenna radiates, the other 5 antennas and the radiated antenna receive the retrieved scattered waves.After each acquisition, we obtain a set of 11 matrices at the 11 frequency points, each comprising 36 elements.These matrices contain valuable information regarding the condition of the food product being tested.Moreover, we underline that, during the measurements, the jar is in motion as the transition between antennas and frequency sweeping takes place.Therefore, the obtained matrices are not symmetrical, since the dynamic movement of the jar leads to changes in the scattering behavior of the MW.

Dataset construction
To generate the datasets, we perform multiple repetitions of measurements (illustrated in Table 3), spanning hundreds of times for each specific case.The incorporation of diverse data collection approaches, such as conducting measurements on different days, swapping between the contaminated and uncontaminated jars, and slightly rotating the jar before each single measurement, plays a crucial role in enhancing the robustness of our findings.
An externally triggered script is used to control the desired parameters in our measurements.This script enables us to conduct uninterrupted hundreds of measurements while sequentially recording the scattering matrices.Every single measurement includes 11 matrices, each of size 6 × 6 .These 11 matrices are arranged in columns, as illustrated below: where each element S f m ij,n is a complex number and n refers to the index of the measurement sample, i and j are the indices corresponding to receiving and radiating antennas, respectively, and f m with m = 1, . . ., 11 denotes the 11 frequency points.From Eq. ( 7), the following vectors are derived for each frequency f m : where A in Eq. ( 8) refers to the amplitude of the measured scattering parameters, while Eq. ( 9) contains both their real and imaginary parts in a separate form.Gathering the 11 vectors corresponding to the 11 frequencies allows us to obtain the following vectors:  www.nature.com/scientificreports/which encompasses all the extracted scattering parameters from a tested sample.Each vector comprises either 396 entries for an amplitude-only dataset or 792 entries for a dataset with complex numbers data.With the provided vectors, we can generate the required datasets for both training and testing phases by collecting the complete set of vectors associated with all measurement samples in the following manner: where N represents the total number of conducted measurements.Figure 13 displays the amplitude plot for two matrices [S n ] corresponding to different test samples and nor- malized to the maximum amplitude value in each sample case.The magnitude values in Fig. 13a demonstrate better transmission performance of the employed antennas above 2.5 GHz in the case of the water jar.This is coherent with the behavior of the antenna reflection coefficients in Fig. 5, where below 2.5 GHz the antenna is not well matched.Instead in Fig. 13b, the values indicate better transmission performance from 6 GHz up to 8 GHz , while, beyond that range, there is a decrease in the magnitude of the transmission coefficients.This behavior is related to the antenna near-field shown in Fig. 6 where there is an evident reduction of the radiated field above 8 GHz.The significant variation in the magnitude of transmission coefficients within the chosen frequency bands for oil-based jar samples and water-based jar samples enables us to selectively focus on subranges with favorable transmission behavior.The selective process within the frequency bands will be demonstrated in the experimental results section when we attempt classification based solely on the most significant magnitude for the transmission coefficients across these frequency bands.

Support vector machine (SVM)
Employing machine learning tools in these applications becomes essential due to the critical requirement of categorizing samples from food jars as contaminated or uncontaminated within a production chain that operates in real-time.The power and the effectiveness of using such tools for classification arise from their remarkable efficiency in rapidly making decisions without the need for extensive data preprocessing.In this section, we explore the reasons for selecting the SVM algorithm for the classification procedure.
The SVM serves as a supervised binary classifier, renowned for its robustness and precision in ML algorithms.This is particularly evident when dealing with small datasets because SVM focuses on finding the best possible separation between classes by identifying support vectors, which are the data points closest to the decision boundary (the hyperplane).This characteristic allows SVM to make effective decisions in scenarios where the dataset size is limited as in our case.SVM comes in two primary categories: linear SVM and non-linear SVM.The first is preferable in straightforward classification problems when the data from both classes can be linearly separated.On the other hand, the second, non-linear SVM, is more suitable for scenarios where the data are non-linearly separable and correlated.In both cases, SVM operates by identifying the optimal hyperplane that effectively categorizes the desired classes for classification.The effectiveness of SVM hinges on the accurate tuning of its hyperparameters, one of which is denoted as "C".This parameter plays a crucial role in adjusting the margin that separates the two classes.Regardless of whether linear or non-linear SVM is employed, selecting the appropriate value for "C" is essential.In non-linear SVM, a technique known as the "Kernel" function is used to discover the optimal hyperplane.This involves projecting the data into a higher-dimensional space, aiming to determine a hyperplane that effectively separates these data points.However, using the Kernel trick necessitates the calculation of additional hyperparameters.In our study, we use the Radial Basis Function (RBF) Kernel 33 , which introduces another important hyperparameter called Gamma ( γ ).Determining γ holds significance, as it determines the weight assigned to samples based on their distance from the origin of the training dataset.Selecting appropriate values for both C and γ is not a straightforward task.To address this challenge, we employ the Grey Wolf Optimizer 34 (GWO) to systematically search for the optimal values of these two parameters.To explore further the implementation details of the classifier and the GWO method, we follow the same procedures outlined in 35 .
The Principal Component Analysis (PCA) provides us with essential information regarding our dataset distribution, allowing visualization in lower dimensions through the variance of the most significant eigenvectors 36,37 .We applied PCA on different types of training sets to both water-based and oil-based food samples, including datasets with only amplitude values and datasets that encompass the complex nature of the S-parameters.Figure 14 illustrates the projection of the three most significant eigenvectors from the PCA outcomes.The data exhibit overlaps and demonstrates a markedly nonlinear relation between the contaminated and the uncontaminated samples in both magnitude-only and complex nature datasets for oil-based samples.On the other hand, for water-based samples, the magnitude-only dataset also displays overlaps, whereas the complex nature dataset shows linear separability and lack of correlation.Given this analysis of the plots, we investigated the possibility of employing nonlinear algorithms (SVM) that can effectively separate and categorize all our samples.

Experimental results
Within this section, we provide the results derived after applying SVM non-linear classification algorithm to the datasets previously discussed in the preceding section.The outcomes acquired pertain to the testing of two categories of food products: those that are oil-based and those that are water-based.The two upcoming subsections present comprehensive findings, encompassing various factors that can influence the performance of the ML classifier.These factors include the complex numbers dataset, inserting only the amplitude part of the measurement data in the dataset, division of dataset portions (training and test sets), different frequency bands selection, and distinct types of classifications.The performance accuracies that appear in the following tables represent the average of over 100 classification trials.In each iteration of the algorithm, our dataset undergoes shuffling, and distinct samples are selected for both training and testing, while maintaining the same hyperparameters.Additionally, the confusion matrices included correspond to the worst reproducible obtained from the 100 algorithm runs.www.nature.com/scientificreports/Before presenting our results, it is important to establish the definition of the confusion matrix, a matrix summarizing classification outcomes.Table 4 displays the confusion matrix that includes the following entries: the number of true positive (TP), indicating uncontaminated cases correctly classified as uncontaminated; the number of false positive (FP), denoting uncontaminated cases misclassified as contaminated; the number of false negative (FN), representing contaminated cases misclassified as uncontaminated; and the number of true negative (TN), indicating contaminated samples correctly classified as contaminated cases.It is important to note that the number of FN is the critical parameter, as it indicates a flaw in the detection of contaminants.
Moreover, the accuracy reported in the following tables is defined as follows: In the following subsections, we will analyze binary classifications, simply identifying contaminated and uncontaminated products, and multi-class classifications, where instead we are able to identify the contaminants type.
In the multi-class analysis, three classes are considered: uncontaminated, contaminated with PTFE, and contaminated with SLG.Although the industry is interested in detecting whether their products are contaminated or not (binary classification), the multi-class classification provides the prevalence of the contaminants.This is important for identifying the part of the production chain that is responsible for the defects.

Water-based contents
In this subsection, we present and discuss the accuracy percentages obtained from the classification results for the complex number dataset of water-based food products under different conditions shown in Table 5.The conditions include variations in the dataset split, type of classification, and the frequency band.Considering these conditions, we analyze and compare the obtained results.Table 5 presents results for two different dataset splits, that are 300-200 and 200-300 referring to the training and test portions samples of our dataset.The classification accuracy comes perfect in all binary classifications regardless of all the different conditions.In multiclass classifications, the accuracy remains consistently high across the different dataset splits, ranging from 99.8% to 100%.These results show that the performance of the used Ml model is robust and not significantly affected by the specific distribution of training and test samples.The minor errors that appear in the last two confusion matrices in Table 5 correspond to a single test sample that was contaminated with a small PTFE sphere.In the first error, it was classified as a contaminated case but with an SLG sphere, while in the second error, it was classified as an uncontaminated case, which is considered a more critical fault.www.nature.com/scientificreports/Using only the amplitude part of the scattering parameters for the classification process has practical advantages, especially for implementation in an in-line production chain.It simplifies the system by requiring a power measurement system that captures magnitude without the need for measuring the phase.In Table 6, we present the results acquired from a dataset derived exclusively from the magnitude component of the measurement samples.For binary classification approach, in the classification performed on 1.5 to 3.5 GHz frequency band, both dataset splits achieved 100% accuracy, with no misclassifications.While, from 2.5 to 3.5 GHz frequency band, high accuracy results recorded 99.7% for the two dataset splits with only a few misclassifications recorded in the confusion matrices for one uncontaminated sample classified as contaminated.On the other hand, for the multiclass classification, in the frequency band between 1.5 and 3.5 GHz, the 300-200 dataset split achieved a high accuracy of 99.9% with minor misclassifications indicated in the confusion matrices as an uncontaminated test sample recognized as contaminated.While, in 2.5-3.5 GHz frequency band, the accuracy was slightly lower at 99.5%, with a small number of misclassifications obtained.The second dataset split for both frequency bands achieved a high accuracy of 99.8%, with similar confusion matrices, which is a sample contaminated with PTFE classified as a sample contaminated with SLG.In summary, Table 6 demonstrates that the classification experiments using magnitude-only data for water achieved high accuracies, indicating the effectiveness of the approach.The results are consistent across different dataset splits and frequency bands, with minor variations in accuracy and misclassifications.

Oil-based contents
Similarly to how we presented the classification results for water-based samples, we are now presenting the results for classifying food samples based on oil content.For the binary classification on complex nature dataset, in the 6 to 10 GHz frequency band with a 250-240 dataset split, an accuracy of 96.7% is achieved.The confusion matrix shows a high number of correctly classified samples with eight false positive recorded.While for the classification over 6 to 8 GHz frequency band with the same dataset split, the accuracy slightly increases to 98% and the confusion matrix indicates a lower number of false positives (4 samples).For the multiclass classification In Table 8, in the binary classification scenario, high accuracies are obtained for both frequency bands.The classification on the 6-10 GHz band showed an accuracy of 98.3%, while the performance of the algorithm on the 6-8 GHz band achieved a slightly higher accuracy of 99.6%, and the misclassifications are only obtained only in the false positive class.For multiclass classification, in the 6 to 8 GHz frequency band the performance is perfect with accuracy of 100%, and a high accuracy of 99.8% is observed in the 6 to 10 GHz band.The notable improvement in the performance accuracy of the SVM algorithm on the magnitude-only dataset can be attributed to the exclusion of the phase component from the measurements.In the near field, the phase of scattering parameters is highly sensitive to changes in distance.Small variations in the object's position within the nearfield region lead to a change in the angle of view of the jar with respect to the measurement system, which can result in significant phase variations.Given the movement of the jar, we anticipate a high phase fluctuations, that lead to an increase in the complexity of the dataset.On the other hand, the situation differs in the classifications involving water, where comparable and almost perfect accuracies were achieved with both dataset types.This can be attributed to the high contrast in permittivity between water and the contaminant materials, making the classification process simpler.Instead, the contrast in permittivity between oil and the contaminants is relatively lower than that between water and the same contaminants.This results in complexity in the classification process with oil jar samples and increases the errors in performance accuracy.
In the concluding part of the dataset construction section and referring to Fig. 13a, b, we proposed the idea of selecting a specific subrange within the frequency bandwidths to carry out the measurements.This selection is based on the favorable transmission characteristics observed in the amplitude plot of the scattering parameters (Fig. 13a, b).The effectiveness of this proposal is validated in the results, where the classifier algorithm exhibits improved performance when using only data from 6 to 8 GHz for oil-based products.

Conclusion and perspectives
The imperative need to detect physical contaminants inside food and beverage products before market distribution prompted our focus on developing an MW sensing system to evaluate food products with varying ingredients.Considering the prevalence of water and oil as primary components in many food and beverage items, we introduced a versatile methodology applicable to both mediums.This study addressed the integration of MW sensing technology with machine learning tools for detecting contaminants in food and beverage products.The methodology encompassed a comprehensive examination of the MW sensing system, spanning the selection of suitable frequency bands to the system performance in the near-field radiated region.Our process began with the collection of scattering parameters to form datasets, subsequently proceeding to the classification stage employing the SVM learning algorithm.Notably high accuracy was achieved in both binary and multiclass classifications, encompassing datasets with complex numbers and those containing the amplitude part only.
While our study has made significant contributions to employing MW sensing technology enhanced by ML for the non-invasive evaluation of food products, it is essential to recognize its limitations to provide a comprehensive understanding of our findings.The main limitations are in the algorithm training phase.First of all, the numbers of samples used here for training were the minimum required to obtain a good classification performance.Then, in the multiclass analysis, we tried to include more contaminant materials, but, with the used SVM algorithm, the accuracy of the classification got worse.Hence, as part of our future work, we aim to enhance the robustness of our system by investigating other ML algorithms, incorporating additional contaminant materials, particularly in the context of multiclass classification.Moreover, we plan to extend our experimental analysis to a wider range of food and beverage products as well as conduct the system testing in industrial environments.

Figure 2 .
Figure 2. The EM characteristics of water and oil.(a) Relative permittivity and conductivity of water.(b) Relative permittivity and conductivity of oil.(c) Penetration depth within water.(d) Penetration depth within oil.The dotted lines within (c,d) denote the upper limit for the frequency range selected for carrying out our measurements on the samples.

Figure 3 .
Figure 3. (a) Front view of the design, (b) rear view of the design, (c) front view after fabrication, (d) rear view after fabrication.Red labels indicate the following: L1 and L2 represent the width and length of the antenna's transmission line, while R1 and R2 denote the longer and shorter radii of the four ellipses comprising the antenna structure.Additionally, L3 and L4 correspond to the dimensions of the V-cut triangular shape in the ground plane.

Figure 4 .
Figure 4.The system for near-field measurements.(a) The measurement setup displays the transmitting antenna, denoted as 1, which is the flower antenna used in the setup.(b) The measurement setup also features the receiving wideband horn antenna, labeled as 2.

Figure 5 .
Figure 5.The measured amplitude of reflection coefficients for the realized antenna in three scenarios: with an empty jar, with a jar filled with oil, and with a jar filled with water.

Figure 6 .
Figure 6.The measured amplitude of the antenna's near-field (normalized to the maximum magnitude value across all frequency points) in the absence of any jar at: (a) 2 GHz, (b) 4 GHz, (c) 6 GHz, (d) 8 GHz, and (e) 10 GHz The rectangular shape featured in the plot indicates the anticipated location of the food jar within the measurement system.

Figure 7 .
Figure 7.The design system used for E-field spatial coverage analysis.

Figure 8 .
Figure 8.The E-field spatial coverage at 2.5 GHz inside the water jar: (a) incident, (b) total, and (c) scattered.

Figure 9 .
Figure 9.The simulation system similar to the measurements except for the presence of the foreign body.
16.4 ± 1.5 X a,e -�X(geometrical) = 23.15�X(electrical) = 44.6 46.5 ± 1.5 account the range resolution.The error observed in the ( X c,d ) can be attributed to the assumed exact position of the antenna's phase center at point c, as depicted in Fig. 9.

( 6 )Figure 11 .
Figure 11.The amplitude of the IFFT results for the measured reflection coefficients.

Figure 12 .
Figure 12.The time frame of one complete data acquisition (one single measurement).

Figure 13 .
Figure 13.The normalized amplitude of the scattering matrix [S n ] for two uncontaminated samples under test: (a) water, (b) oil.

Table 1 .
The range of the relative permittivity for the contaminants, used in the measurements, in the chosen frequency ranges.

Table 3 .
The number of measurements conducted with oil and water jar samples containing various types of contaminants.

Table 4 .
The confusion matrix.

Table 5 .
Classification results on complex numbers dataset nature for water.

Table 6 .
Classification results on only amplitude dataset nature for water.

Table 7 .
Classification results on complex numbers dataset nature for oil., 95% and 95.5% performance accuracies are reported for the 290-200 dataset split respectively on the two frequency bands.The confusion matrices reveal significant misclassifications across the uncontaminated class.In summary, Table7manifests varying results across different classification scenarios.The binary classification experiments achieved high accuracy in both frequency bands, while the multiclass classification experiments exhibited lower but still effective accuracy.

Table 8 .
Classification results on only amplitude dataset nature for oil.