Application of Temperature Compensation Combined with Neural Network in Infrared Gas Sensor

Due to the state of the gas to be measured, the detection mechanism of the pyroelectric detector and the temperature drift of the peripheral circuit components and the detection of the ambient temperature will interfere with the measurement accuracy of the nondispersive infrared gas sensor from many aspects. This paper proposes a temperature compensation method based on the BP neural network. The compensation function of the gas sensor is realized by programming the various functional parameters in the neural network through the program provided in the Matlab neural network toolbox. Experimental simulation results show that the proposed method effectively reduces the influence of external temperature on the gas sensor output and improves its accuracy and stability.


Introduction
Influenced by the state of the gas to be measured, the detection mechanism of the pyroelectric detector and the temperature drift of the peripheral circuit components and the detection of the ambient temperature will interfere with the measurement accuracy of the nondispersive infrared gas sensor from many aspects. Gas sensor temperature compensation is generally divided into hardware compensation and software compensation; the main idea of hardware compensation is through the external equipment of gas sensor chamber temperature in dynamic balance, so as to avoid the measurement error caused by detection of environmental temperature change; representative is Yongquan et al. for a gas sensor accurate temperature control method and device, through real-time detection of the current ambient temperature, to correct the temperature target using the temperature control module [1]. However, due to the drift of electronic components and the precision of component welding, the measurement circuit of hardware compensation is often of low reliability and high cost. The main idea of software compensation is to fit the gas sensor according to the temperature experiment results to correct the nonlinear effects of the least squares method, interpolation method, polynomial method, and the validity of the infrared gas sensor. This paper tries to use BP neural network to compensate the gas sensor for temperature.

States of the Art
The research on infrared gas sensor emerged in the 1970s. After decades of development, it has a relatively mature technology and is widely used in air pollutant monitoring, automobile exhaust composition analysis, mine gas monitoring and special gas concentration detection, and other fields of [2]. Representatives are the following: SM-SF6 SF6 gas sensor of SmartGas, measuring range of 0~1000 ppm, detection accuracy of ±2% FS, resolution of 1 ppm, and preheating time of 30s, and CozIR CO 2 gas sensor of GSS, measuring range of 0~5%, with warm compensation function. Detection accuracy can reach ±0.03% FS, repetitive error less than 1.7% Fs and S8 CO 2 gas transmitter of SenseAir 0~2000 ppm and ±1.2%. TIF SF6 can set seven leakage concentration; detection accuracy can reach 3 g/year. In year 2010, Xiaodong of Zhengzhou University conducted a study based on the design of the infrared absorption type COz concentration analyzer. Using the ATmega128 microcontroller as the control core, the measurement range is ranging from 0 to 5%. Relative error is less than 2% [3]. In 2011, Jing of Fudan University studied on the key technology of NDIR portable gas sensor. We propose a novel MEMS microenrichator based on silicate-1 molecular sieve material. Midinfrared hollow fiber is introduced as the gas chamber of NDIR portable gas sensor, effectively improving the system signal-to-noise ratio. The lower detection limit can reach 5 ppm [4]. In 2014, Harbin Institute of Technology conducted research on gas concentration detection alarm device based on NDIR technology. A quadratic polynomial fitting curve was used for the calibration. The measurement range is ranging from 0 to 5%. The detection accuracy can reach ±0.05% FS [5]. In 2016, Lili of the University of Science and Technology of China conducted a study on the key technology of aircraft fire alarm detection based on CO 2 gas concentration detection. The temperature compensation model was established by using the polynomial partial least squares method and by low temperature (4°C), room temperature (25°C), and high temperature (40°C). The measurement range is from 0 to 1000 ml/m 3 etc. [6].
With the continuous improvement of modern gas detection means, the detection results of gas sensors are becoming more and more accurate. This is due to the following two factors: first, the gas sensor materials, the performance of the sensor accuracy, and the optimization and development of the gas sensor detection model, especially the application of machine learning algorithm to the sensor modeling analysis, replacing the traditional simple controller AD sampling data conversion process. The sensor detection model input is no longer limited to a single variable. Therefore, establishing a suitable measurement model for the gas sensor is helpful to improve the stability of the detection system.
The Slovenian Joseph Stefan Institute was the first to attempt to use neural networks in short-term air pollution prediction and to predict SO pollution around Slovenian thermal power plants, proving that the method can reduce the peak of pollutant concentrations in critical meteorological conditions [7]. The University of Arizona has developed a portable, low-power, battery-powered hydrogen detection system. The system has a wide hydrogen detection range, and a dual set point of sound and flashing alarms, and a direct readout of the hydrogen concentration ppm [8].
Sudan Qaboos University of Oman has proposed O3 sensor modeling using neural networks in the lower atmosphere to predict the relationship between tropospheric O3 concentration and meteorological conditions and various air quality parameters. The results show that artificial neural network (ANN) is an effective method for modeling air pollution [9]. Huazhong University of Science and Technology proposed a fiber hydrogen sensor based on BP artificial neural network, which uses the neural network to eliminate the internal and external effects of light source fluctuations, light loss, and optical fiber beam jitter, and the accuracy of the sensor was improved to 0.1% [10].
Southeast University designed a hydrogen concentration detector based on LPC2104 controller for the thermal con-ductivity hydrogen sensor TCS208F, analyzed the hardware circuit and software design of the system, and applied it to the hydrogen purity detection of Changzhou Halipu Company [11]. Nanjing University of Information Engineering adopts the improved genetic algorithm to optimize the backpropagation neural network algorithm and realize the temperature compensation of the HMP45D humidity sensor. Compared with the measured data under multitemperature conditions, it is found that the improved measurement system improves the compensation accuracy somewhat, and the convergence rate is also faster [12].
Nanjing University of Science and Technology designed a multisensor hydrogen leakage detection system, through the experimental test analyzed the temperature on the sensitivity and response characteristics of metal oxide hydrogen sensor, and through the concentration measurement sensor and reference sensor resistance rate difference, reduce the environmental temperature interference to the measurement results [13].
New methods for simulation and digital hardware and software for detecting hydrogen concentrations are proposed by Amir Kabir University of Technology in Iran. With the advantages of MEMS technology, the digital and analog circuits of the MEMS hydrogen analyzer can calculate the conductivity between the heating power loss and the temperature difference between the sensor and the environment, thus realizing the measurement of hydrogen concentration with a maximum accuracy error of about 0.2% [14].
In 2016, Lamamra and Rechem proposed an artificial neural network (ANN) modeling method for the metal oxide gas sensor TGS2610 and optimized it through genetic algorithm. The comparative results of ANN model and experimental data showed good consistency, which verified the reliability of this model [15]. China University of Mining and Technology has developed a new MEMS gas sensor based on neural network temperature compensation. In view of the problem that the new thermal conductivity gas sensor is greatly affected by temperature, BP neural network, and RBF neural network, China University of Mining and Technology has developed a new MEMS gas sensor based on neural network temperature compensation, so that high and low temperature can meet the requirements of the system [16].
Nanjing University of Information and Engineering studied the temperature and humidity sensor compensation algorithm based on BP neural network. The BP neural network is improved by the artificial fish swarm algorithm, and the BP neural network is improved by the simplified particle swarm algorithm, respectively, which can reduce the interference of environmental factors to the sensor measurement results to a certain extent [17]. Shandong University developed a hydrogen measuring instrument for the containment of nuclear power plants, analyzed the influence of pressure, temperature, and humidity factors on the measurement results of the thermal conductivity probe, and compensated the temperature and humidity digital according to the fitting formula of the measurement data, and the calibration accuracy can also meet the design requirements [18]. The hydrogen detection system using the temperature monitor is designed by the Tuxi University of Technology.

Journal of Sensors
The structure diagram of the hydrogen detection system based on the temperature monitor is specially used for the high concentration of hydrogen measurement in hydrogen fuel cells. Based on the neural network algorithm, to measure the H2 concentration in a wide dynamic range by learning the solid temperature in a hydrogen-containing gas, the system can measure hydrogen in the range of 40% to 100% [19]. From the above studies, we can see that using the appropriate algorithm for modeling can effectively improve the gas sensor accuracy. From the above studies, we can see that using the appropriate algorithm for modeling can effectively improve the gas sensor accuracy. This paper presents a gas sensor temperature measurement method incorporating BP neural network compensation. This method effectively reduces the influence of external temperature on the gas sensor output and effectively improves the accuracy and stability of the sensor. The overall method is shown in the following Figure 1. One information is not stored in one place but is distributed throughout the network by content. Instead of storing only one external information, it stores parts of multiple information. The entire network processes multiple information before it is stored throughout the network, so it is a distributed storage mode.

Massively Parallel
Processing. The storage and processing of neural network information are combined; that is, the storage of information is now in the distribution of neurons' interconnection and is mainly processed in large parallel distribution, which is superior to the modern digital computer with serial discrete symbol processing.
3.1.3. Self-Learning and Adaptability. The direct connection weights of each layer of the neural network have a certain tunability. The network can determine the weights of the network through training and learning, showing a strong adaptability to the environment and the self-learning ability of external things.

Strong Robustness and Fault
Tolerance. The distributed information storage mode of neural network makes it have strong fault tolerance and associative memory function, so that if a certain part of the information is lost or damaged, the network can still restore the original complete information, and the system can still run. According to statistics, in all neural network applications, BP neural network accounted for more than 80%. BP neural network is favored by many industries because of its good nonlinear approximation ability and its ease of use. The back propagation (BP algorithm) used by the BP neural network is the most mature and widely used tutor learning algorithm in the feedforward neural network. The application of pattern recognition, image processing, information processing, intelligent control, fault detection, enterprise management, market analysis, and other aspects has achieved remarkable results.
3.2. The BP Neural Network Structure. The BP neural network [20][21][22][23][24] is a multilayer feedforward network trained by the error backpropagation algorithm, which is usually used to classify and predict the data. The most important part of BP neural network is the learning part of its weight and threshold. Generally, the learning process is divided into two parts. One part is the forward transmission process; that is, the input sample is transmitted from the input layer layer by layer to the output layer. The other part is the error reverse transmission process; that is, if the actual output of   Journal of Sensors the output layer is not the desired output, the error is an adjustment signal layer by layer, processing the connection weight matrix between neurons to reduce the error. After a repeated learning process, the error is finally reduced within the initially set range. The BP neural network is composed of the loser layer, the output layer, and the intermediate layer between the two. The middle layer can be a single layer or a multilayer, because the middle layer is not connected to the external environment, so it is also called the hidden layer. The layers are connected between the input layer, the hidden layer, and the output layer, but not between the individual nodes of the single layer. The structural diagram of the BP neural network is shown in Figure 2. The input layer mainly sends the training samples to the network, while the hidden layer and the output layer mainly train the sample data. The parameters obtained by the network training samples are stored in the weights between the neuron and the threshold of each neuron.

The BP Neural Network Training Process
3.3.1. Forward Propagation. The input sample is processed from the input layer layer by layer and then transmitted to the output layer, and the state of each layer only affects the state of the next layer. The output layer compares the actual output with the desired output, and if the actual output does not equal the desired output, it enters the backpropagation process. Figure 3 is a flow chart of the BP neural network algorithm.
There are n input layer nodes, q hidden layer nodes, and m output layer nodes, the weights between input layer and hidden layer are v ki , and the transfer function of hidden layer is f 1 ð:Þ. The weight between the hidden layer and the output layer is w ki , and the transfer function of the output layer is f 2 ð:Þ [25]; then, hide the layer node output w ki f 2 .
Output layer node output: In this way, the BP network completes the approximate mapping of the n-dimensional space vectors to the m -dimensional space.

Back Propagation.
First, the error function is defined with p learning samples, with x1, x2,... For the xp representation, the pth sample that enters the network gets the output y p j , j = 1, 2, ⋯, m, using the squared error function: The expected output is given in the formula for t p: j . For the p samples, the global error is For backpropagation, the error signal is transmitted back by the original forward propagation path, and the weight coefficient of each neuron in each hidden layer is constantly modified, so that the global error signal E tends to be minimized. During the learning process, the standard BP algorithm uses a unified learning speed for all the weights, and the length of each step is proportional to its directional slope. The updated basic weight formula [26] is In the formula, W jk is the step length parameter (learning rate); ∂E is the nth weight correction; and ∂W jk is the negative gradient of error squares.
Since BP only uses local gradient information, the value must be small, thus making the algorithm skip the minimum value, which leads to slower learning convergence speed. In order to speed up the convergence speed, the common method is to add the momentum factor, whose weight update formula is as follows: In the formula, μ is the momentum factor used to damping local oscillations.. In order to meet the requirements of accelerating training speed and avoid local minimum value, the method to improve BP algorithm is proposed: (1) Different learning rate is used for each weight and represented by the exponential decay function (k). This allows the learning rate to increase faster in flatter regions than in steeper regions (2) In the learning process, the learning rate can be adaptively adjusted according to the gradient information of the error function E, to improve the generalization ability of the network and improve the network convergence performance [27] Output layer Hidden layer Input layer Sample Actual layer

Expected output signal
Error e + - Figure 2: Basic structure of the BP network.

Journal of Sensors
(3) The momentum term is used in the algorithm, and the momentum term, like the learning rate, also changes (4) In order to avoid too large learning rate or momentum, set the upper limit (5) Parameters and probability P are used to control the memory and recovery of the network learning process; that is, if the number of error increases is greater, the learning rate and momentum coefficient will be reduced, and the best point will be searched to learn again. In order to avoid fluctuations, the search is carried out randomly in the way of probability P

Hybrid PSO-BP Neural Network.
Since the initial weights and thresholds of the BP neural network are randomly generated, when the selection of the two is inappropriate, problems such as slow network convergence and local minimum may occur. For this problem, this paper further uses the PSO algorithm to optimize the BP neural network, reduce the influence of the initial value on the prediction results of the BP neural network, and improve the network convergence speed and prediction accuracy. When the PSO algorithm is used to optimize the BP neural network, the degree of the particle search results is usually determined by the fitness value, which can be based on the mean squared error function. And the formula is where n is the number of network learning samples and Y p ðiÞ is the expected output value of neurons in the network output layer. The process of optimizing the BP neural network by the PSO algorithm is shown in Figure 4. When the fitness value meets the accuracy requirements or the number of iterations reaches the set upper limit, the best speed and position of the PSO algorithm in finding the particle in the solution space are taken as the weight and threshold of the BP neural network, and the PSO-BP hybrid neural network prediction model is established.
Hidden layer + + Output layer Figure 3: Flow chart of the BP neural network algorithm. Figure 5. In the figure, V c is the working voltage, V h is the heating voltage, the output voltage V is the amount to be measured, and the sensitivity S is V0/Vg, where V0 and V g are the output voltage of the sensor in the air and the measured gas, respectively.

Gas Sensor Test Calibration
Data. The use of BP neural network for temperature compensation is because of the basic characteristics of the neural network, so that the sensor has a complex nonlinear mapping, self-organization, selflearning, and reasoning capabilities [28].Only the sample needs to be trained to simulate the intrinsic relationship of input and output. The input amount of the BP neural network is the sensitivity S. Under the influence of temperature, the sensitivity S of the gas will change, and the output is the concentration C′, requiring the output C′ of the neural network to approximate the calibrated target amount C, so as to achieve the temperature compensation of the concentration C. To meet the above requirements, the neural network should be first trained, and the training samples are provided by the experimental data calibrated by the laboratory. The sensor used in the experiment is an ethanol sensor with tin dioxide as a sensitive material. The schematic diagram of the sensor is shown in Figure 6, the heating voltage is 4 V, and the calibration results are shown in Table 1.
To better converge the neural network, [29] the experimental data were first normalized before feeding the sample data into the network. The formula is as follows: where S i,m and C m are the normalized values of the input and output of neural network; S i,m and C m are the input and output of m-m sample; S i,max and S i,min are the maximum and minimum calibration values of voltage sensitivity measured in group i experiment; and C max and C min are the maxi-mum and minimum calibration values of concentration. After normalizing the data, the data shown in Table 2 are available.

Simulation Studies and
Results. The data were processed for [30] using the BP Neural Net toolbox for Matlab2012. Data processing in the Matlab environment is mainly divided into two parts: constructing the BP neural network and integrating the samples and obtaining the structure coefficient. The detailed process is shown in Figure 7.
The BP algorithm is used to process the samples. One node is selected for the input layer, and six nodes are selected [31] for the hidden layer. The number of hidden layers is not fixed, and the output layer selects one node. The range of the input vector is [0,1], the implicit layer adopts the losig function, the output layer adopts the purelin function, and the network training function is trainlm [32][33][34]. The training error was set to 0.0001, and the    Journal of Sensors training number was set to the maximum 3000. The data in Table 3 can be obtained by processing the trained network data of Table 2. The percent absolute error of the BP neural network prediction is shown in Figure 8.

Analysis of the Algorithm Compensation Effect.
Through the Matlab drawing function, writing the corresponding program to simulate each temperature point before compensation and after compensation, it can be found that Figure 9 (working curve at different temperatures after compensation) is better overlapping than Figure 10 (working curve before compensation), effectively reducing the impact of external temperature on the output.

Conclusions
With the development of automation level, the application of gas sensor is more and more extensive in all kinds of control systems of automation equipment. Among them, the application of infrared gas sensor is particularly prominent, but the infrared gas sensor will be affected by the temperature, resulting in zero-point drift and sensitivity drift. Because temperature is the most important interference amount of the sensor system, it is extremely important to compensate the sensor temperature in practical application.
To improve the measurement accuracy and improve the error output characteristics caused by the temperature change of the sensor, measures must be taken to correct the temperature error. Experts and scholars take temperature compensation as an important way to improve the accuracy of gas sensors, and there are a lot of researches, regarding the maturity and development of computer algorithms. It is a new trend to predict temperature compensation based on mature models. In this paper, an ethanol sensor with tin dioxide as a sensitive material is an example.     Based on the BP neural network method, through the programs provided in the Matlab Neural Network toolbox, various function parameters in the neural network are programmed to realize the compensation function of the gas sensor. By comparing the working curve diagram before and after the compensation, it is found that this method effectively reduces the influence of the external temperature on the gas sensor output at all temperature levels and effectively improves the accuracy and stability of the sensor.

Data Availability
The labeled datasets used to support the findings of this study are available from the corresponding author upon request.

Conflicts of Interest
The authors declare no competing interests.