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

Authors: Kangning Dong; Jinfang Yang
Journal: Journal of Sensors
 (2022)

---

## Abstract

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.


---

## Body

## 1. 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.


## 2. 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 CO2 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 CO2 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 CO2 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/m3 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 conductivity 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. 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.Figure 1
Measurement method in gas sensor with BP neural network.


## 3. Methodologies

### 3.1. BP Neural Network

Multilayer feedforward artificial neural network (or multilayer perceptron, MLP) using the error back propagation algorithm (BP: Error Back-propagation Algorithm) is called BP neural network or BP neural network model. Neural network has obvious characteristics.


#### 3.1.1. Distributed Information Storage Mode

Neural network stores information in the form of the state of the various processors themselves and the connections between them. 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.


#### 3.1.2. 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.


#### 3.1.4. 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–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 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.Figure 2
Basic structure of the BP network.


### 3.3. 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. Figure3 is a flow chart of the BP neural network algorithm.Figure 3
Flow chart of the BP neural network algorithm.There aren input layer nodes, q hidden layer nodes, and m output layer nodes, the weights between input layer and hidden layer are vki, and the transfer function of hidden layer is f1.. The weight between the hidden layer and the output layer is wki, and the transfer function of the output layer is f2. [25]; then, hide the layer node output wkif2.
(1)zk=f1∑i=0nvkixi,k=1,2,⋯,q.Output layer node output:(2)yj=f2∑k=0qwjkzk,j=1,2,⋯,m.In this way, the BP network completes the approximate mapping of then-dimensional space vectors to the m-dimensional space.


#### 3.3.2. Back Propagation

First, the error function is defined withp learning samples, with x1, x2,... For the xp representation, the pth sample that enters the network gets the output yjp, j=1,2,⋯,m, using the squared error function:
(3)Ep=12∑j=1mtjp−yjp2.The expected output is given in the formula fortjp..For thep samples, the global error is
(4)E=12∑p=1P∑j=1Mtjp−yjp2=∑p=1pEp.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 signalE 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
(5)Wjkn=−η∂E/∂Wjk.In the formula,Wjk is the step length parameter (learning rate); ∂E is the nth weight correction; and ∂Wjk 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:(6)Wjkn=−∂E∂Wjkn+μWjkn−1.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 functionE, to improve the generalization ability of the network and improve the network convergence performance [27](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 probabilityP 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


### 3.4. 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(7)fitness=1n∑t=1n∑p=1qYpi−YΛpi2,where n is the number of network learning samples and Ypi 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.Figure 4
Optimizing the BP neural network flow.


## 3.1. BP Neural Network

Multilayer feedforward artificial neural network (or multilayer perceptron, MLP) using the error back propagation algorithm (BP: Error Back-propagation Algorithm) is called BP neural network or BP neural network model. Neural network has obvious characteristics.


### 3.1.1. Distributed Information Storage Mode

Neural network stores information in the form of the state of the various processors themselves and the connections between them. 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.


### 3.1.2. 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.


### 3.1.4. 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.1.1. Distributed Information Storage Mode

Neural network stores information in the form of the state of the various processors themselves and the connections between them. 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.


## 3.1.2. 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.


## 3.1.4. 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–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 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.Figure 2
Basic structure of the BP network.


## 3.3. 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. Figure3 is a flow chart of the BP neural network algorithm.Figure 3
Flow chart of the BP neural network algorithm.There aren input layer nodes, q hidden layer nodes, and m output layer nodes, the weights between input layer and hidden layer are vki, and the transfer function of hidden layer is f1.. The weight between the hidden layer and the output layer is wki, and the transfer function of the output layer is f2. [25]; then, hide the layer node output wkif2.
(1)zk=f1∑i=0nvkixi,k=1,2,⋯,q.Output layer node output:(2)yj=f2∑k=0qwjkzk,j=1,2,⋯,m.In this way, the BP network completes the approximate mapping of then-dimensional space vectors to the m-dimensional space.


### 3.3.2. Back Propagation

First, the error function is defined withp learning samples, with x1, x2,... For the xp representation, the pth sample that enters the network gets the output yjp, j=1,2,⋯,m, using the squared error function:
(3)Ep=12∑j=1mtjp−yjp2.The expected output is given in the formula fortjp..For thep samples, the global error is
(4)E=12∑p=1P∑j=1Mtjp−yjp2=∑p=1pEp.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 signalE 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
(5)Wjkn=−η∂E/∂Wjk.In the formula,Wjk is the step length parameter (learning rate); ∂E is the nth weight correction; and ∂Wjk 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:(6)Wjkn=−∂E∂Wjkn+μWjkn−1.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 functionE, to improve the generalization ability of the network and improve the network convergence performance [27](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 probabilityP 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


## 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. Figure3 is a flow chart of the BP neural network algorithm.Figure 3
Flow chart of the BP neural network algorithm.There aren input layer nodes, q hidden layer nodes, and m output layer nodes, the weights between input layer and hidden layer are vki, and the transfer function of hidden layer is f1.. The weight between the hidden layer and the output layer is wki, and the transfer function of the output layer is f2. [25]; then, hide the layer node output wkif2.
(1)zk=f1∑i=0nvkixi,k=1,2,⋯,q.Output layer node output:(2)yj=f2∑k=0qwjkzk,j=1,2,⋯,m.In this way, the BP network completes the approximate mapping of then-dimensional space vectors to the m-dimensional space.


## 3.3.2. Back Propagation

First, the error function is defined withp learning samples, with x1, x2,... For the xp representation, the pth sample that enters the network gets the output yjp, j=1,2,⋯,m, using the squared error function:
(3)Ep=12∑j=1mtjp−yjp2.The expected output is given in the formula fortjp..For thep samples, the global error is
(4)E=12∑p=1P∑j=1Mtjp−yjp2=∑p=1pEp.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 signalE 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
(5)Wjkn=−η∂E/∂Wjk.In the formula,Wjk is the step length parameter (learning rate); ∂E is the nth weight correction; and ∂Wjk 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:(6)Wjkn=−∂E∂Wjkn+μWjkn−1.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 functionE, to improve the generalization ability of the network and improve the network convergence performance [27](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 probabilityP 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


## 3.4. 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(7)fitness=1n∑t=1n∑p=1qYpi−YΛpi2,where n is the number of network learning samples and Ypi 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.Figure 4
Optimizing the BP neural network flow.


## 4. Result Analysis and Discussion

### 4.1. Basic Test Circuit

The basic test circuit is shown in Figure5. In the figure, Vc is the working voltage, Vh is the heating voltage, the output voltage V is the amount to be measured, and the sensitivity S is V0/Vg, where V0 and Vg are the output voltage of the sensor in the air and the measured gas, respectively.Figure 5
Basic test circuit.


### 4.2. 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, self-learning, 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.Figure 6
Schematic diagram of the gas sensor.Table 1
Sensor input and output calibration values at different ambient temperatures.
C on centrationC/(g•m-3)SensitivityS18°C20°C22°C24°C0.5003.4653.7763.9874.1821.0004.1074.3164.4324.6921.5004.5074.6645.4045.4862.0005.6015.7046.0086.1372.5006.3286.5286.5547.2813.0007.2087.6937.8038.161To 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:
(8)S¯i,m=Si,m−Si,minSi,max−Si,min,(9)C¯m=Cm−CminCmax−Cmin,whereSi,m and Cm are the normalized values of the input and output of neural network; Si,m and Cm are the input and output of m-m sample; Si,max and Si,min are the maximum and minimum calibration values of voltage sensitivity measured in group i experiment; and Cmax and Cmin are the maximum and minimum calibration values of concentration. After normalizing the data, the data shown in Table 2 are available.Table 2
The normalized NN input-output samples
(a)mC¯mS¯i,mmC¯mS¯i,m18°C20°C10010020.20.17220.20.13830.40.27830.40.22740.60.57140.60.49250.80.76550.80.703611611(b)mC¯mS¯i,mmC¯mS¯i,m22°C24°C10010020.20.11720.20.05330.40.37130.40.32840.60.5340.60.4950.80.67250.80.779611611


### 4.3. 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.Figure 7
Matlab environment data processing process.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–34]. The training error was set to 0.0001, and the 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.Table 3
Output results after the training period.
C on centrationC/(g•m-3)SensitivityS18°C20°C22°C24°C1.0000.204 70.199 60.199 60.196 31.5000.4030.396 70.399 50.400 62.0000.600 10.601 70.599 80.598 52.5000.799 70.801 80.7990.799 43.0001111Figure 8
Percent absolute error of BP neural networks


### 4.4. 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 Figure9 (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.Figure 9
Working curve after compensation.Figure 10
Working curve before compensation.


## 4.1. Basic Test Circuit

The basic test circuit is shown in Figure5. In the figure, Vc is the working voltage, Vh is the heating voltage, the output voltage V is the amount to be measured, and the sensitivity S is V0/Vg, where V0 and Vg are the output voltage of the sensor in the air and the measured gas, respectively.Figure 5
Basic test circuit.


## 4.2. 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, self-learning, 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.Figure 6
Schematic diagram of the gas sensor.Table 1
Sensor input and output calibration values at different ambient temperatures.
C on centrationC/(g•m-3)SensitivityS18°C20°C22°C24°C0.5003.4653.7763.9874.1821.0004.1074.3164.4324.6921.5004.5074.6645.4045.4862.0005.6015.7046.0086.1372.5006.3286.5286.5547.2813.0007.2087.6937.8038.161To 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:
(8)S¯i,m=Si,m−Si,minSi,max−Si,min,(9)C¯m=Cm−CminCmax−Cmin,whereSi,m and Cm are the normalized values of the input and output of neural network; Si,m and Cm are the input and output of m-m sample; Si,max and Si,min are the maximum and minimum calibration values of voltage sensitivity measured in group i experiment; and Cmax and Cmin are the maximum and minimum calibration values of concentration. After normalizing the data, the data shown in Table 2 are available.Table 2
The normalized NN input-output samples
(a)mC¯mS¯i,mmC¯mS¯i,m18°C20°C10010020.20.17220.20.13830.40.27830.40.22740.60.57140.60.49250.80.76550.80.703611611(b)mC¯mS¯i,mmC¯mS¯i,m22°C24°C10010020.20.11720.20.05330.40.37130.40.32840.60.5340.60.4950.80.67250.80.779611611


## 4.3. 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.Figure 7
Matlab environment data processing process.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–34]. The training error was set to 0.0001, and the 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.Table 3
Output results after the training period.
C on centrationC/(g•m-3)SensitivityS18°C20°C22°C24°C1.0000.204 70.199 60.199 60.196 31.5000.4030.396 70.399 50.400 62.0000.600 10.601 70.599 80.598 52.5000.799 70.801 80.7990.799 43.0001111Figure 8
Percent absolute error of BP neural networks


## 4.4. 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 Figure9 (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.Figure 9
Working curve after compensation.Figure 10
Working curve before compensation.


## 5. 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.



---

*Source: 5063472-2022-06-07.xml*