Mixed Gas Detection and Temperature Compensation Based on Photoacoustic Spectroscopy

In recent years, with the continuous progress of technology and the development of society, the demand for updating trace gas detection technology has been increasing. The ability to quickly and accurately detect the composition and concentration of gases has become a hot topic in current research. In response to address issues such as difficulties in judging data for classification and recognizing gas components with low accuracy, a KNN-SVM algorithm has been proposed. The algorithm primarily reclassifies ambiguous data that are close to the hyperplane but do not have a clear affiliation, capturing data characteristics more comprehensively. It determines the weight ratio of each algorithm through experiments to improve the accuracy of gas category discrimination. Experimental results show that, compared to the traditional SVM algorithm, the KNN-SVM algorithm performs better in gas classification prediction, with an accuracy rate of 99.167% and an AUC indicator of 99.375%, enhancing the accuracy of gas detection. In response to the impact of temperature on the system during the experimental process, a WOA-BP temperature compensation model was established to compensate for temperature in gas concentration detection. After comparing various optimized BP neural network models, the performance of the WOA-BP temperature compensation was the most outstanding, with an R2 of 97.89%, MAE of 1.4868, RMSE of 2.0416, and a convergence speed after 15 iterations, reducing detection errors and thus achieving precise detection of low-concentration mixed gases.


Mixed Gas Detection and Temperature Compensation
Based on Photoacoustic Spectroscopy Sun Chao , Hu Runze , Liu Niansong , and Ding Jianjun Abstract-In recent years, with the continuous progress of technology and the development of society, the demand for updating trace gas detection technology has been increasing.The ability to quickly and accurately detect the composition and concentration of gases has become a hot topic in current research.In response to address issues such as difficulties in judging data for classification and recognizing gas components with low accuracy, a KNN-SVM algorithm has been proposed.The algorithm primarily reclassifies ambiguous data that are close to the hyperplane but do not have a clear affiliation, capturing data characteristics more comprehensively.It determines the weight ratio of each algorithm through experiments to improve the accuracy of gas category discrimination.Experimental results show that, compared to the traditional SVM algorithm, the KNN-SVM algorithm performs better in gas classification prediction, with an accuracy rate of 99.167% and an AUC indicator of 99.375%, enhancing the accuracy of gas detection.In response to the impact of temperature on the system during the experimental process, a WOA-BP temperature compensation model was established to compensate for temperature in gas concentration detection.After comparing various optimized BP neural network models, the performance of the WOA-BP temperature compensation was the most outstanding, with an R2 of 97.89%, MAE of 1.4868, RMSE of 2.0416, and a convergence speed after 15 iterations, reducing detection errors and thus achieving precise detection of low-concentration mixed gases.

I. INTRODUCTION
I N THE field of modern environmental monitoring and in- dustrial safety, gas detection has always been a crucial task.Accurate and efficient detection and identification of gas components are essential for maintaining environmental quality, ensuring personnel safety, and optimizing industrial production processes [1].Traditional gas detection methods mainly rely on chemical sensors or spectroscopic instruments [2].However, these methods often require complex calibration procedures, are susceptible to external interference, and are costly.In this context, photoacoustic spectroscopy gas detection technology [3] has attracted widespread interest and research.It combines the advantages of laser spectroscopy and acoustic detection, bringing new possibilities to gas detection.Compared to traditional methods, photoacoustic spectroscopy gas detection technology has multiple advantages, including high sensitivity, real-time capability, low cost, no need for chemical reagents, and the ability to simultaneously detect multiple trace gas components.This technology analyzes acoustic signals to achieve fast and accurate detection of gas components.
In the past, to improve the accuracy of gas detection, engineering improvements were usually relied upon.The enhancement of photoacoustic signals was often used to design high-sensitivity gas sensors, improve the resolution of spectrometers, or increase the number of lasers and sensing systems in experimental setups [4], [5].These methods have achieved some success to a certain extent, but they also face some challenges such as high cost, complex instrument maintenance, and calibration difficulties.In addition, traditional methods have limited ability to simultaneously detect multiple gas components, and it is difficult to make better improvements under hardware conditions.
However, with the continuous improvement of mathematical methods and computational capabilities, the field of gas detection is undergoing a revolution.Researchers are now able to use complex algorithms and mathematical models to process and analyze gas detection data, achieving higher-level gas classification and identification.The following are some mathematical methods and algorithms leading the development in this field: Du Hongfei et al. [6] successfully addressed the recognition and prediction problems of mixed gases composed of NO 2 and NH 3 by using a genetic algorithm to globally optimize the initial weights and thresholds of the BP neural network.In their optimized GA-BP network algorithm, the qualitative recognition accuracy of mixed gases reached 100%, and in the worst case, the error of quantitative prediction did not exceed 30%.Qian Xinming et al. [7] proposed a combustible gas classification prediction model based on least squares support vector machine(LS-SVM), constructing different classification models using polynomial kernel function and radial basis kernel function.Testing on sample data showed that the accuracy of the two classifiers was similar.The classifier using a radial basis kernel function achieved a testing accuracy of 81%, which helps improve the accuracy and efficiency of gas monitoring operation.Li Peng et al. [8] proposed a new gas leak fault diagnosis method, combining the whale optimization algorithm with variational mode decomposition (WOA-VMD) and SVM.This method can adaptively obtain the optimal parameter set, with significant advantages in anti-mode mixing and noise interference.The accuracy of diagnosing gas leakage from pressure vessel acoustic signals reached as high as 99.18%.Duan Xiaoli et al. [9] proposed an improved PSO-SVM algorithm to solve the problem of overlapping spectral feature information of five different concentration ranges of mixed gases (CH 4 ,C 2 H 6 , C 3 H 8 ,SO 2 ,and CO 2 ).They used a particle mutation-constrained PSO algorithm to optimize the model's convergence path, improving the model's optimization efficiency.Compared to traditional BP network optimization algorithms, this improved algorithm not only has a faster speed but also higher predictive accuracy, significantly improving modeling efficiency.Yang Zhao et al. [10] proposed a PCA-SVM model for classifying different concentrations of mixed gases (CO, CH 4 , H 2 S, and C 2 H 6 O).Testing on randomly selected gas datasets showed that the PCA-SVM model demonstrated significant advantages in classification performance, with an accuracy of 98.974% for a gas dataset containing 13 features and even reaching 100% accuracy for a dataset containing 27 features, thus improving classification performance.W. Xia et al. [11] combined PCA and KNN algorithms to identify the components of mixed gases, using PCA to extract gas characteristics and KNN for gas type identification.Experimental results showed a significantly higher accuracy in gas identification in the reduced feature space compared to the unreduced scenario.Additionally, they compared the proposed method with PCA and SVM algorithms, finding that the new method achieved a recognition accuracy of 96.88% for the identification of mixed gas components.
Despite the significant progress of these methods in improving the classification performance and accuracy of gas detection, there are still some shortcomings.Some issues include the need for more experimental data and broader sample coverage to ensure the robustness and applicability of algorithms under different conditions.Some methods may require more computing resources and time to run, thus requiring further optimization to improve efficiency, especially in the application of real-time detection systems.Therefore, this paper proposes a KNN-SVM algorithm for the qualitative classification of mixed gases.Compared to traditional SVM algorithms, this integrated algorithm complements the shortcomings of each algorithm, more comprehensively captures the features of the data, and can further improve the accuracy of classification and identification, adapting to different mixed gases and diverse gas components.In practical applications, it can usually perform rapid classification and identification, which is crucial for real-time gas detection and monitoring systems.
In photoacoustic spectroscopy gas detection systems, temperature is a crucial parameter during gas detection, impacting the system in various aspects.Temperature has a direct impact on the generation of the photoacoustic effect.In the photoacoustic cell, gas molecules absorb light, leading to localized temperature increases, causing the expansion of the surrounding medium and generating sound waves.When the temperature rises, the gas density decreases, and the speed of sound increases, leading to changes in the propagation path and velocity of sound waves in the medium.These changes affect the propagation speed and characteristics of sound waves, thus affecting the quality of detection signals.Ma Fengxiang et al. [12] established an SVR regression model to correct the influence of temperature and humidity on acetylene gas.Compared with OLS, the SVR correction results were smoother and had better generalization ability.Ma Li et al. [13] used the random forest algorithm to perform temperature compensation for the response signals of infrared sensors to CH 4 and CO at different temperatures.The correlation coefficients between the compensated gas concentration and the response signals were 0.9203 and 0.9099, respectively, improving the accuracy of gas detection.Liu Qi et al. [14] used constant temperature control boxes, temperature control circuits, and temperature bias algorithms to achieve precise temperature compensation for the CO 2 concentration detected by infrared sensors.Finally, combined with concentration gradient experiments, they calibrated the measurement results, improving the accuracy of the measurements.Zhang Lewen et al. [15] used the change law of the absorption spectrum line intensity S(T) at variable temperatures to replace the fitting curve of the 2f amplitude, simplifying the multiple measurements of 2f peak values and fitting calculations required in the actual temperature changes and reducing errors introduced by temperature changes and other factors.Yu Zhang et al. [16] proposed the TCM method to drive the resonance of quartz crystal resonators, improving the resonance calibration accuracy by 2 orders of magnitude and reducing the frequency shift value to less than 0.3 ppm for temperature compensation calibration in quartz-enhanced photoacoustic spectroscopy.
While the above-mentioned methods for compensating detection errors caused by temperature effects in the photoacoustic spectroscopy gas detection system have shown good results, there is still room for improvement in compensating for detection errors at low concentrations and in terms of efficiency [17], [18], [19], [20], [21], [22], [23].Addressing these issues, this paper establishes a WOA-BP temperature compensation model to correct the detection errors of gas concentrations.Through experimental comparisons of various optimized BP neural network models, the performance of the WOA-BP temperature compensation model stood out, achieving an R 2 of 97.89%, MAE of 1.4868, and RMSE of 2.0416 on the test set, with 15 iterations.This improved the overall convergence speed and ensured the stability and accuracy of the photoacoustic spectroscopy gas detection system.

II. PHOTOACOUSTIC SPECTROSCOPY GAS DETECTION SYSTEM
To achieve qualitative and quantitative analysis of mixed gases, a complete gas detection system needs to be set up, mainly consisting of a light source, a photoacoustic cell, a photoacoustic signal detection, and a gas delivery system.The light source uses an infrared laser with corresponding filters, as shown in Fig. 1.The photoacoustic cell adopts the PA201 photoacoustic gas detector module, in which the infrared laser emits a periodic beam entering the PA201 photoacoustic cell to generate a photoacoustic effect.The gas delivery system consists of gas cylinders containing 12 ppm C 2 H 2 , NO 2 , SF 6 , 10 ppm NO 2 , SF 6 , 5 ppm C 2 H 2 (background gas is N 2 ), two bottles of pure N 2 , and three gas valves.The gas delivery system completes   the gas concentration needed for the experimental detection by mixing or proportioning them.Finally, the photoacoustic signal processing module detects the sound signal generated by the photoacoustic effect as shown in Fig. 2.
The PA201 photoacoustic detector is a device designed specifically for measuring trace gases.By utilizing the photoacoustic effect, when the target gas absorbs the energy generated by the modulated beam passing through the photoacoustic cell, the photoacoustic signal rises.This energy is then transferred to the heating of the gas, resulting in periodic pressure variations in the gas at the same frequency as the modulation frequency of the infrared beam as shown in Fig. 3.The design of the photoacoustic cell allows it to receive and amplify this acoustic signal.The pressure wave is detected by a cantilever pressure sensor, which moves back and forth due to changes in the surrounding gas pressure.The micro-gold-coated silicon cantilever acts like a door between the photoacoustic cell and a larger balanced cell, and the pressure wave bending of the cantilever beam and the displacement of its free end are measured using a compact laser interferometer.The detection of the signal is achieved through the tiny vibrations of the cantilever beam.
The system utilizes the resonant characteristics of the cantilever beam, giving it a specific natural frequency that matches the frequency of the photoacoustic wave.When the cantilever beam is excited at resonance, its vibration amplitude is significantly enhanced, making the pressure change more pronounced.This system, which combines the photoacoustic cell and cantilever-type pressure sensor, can play a role in trace gas measurement, achieving efficient and accurate measurement of trace constituent concentrations in the target gas.The dimensions of the cantilever beam are: thickness of 10 μm, width of 1.2 mm, and length of 5 mm, with a gap of less than 5 μm between the cantilever and the frame.The PA201 photoacoustic cell has a flow restriction function, which limits the flow through the PA unit to protect the sensitive cantilever beam structure from damage.
The measurement results are processed by a real-time digital signal processing (DSP) unit, which generates analog and digital output signals proportional to the motion of the cantilever.
The analog signal can be connected through a BNC output connector, while the digital signal is transmitted via a USB interface.Finally, the LabView software is used to display the photoacoustic signal, spectrum, and record the signal trend at a certain frequency in real-time as shown in Fig. 4.

A. SVM
In simple terms, SVM is a vector point on the support or support plane that separates two categories of data points on a hyperplane.It is used to solve classification, regression, and multi-classification problems.The basic principle is to find an optimal decision boundary between data points to separate different categories of data and ensure that the distance between this boundary and the nearest data points (support vectors) is maximized.Its key idea is to improve the generalization ability of the learning machine by minimizing structured risk.It balances empirical risk and confidence interval to ensure that good statistical laws can still be obtained with few statistical samples.This method can effectively separate data, so SVM is used to classify gas types in this paper.
Initially, SVM was a binary classification model.Assuming the data set is (x i , y i ), where x i represents the input data and is an n-dimensional vector for i = 1, 2, …, n, and y i represents the output data, which belongs to two different categories and y i ∈ [−1, 1], a hyperplane needs to be found in the n-dimensional data space.Therefore, we have the following equation: Where ω represents the normal vector, b represents the intercept, and x is the feature vector of the data point.
For a data point x, let its vertical projection onto the hyperplane correspond to x 0 , since ω is a vector perpendicular to the hyperplane, γ is the distance from the data point x to the classification interval, then : Owing to f (x 0 ) = 0, Substituting (2.1) into In order to find the interval, only its absolute value is required, then there is : The goal of SVM is to find a maximum margin hyperplane to design the decision-making optimal classification hyperplane, that is, to find maxγ.According to the definition of the interval and the constraint condition y i (ω In order to facilitate the calculation, let γ = 1, the above problem can be optimized into a minimization problem with penalty term : where C represents the penalty factor and ξ represents the relaxation factor.
In order to solve this optimization problem, the dual problem is usually used, and the Lagrangian multiplier α i is introduced to construct the Lagrangian function : where n is the number of data points.By solving the saddle point of the Lagrangian function and taking the partial derivatives of ω and b into the above formula, the original problem can be transformed into the optimal dual problem : where x i , x j represents the inner product kernel function of the nonlinear mapping.By solving α and deriving the solutions of ω and b, the separating hyperplane and the classification decision function are obtained.

B. KNN-SVM
In the task of multi-classification for diverse gas mixtures, the SVM classifier supports two types of classification methods: one-vs-one and one-vs-rest.However, both of these methods have some issues when dealing with multi-class problems, such as data bias and unbounded generalization error.Therefore, a new method called KNN-SVM is proposed, which determines the classification based on the distance from the test data point to the hyperplane.If a data point is sufficiently far from the hyperplane, it indicates a clear belonging to a certain class and can be directly classified as that class.If the distance is close but there is no clear membership, it can be classified as ambiguous data.For the data points within the determined region of the SVM, we directly use SVM for classification.For ambiguous data, we employ a combination of KNN and SVM for secondary classification through voting.This method determines the ambiguity of data by calculating the ratio between the distance from the test data point to the hyperplane and the maximum margin.
The KNN algorithm calculates the distance between the data to be classified and all the training data can be expressed as: Authorized licensed use limited to the terms of the applicable license agreement with IEEE.Restrictions apply.Among them, x i represents the input data and x j represents the training data.
According to the similarity between the distance and the data points, we can transform the distance into a weight ω i , which represents the degree of association between the input data and the training data.By calculating the weight of each category and standardizing it, we can regard these weights as the generation probability of each category.The closer the training data is, the higher the influence on determining the category of the input data is.
Assuming that the target is binary {−1, 1}, then the expression: If P 1 ≥ P −1 , then the classification result is class 1.
The regression value can be obtained by repeating the classification process all the time.
Among them, y represents the output result and f(x i ) represents the value of the nearest neighbor data.
When determining the category of fuzzy data, KNN and SVM common voting points are used for secondary classification, in which the decision function of SVM is expressed as where K(z i , z) represents the kernel function.
The classification rules in the KNN algorithm are expressed as : where C represents the category.
The double voting mechanism combines the results of KNN and SVM to improve the accuracy of classification.Under this mechanism, the two classifiers classify the samples separately, and then combine their results according to the weight.Final_Result = ω SVM Result SVM + ω KNN Result KNN (13) In the experiment, the weight of SVM is 1.5 times that of KNN.This method fully considers the fuzziness of data and avoids the problem of misjudgment caused by too strict conditions.The double voting mechanism makes full use of the advantages of KNN and SVM, and can improve the classification performance in multi-classification problems.According to the characteristics of the problem, the weight can be adjusted to achieve the best results.

C. Experiments and Analysis
In order to perform quantitative and qualitative analysis of mixed gases, first, different concentrations of three gases: C 2 H 2 (12 ppm, 5 ppm), NO 2 (12 ppm, 10 ppm), and SF 6 (12 ppm, 10 ppm) are detected separately.After mixing with nitrogen in ratios of 1:1 and 1:2, six different concentration groups for the three gases are obtained and tested, with each concentration group of each gas tested in 10 sets, resulting in 60 sets of data.Next, 12 ppm of C 2 H 2 , NO 2 , and SF 6 are mixed in pairs and tested with a 1:1:1 nitrogen mix, with each concentration group of each gas tested in 10 sets, yielding 40 sets of data in total.Then, 12 ppm of C 2 H 2 , NO 2 , and SF 6 are directly mixed and tested, with 10 sets of tests for each gas, resulting in 30 sets of data as validation data.Finally, the collected data set is combined and randomly divided into training and testing sets with a probability ratio of 6:4.All the above data are extracted for absorption peak and wavelength as features and tested under the same environmental conditions.
In the detection of each single gas, due to the detection of six different concentrations of gas amplitude changes, the absorption peaks of these six known concentrations can be linearly fitted, so that the concentration of the gas can be inverted in the mixed gas detection.Each concentration is detected in 10 groups, and the average of the 10 groups of absorption peaks is used as the required eigenvalue for linear fitting.The fitting lines of the three gases are as follows (as shown in Figs.5-7): From the above diagram, it can be seen that the R 2 of the fitting line of the three gases is above 0.98 after adjustment, and the accuracy of gas detection can be obtained.After that, the concentration of the gas can be inverted according to the detection of the mixed gas, and the quantitative analysis of the mixed gas can be completed.According to the collected experimental data, the concentration of a single gas of the mixed gas species is shown in the following Table 1:

TABLE I CONCENTRATIONS OF INDIVIDUAL GASES IN THE MIXED GAS
The performance of SVM largely depends on the selected kernel function and its associated parameters.By optimizing the parameters and comparing various types of kernel functions, we can select the kernel function with the highest accuracy and its corresponding parameters.The AUC value represents the probability that a classification model will rank a positive class sample ahead of a negative class sample based on its score.The larger the AUC value, the better the performance of the model.This approach allows us to choose the most suitable kernel function from multiple options, thereby improving the performance of SVM.
The best parameters suitable for this dataset were determined through parameter tuning, resulting in the following values: C = 10, degree = 2, gamma = 'scale', kernel = 'linear".To validate the effectiveness and superiority of the algorithm  proposed in this paper, a qualitative analysis was performed on the mixed gases.The KNN-SVM algorithm was compared with the traditional SVM algorithm in terms of classifying and predicting the detected mixed gases.The specific results of the parameter comparison are as follows (as shown in Figs.8-9): Based on the comparison of the data in Tables II and III, it is evident that the KNN-SVM algorithm proposed in this paper shows a significant improvement in the accuracy of gas

TABLE III PERFORMANCE COMPARISON BETWEEN KNN-SVM AND TRADITIONAL SVM
classification prediction compared to the traditional SVM algorithm after parameter optimization.The accuracy can reach 99.167%, and the AUC value reaches 99.375%.It demonstrates better analytical capabilities for the qualitative prediction of mixed gases, enabling a more accurate classification of mixed gases.Through linear fitting and the KNN-SVM algorithm, it is possible to infer the concentration and types of mixed gases.The KNN-SVM algorithm effectively combines the advantages of KNN and SVM, thereby enhancing the accuracy of mixed gas detection.

A. WOA-BP
The Whale Optimization Algorithm (WOA) is an optimization algorithm that simulates the search process of individual whales.It continuously adjusts the positions and velocities of whales to find the optimal solution.Their primary hunting method is bubble-net feeding, as shown in Fig. 10.WOA combines with the BP neural network and adopts a spiral-shaped simulation of the bubble-net attack mechanism of whales.It optimizes the parameters of the neural network through collaborative searching for food.It uses random or best search agents to simulate hunting behavior.WOA-BP, by simulating the collaborative search behavior of whales, more effectively explores the parameter space of the neural network, thereby improving training efficiency and performance.
The main steps of the algorithm are as follows (as shown in Fig. 11): 1) Normalize the input and output data by using the mapminmax function to map the data to the range of 0 to 1.This is done to facilitate better training of the neural network.2) Use the WOA algorithm to determine the structure of the neural network.This is achieved by calling the WOA function and passing the input and output data of the training set to obtain the optimal number of hidden layer nodes.3) Based on the optimal number of hidden layer nodes and other parameters, build a feedforward neural network model with hidden layers using the newff function.The model uses tansig and purelin as activation functions and trainlm as the training algorithm.

B. Temperature Compensation
To verify the effect of temperature on the photoacoustic spectroscopy gas detection system, we conducted a temperature range gas detection experiment.In this system, the temperature can be controlled using the Tempset settings in the PA201 photoacoustic module, which is the temperature control module.The calibration value is set to 50 °C, and the maximum temperature can be set to 60 °C.Therefore, we performed gas detection experiments for 12 ppm NO 2 gas at temperatures ranging from 25 °C to 60 °C, with measurements taken every 5 °C.For each temperature, we measured the photoacoustic signal amplitude for 0-300 s and obtained the corresponding gas waveform.We conducted 5 sets of measurements.The gas concentration at each temperature was determined by fitting the NO 2 peak value to the gas concentration relationship graph obtained in Section III-C.Since the system was calibrated at a detection temperature of 50 °C during installation testing, we set the detection error for 12 ppm NO 2 gas concentration at 50 °C to 0. Below are the test data for 12 ppm NO 2 at temperatures ranging from 25 °C to 60 °C, with 5 °C intervals.From the above Table IV, it can be seen that temperature has a significant impact on the photoacoustic spectroscopy gas detection system.Taking 50 °C as the calibration temperature for the system, we can observe that as the temperature difference between the detection temperature and the calibration temperature increases, the detection error for gas concentration also increases.Especially when the detection temperature decreases to 25 °C, the error between the detection result and the actual value becomes quite large.To address this issue, appropriate temperature compensation measures must be taken to improve the performance of the photoacoustic spectroscopy gas detection system at different temperatures.

C. Experiments and Analysis
To evaluate the performance of the WOA-BP neural network algorithm, feature values were extracted from the photoacoustic signal amplitudes measured at each temperature from 0 to 300 seconds, with a sampling interval of 15 seconds.These feature values were used as inputs, while the corresponding temperatures were designated as outputs.With 5 sets of data measured Authorized licensed use limited to the terms of the applicable license agreement with IEEE.Restrictions apply.for each temperature, a total of 40 datasets were collected.Among these, 60% were randomly selected as the training set and 40% as the testing set.The training results of this algorithm were then compared with those of previous algorithms such as BP, GA-BP, and PSO-BP, which are used for neural network temperature compensation models, in order to verify and analyze the performance of these four algorithms.
From the above graph as shown in Fig. 12, it is clearly evident that WOA-BP exhibits significant superiority in optimizing the BP temperature compensation algorithm.This algorithm not only demonstrates a higher degree of predictive fitting for temperature compensation in the photoacoustic spectroscopy gas detection system but also performs better in terms of prediction error.In comparison to the other two optimization methods, WOA-BP showcases its distinct advantages.
In order to more intuitively compare the compensation effects of these algorithms, various indicators of these algorithms will be listed as shown in Fig. 13 and Table V.
From the above graph and table, it can be observed that the temperature compensation performances of these four BP compensation algorithms differ.Compared to the traditional BP network, the three optimized BP network compensation algorithms show significant improvements.Among them, the WOA-BP temperature compensation algorithm achieves the highest performance, with an increase of approximately 8% and Based on the data analysis above, it can be concluded that the WOA-BP temperature compensation algorithm performs the best in detecting gas concentration compared to the traditional BP network temperature compensation algorithm and the other two optimized BP temperature compensation algorithms.The WOA-BP algorithm optimizes the learning process of the neural network, enabling the model to accurately capture the impact of temperature changes on gas detection results and improve the prediction accuracy.Compared to the other two optimization algorithms, WOA-BP more effectively avoids overfitting during the optimization process, ensuring the model's generalization ability.This is particularly important for temperature variation scenarios in practical applications.Additionally, WOA's global search capability makes the algorithm more efficient in finding the optimal solution, improving overall computational efficiency.To further demonstrate the effectiveness and superiority of the WOA-BP compensation algorithm, the deviations of the measured NO 2 concentration values at 12 ppm under different temperature ranges after applying the four BP compensations are calculated and compared, as shown in Fig. 14.
In Fig. 14, it is also evident that after temperature compensation, the concentration values obtained using the WOA-BP compensation algorithm are the most stable, all within 0.5 ppm.While some other compensation algorithms may exhibit better compensation effects for individual temperature values, overall, the errors are larger and even more significant, indicating that their performance is not as stable as that of the WOA-BP compensation.The data above demonstrates that the WOA-BP temperature compensation algorithm can more effectively adjust the weights and biases in the neural network, leading to higher fitting accuracy and lower prediction errors.Furthermore, it shows better adaptability and stability when handling different types and ranges of temperature variations.

V. CONCLUSION
This study addresses the issue of low accuracy in gas component identification by proposing a KNN-SVM algorithm.This algorithm conducts a secondary classification on ambiguous data that are close to the hyperplane but lack clear affiliation, combining the dynamic updating capability of KNN with the strong generalization ability of SVM to capture data features more comprehensively.Experimental results show that, compared to the traditional SVM algorithm, the KNN-SVM algorithm achieves a gas classification accuracy of 99.167% and an AUC of 99.375%, enhancing the accuracy of gas classification.Furthermore, changes in the detection environment temperature can affect the precision of gas detection.To address this issue, this paper designs a WOA-BP temperature compensation model for the detection system, compensating for errors in gas concentration experimental results.The WOA-BP temperature compensation method achieved an R 2 of 97.89%, an MAE of 1.4868, and an RMSE of 2.0416, with 15 iterations.The compensation range can be ensured at the ppm level, improving the overall convergence speed and ensuring the stability and detection accuracy of the photoacoustic spectroscopy gas detection system.

Fig. 8 .
Fig. 8. Confusion matrix and ROC curve for gas classification using traditional SVM algorithm.

4 )
Train the neural network model.Set parameters such as the number of training epochs, learning rate, and minimum training error goal, and use the train function to perform the training.5) After training is completed, use the trained neural network model to make predictions on the training and test sets.The predicted results are then transformed back to their original scale through the process of inverse normalization.

Fig. 12 .
Fig. 12. Prediction results of training set and test set of four temperature compensation algorithms: (a) WOA-BP training set prediction; (b) WOA-BP test set prediction; (c) PSO-BP training set prediction; (d) PSO-BP test set prediction; (e) GA-BP training set prediction; (f) GA-BP test set prediction; (g) BP training set prediction; (h) BP test set prediction.

Fig. 13 .
Fig. 13.Number of iterations of three algorithms: (a) the number of PSO-BP iterations; (b) the number of GA-BP iterations; (c) the number of WOA-BP iterations.

TABLE II SVM
CLASSIFICATION PERFORMANCE COMPARISON WITH DIFFERENT KERNEL FUNCTIONS

TABLE IV CONCENTRATION
OF12 PPM NO 2 DETECTED AT DIFFERENT TEMPERATURES

TABLE V DIFFERENT
TEMPERATURE COMPENSATION ALGORITHM INDICATORS 5% compared to GA-BP and PSO-BP, reaching 97.89%.The mean absolute error (MAE) in the training set decreases by 1.7126 and 0.0449, resulting in only 1.3841, while the MAE in the testing set decreases by 1.6812 and 1.0948, resulting in only 1.4868.The root mean square error (RMSE) in the training set decreases by 1.4225 and 0.1645, reaching 2.0749, while the RMSE in the testing set decreases by 1.7341 and 1.2161, reaching 2.0416.Additionally, the number of iterations decreases by approximately 63% and 44%, reducing the convergence time of the algorithm.The coefficient of determination (R 2 ) in the training set increases by approximately 6% and 1%, reaching 96.77%, while the R 2 in the testing set also improves.