Algorithm Research for Bubble Detection in Capacitive Liquid Level Sensor of Fully Automated Immunoassay Analyzer

Fully automated immunoassay analyzers are integral to clinical testing, with liquid-level detection crucial to mitigate false measurements and cross-contamination. This study introduces a bubble detection algorithm based on the Random Forest machine learning model to address bubble detection in analyzers using capacitive sensors. The algorithm processes collected capacitance data, accurately identifying bubbles and ensuring sampling accuracy. Data preprocessing, feature extraction, and classification enable precise bubble detection. Compared to the traditional CART decision tree algorithm, this algorithm demonstrates superior bubble detection performance, indicating its significant research value and potential for liquid-level detection in fully automated immunoassay analyzers.


INTRODUCTION
Fully automatic in vitro diagnostic instruments play an important role in clinical testing.Liquid-level detection technology is key to achieving full automation and preventing false measurements and reagent cross-contamination.It is mainly achieved by controlling the depth of the dispensing needle into the sample and reagent to be tested, reducing dispensing errors, avoiding cross-contamination, avoiding the dispensing needle inhaling air bubbles and precipitates at the bottom of the sample, and improving detection accuracy.
There are many technical problems with liquid-level detection technology.The different heights, viscosities, and adhesion of the liquid, the different depths of the dispensing needle, and the unstable carry-over on the outer surface of the dispensing needle can cause system errors.Whether there are bubbles under the liquid level, whether there is foam on the liquid level, and whether there are multiple liquid phases, such as layering, will also affect the liquid level detection technology.The problem of bubbles in the liquid is particularly important, which affects the accuracy of liquid-level detection.It will also make the sample sampling volume inaccurate, leading to blockage of the liquid route and affecting the detection accuracy.To improve the efficiency and detection accuracy of fully automatic immunoassay analyzers, capacitive liquid-level sensors are commonly used for liquid-level detection.However, bubbles can affect the readings and detection accuracy of capacitive liquid level sensors 1 .Therefore, a new bubble detection algorithm needs to be studied to accurately identify bubbles and ensure accurate sample volume.

Working Principle of FDC2214 Capacitance Liquid Level Sensor
Capacitive sensing, a cost-effective, high-resolution, non-contact technology, is suitable for various applications, including proximity detection, gesture recognition, and liquid-level monitoring.While noise sensitivity remains a challenge, the FDC2214 series capacitive-to-digital converters mitigate this through their unique electromagnetic interference-resistant design, offering narrowband design for interference resistance, high resolution, and high-speed operation support 2 .This is shown in Figure 1.The working principle of this sensor is to measure the capacitance between the liquid surface or bubbles and the probe.Therefore, when the dispensing needle touches the liquid surface or bubbles, the capacitance values collected will change.These changes in the process curve can be classified using random forests, which can determine whether the liquid surface or bubbles have been detected.

Design Idea of Bubble Detection Algorithm
First, some functions were defined for calculating curve feature values.Then, feature extraction was performed on the bubble and non-bubble data to generate the corresponding feature matrices 3 .The dataset was split into a training set and a test set.The Random Forest algorithm was used for model training and evaluation.Finally, we output the accuracy and feature importance of the model and read data through the serial port to store it in a CSV file.

Random Forest Algorithm
The Random Forest algorithm is an ensemble learning method that combines the simplicity of decision trees and the advantages of ensemble learning to improve the accuracy and stability of model 4 .It constructs multiple decision trees by randomly selecting subsets of features and samples, ensuring the diversity of decision trees and reducing overfitting.In the prediction phase, Random Forest combines the predictions of each tree to improve generalizability and robustness.

Algorithm Implementation Steps and Flow
The bubble detection algorithm aims to identify bubbles in the liquid by analyzing sensor data.The algorithm consists of two main parts: data collection and feature extraction and bubble classification.In the data collection part, the COM3 port is first opened through the serial port connection, and the baud rate is set to 115200.Then, data is read from the sensor and stored in a CSV file.
The feature extraction part first defined a function Waveform, which is used to calculate the curve feature values of the data.This function describes the features of the data by calculating the maximum, minimum, median, mean, variance, peak, peak-to-peak, effective value, and other parameters 5 .Next, a differential function Diff is defined to calculate the differential of the data.Then, by calling the Waveform and Diff functions, the read data is subjected to feature extraction to obtain a set of feature vectors.These feature vectors represent the relevant features of whether bubbles exist or not.
The bubble classification part uses a Random Forest classifier 6 for the classification task.Firstly, data is read from the CSV files of the labeled bubble data and non-bubble data, and feature extraction is performed on the data 7 .Then, the extracted feature vectors are merged into a feature matrix, and a target variable is created to indicate whether each sample comes from the bubble or non-bubble class.Next, the dataset is divided into a training set and a test set.A Random Forest classifier is used for model fitting, and the model performance is evaluated on the test set 8 , as shown in Figure 2.

Algorithm Verification and Performance Evaluation Method
We use the test set to evaluate the model.The score method of the trained model is called, with the input of the test set feature matrix and target variable, to calculate the accuracy as per Equation (1), precision as per Equation (2), and recall as per Equation (3).These indicators provide a basis for a comprehensive evaluation of model performance 9 .TP and TN represent the true positive and true negative predicted by the model, and FP and FN represent the false positive and false negative.Accuracy is the proportion of correct predictions to total samples; precision is the proportion of true positive samples in the predictions 10 ; recall is the proportion of true positive samples that are correctly predicted.

Sample Data Preprocessing
In this study, we collected a set of sensor data curves with a total of 2000 data entries.These data are divided into two categories: 1000 curves with bubbles and 1000 curves without bubbles.The curves without bubbles involve two solutions, one is pure water, and the other is alcohol.The curves with bubbles are produced by mixing pure water and detergent.We further classified the curves with bubbles.According to the shape of the bubbles, we divided them into five types: bubbles with thicknesses of 20 mm, 12 mm, 8 mm, 6 mm, and 3.5 mm.To keep the proportions evenly distributed, the number of each type of bubble in the dataset is equal, as seen in Table 1.

Preliminary Analysis of Sample Data
In the study of the capacitive bubble detection algorithm, we used three key charts to illustrate our findings.First, we compared the capacitive properties of water and alcohol.Then, we compared the situations with and without bubbles, and finally, we studied the capacitance changes of 20 mm thick bubbles in water.
Figure 3 shows the capacitance detection results of water and alcohol without bubbles.The capacitance values of these two liquids are close, indicating that their dielectric constant differences are not significant 11 .Figure 4 shows the capacitance detection results of bubbles of different thicknesses.It can be seen from the chart that the change in bubble thickness does not cause a significant change in capacitance value.This may be attributed to the fact that the bubble thickness does not significantly affect the dielectric constant within a certain range 12 .This result provides clues for further optimizing and improving the capacitive bubble detection algorithm 13 .Figure 5. 20 mm Thick Bubble and Water Figure 5 compares the capacitance detection results of 20 mm thick bubbles in the presence and absence of bubbles.Obviously, the capacitance value changes significantly with bubbles, indicating that the presence of bubbles can significantly affect the change in the capacitance value curve.  2 compares the performance of four predictive models -Random Forest, CART, C4.5, and ID3 -across accuracy, precision, and recall.The Random Forest model demonstrates perfect performance across all metrics.The CART model shows almost flawless prediction with a slightly lower recall.Both the C4.5 and ID3 models display high performance, albeit with marginally more false positives.In summary, all models exhibit strong predictive capabilities, with Random Forest standing as the best-performing model.

Conclusions
Our study addresses bubble detection in fully automated immunoassay analyzers using capacitive liquid-level sensors.To overcome the shortcomings of traditional sensors, we present a new bubble detection algorithm, employing the random forest machine learning model.The algorithm, through capacitance data analysis, accurately identifies bubbles, ensuring precise sample intake.Experimental results highlight its superiority over the traditional CART decision tree algorithm in bubble detection accuracy.Future work will focus on algorithm optimization, enhancing stability and accuracy in complex environments, and investigating its potential applications in related fields.

Figure 3 .
Figure 3. Water and Alcohol without Bubbles Figure 4. Bubbles of Varying Thickness

Table 2 .
Metrics Analysis of CART and Random Forest