# A Research of Neural Network Optimization Technology for Apple Freshness Recognition Based on Gas Sensor Array

Authors: Wei Wang; Weizhen Yang; Yungang Liu; Zhaoba Wang; Zhuanhong Yan
Journal: Scientific Programming
 (2022)

---

## Abstract

In the process of growth, apples’ ripening, storage, transportation, and processing, the appearance and internal physiological characteristics will have some changes because of the effect of time and physical attributes. A series of problems, such as the false ripeness and putrefaction of fruit, will bring huge economic losses to fruit vendors and harm to consumers. In this paper, an odor recognition system has been designed for the fast evaluation of the freshness characteristics of apples, which is based on the freshness characteristics of Fuji apple. A series of apple-air mixture with equivalent model was established by studying the change of gas concentration during the growth and storage of apples. The continuous projection algorithm (Successive Projections Algorithm, SPA) is used to optimize the sensor array to solve the problems of collinearity and overlap and also to eliminate the abnormal and redundant sensors. ZigBee wireless sensor network is adopted to send data to host computer, and BP (Error Backpropagation) neural network algorithm optimized by SFLA (shuffled complex evolution, SCE + Particle Swarm Optimization, PSO) algorithm is used to recognize gas data, which greatly improves the training speed and precision of neural network. The experimental results show that the detection accuracy of the Fuji apples freshness is 98.67% and can quickly and comprehensively identify the freshness of apples.


---

## Body

## 1. Introduction

In 1961 Moncrieff, the first to complete the study of odor recognition technology, developed a mechanical odor detection device. In 1982, Persaud and Dodd proposed the concept of an electronic nose, which consisted of two main components: an odor sensor array and a pattern recognition system. The odor sensor is the core component of the electronic nose system. Because single odor sensor cannot evaluate the complex odor components of objects, the selective chemical sensor array is adopted. At present, the most commonly used sensors are metal oxide semiconductor sensors, metal semiconductor field effect transistor sensors, fast ion conductor sensors, optical odor sensors, and mass sensors. Among these sensors, the MOS (metal oxide semiconductor) sensor based on changes operates in its conductivity and resistance, which are caused by the measured redox between the odor and the odor sensing component. This is the most widely used sensor. Based on the data collected by the sensor array, simple and complex odors can be identified by an appropriate pattern recognition system.Apple not only has sweet flavor, but also is rich in nutrition, which is a kind of high value fruit. According to the Food and Agriculture Organization of the United Nations, apple production worldwide exceeded 70 million tons in 2019. However, in the process of picking, processing, transportation, and storage, its appearance and internal physiological characteristics will be changed due to the problems of false maturation, mechanical damage, and fungal infection, which will bring huge economic losses. It is an important problem to detect the freshness of apple.Italy’s Natale et al. [1] examined the quality of harvested oranges and apples using odor recognition and found that the method could predict apples’ defects. Brezmes et al. [2] used smell recognition to detect the ripeness of pear, apple, and peach, adopted neural network analysis to identify fruit samples, and also found that there is a close relationship between smell signal and fruit; the success rate is up to 92%. Although China starts late in the research of odor recognition technology, it has made great progress. In 1995, Pan and others first developed a system to detect smell of apples. The sensor array is used to collect the gas signal, then extracts the characteristic value from the signal curve, and uses the characteristic value as the input vector of pattern recognition. According to the results of signal processing by PCA (Principal Component Analysis), the good and bad apples can be identified, but there are overlapping parts. The research is mainly carried out under the condition of laboratory, and the classification level and the recognition efficiency need to be further improved. Hu et al. [3] used PEN2 electronic nose system to detect citrus fruits stored in different ways and time. The results showed that linear discriminant method was better than principal component analysis method in identifying citrus fruits stored in different time. The load analysis shows that 2, 7, and 9 sensors have great effect on citrus aroma. Electronic nose is expensive and cannot meet the requirements of large-scale applications. A 2017 study by Guo and Sun [4] found that ethylene release from apples is closely related to their ripeness. When ethylene release is less than 1mg·L−1, the apples do not ripen; when ethylene release is greater than 1mg·L−1, or less than 6mg·L−1, the apples do ripen; when ethylene release is greater than 6mg·L−1, the apples overripe. Because of the complex changes of the external environment, the concentration of single gas is not enough to judge the freshness characteristics accurately, but the research results of the concentration characteristics of ethylene gas are of great significance to freshness identification technology.At present, the study of odor recognition technology in scientific research institutions is still in the laboratory stage, which is suitable for on-the-spot real-time detection and network remote monitoring. The key technologies such as gas sensing mechanism and pattern recognition algorithm still need to be further improved and modified. In this paper, a high-precision identification and matching algorithm is proposed to transmit detection data by wireless communication in the open environment, in which the self-made gas sensor array has a great price advantage over the finished electronic nose.


## 2. Related Work

### 2.1. Technical Principle

The odor recognition system consists of two parts: hardware system and software system. The software system is the host computer, mainly the pattern recognition module as well as the signal reprocessing unit. As a key part of converting gas signals into electrical signals, the gas detector has to be sensitive enough to identify and collect the mixture of gases produced by apples. The signal processing circuit preprocesses the signals collected by the sensors, such as filtering, amplifying, A/D conversion, etc. to reduce noise and signal errors. The obtained analog voltage signal is changed into a binary number that can be processed by a computer. The function of the signal reprocessing unit of the upper computer is to convert the binary signals collected by the computer into digital/analog signals and smoothen the signals. Finally, the signal recognition process is performed by the pattern recognition module to realize the quantitative and qualitative analysis of the measured gas. The basic workflow is shown in Figure1.Figure 1
Odor recognition system flow.As a core component of the odor recognition system, the performance of the gas detector directly determines the function of the odor recognition system. The gas detector is a key bridge for shifting gas signals into electrical signals, and when measuring the gas produced by the apples, the sensor adjusts the gas sample to filter out extraneous interference. The gas detector with good performance indicators can greatly improve the detection sensitivity of odor recognition systems. In an odor recognition system, the gas detector and its arrays must satisfy the following conditions:(1)
Gas detectors are able to identify different odors among the gas mixture, with strong gas detection generality, and also able to identify various odors at the molecular level(2)
When a gas sensor detects a kind of gas, the reaction to the gas odor molecule must be rapid and repeatable, without any “memory effect”The smell of apples is another important indicator of their freshness. So far, more than 300 volatile compounds have been identified in apples, but only a small number of compounds can characterize the freshness of apples. In order to more accurately identify the changes of mixed gases during the process of apple deterioration, it is necessary for apple odor recognition system to be sensitive to distinguish the changes of different gases. The odor recognition system identifies the apple gas by the chemical reaction between the volatile gas mixture of apples to be measured and the sensitive material of gas sensor. So that the gas sensor generates resistance value, current, and other electrical signal changes to realize the acquisition from nonelectrical gas signal to the electrical signal. The collected electrical signals are transmitted to the host computer system, and after processing the signals, the characteristics of the apple odor signals are extracted. The changes of gas were identified by the system pattern recognition unit, and the results of freshness of apples were compared by the analysis system.


### 2.2. Technical Methods

Our research team has done a lot of relevant research work on odor recognition technology and completed the related system design, algorithm research, experimental data analysis, and so on. The system consists of host, ZigBee transmitter, ZigBee receiver, airtight box, and sensor array, as shown in Figure2.Figure 2
Composition of odor recognition system.PC computer as the host is used as the controller of the experiment system and the memory of the experiment data, and the display can show the change of the gas concentration during the experiment. The ZigBee sensor array is used to collect gas concentration in the sealed box. The ZigBee transmitter sends gas concentration collected by sensor array to the ZigBee receiver; the computer processes the data and identifies the freshness. The system uses wireless sensor network nodes to realize data transmission. The use of wireless transmission technology increases the universality and convenience of the system. The airtight box has conductor grounding, used for shielding outside electromagnetic wave.The types of sensors and performance indicators are shown in Table1.Table 1
Gas sensor array.
No.Sensor modelMeasured gasMeasuring rangeWorking voltage (V)S1MQ3Ethanol25–500 ppm5.0S2MG811Carbon dioxide0–10000 ppm6S3ME2-O2Oxygen0–25% vol3.3S4ME3-C2H4Ethylene0–100 ppm5.0Because performance of gas sensor is affected by temperature and humidity, the experiment is carried out under the condition that the temperature and humidity are relatively stable. The gas collection steps are as follows:(1)
Put the gas sensor collection array into the sealed box, power up, and preheat(2)
The apple sample is placed in an airtight box, the gas is evenly diffused, and the smell emitted by apple to be measured reacts with the sensor array in the airtight box to produce an electric signal, and the data is collected and stored in the PC by ZigBee transmitter and receiver(3)
Preprocess the collected data and repeat the steps above by introducing clean air to restore the sensor to its original state after each measurementFor apples of different freshness, final response signal size is different. The CO2 concentration is measured among fresh, not-fresh, rotten, and severely rotten apples as shown in Figure3.Figure 3
Curve of carbon dioxide concentration with different freshness on fruit surface.From the graph, the concentration of carbon dioxide in apples increases with time, reaching a certain value, and freshness of apples is directly related to the concentration of carbon dioxide. Ranging from fresh, not stale, rotten to severely decayed, CO2 concentration is getting higher and higher. Other gases are collected and treated in a manner similar to carbon dioxide. In different test environments, the single gas concentration does not have unique identification characteristics, so it is necessary to collect data from other gas sensors and fuse the data to judge the freshness of apple.


### 2.3. Experimental and Data Processing Techniques

Sixteen apples were measured and the training data were normalized. According to the fresh characteristics of apples, the expected output vector of fresh apples is set as [1, 0, 0, 0]; the expected output vector of not-fresh apples is set as [0, 1, 0, 0]; and the expected output vector of rotten apples is set as [0,0,1,0]. The 16 apple charts are shown in Figure4.Figure 4
Sixteen Fuji apples.The original data collected by the sensor cannot be used directly for training and recognition because of great noise caused by the interference of the system itself and the external electromagnetic wave. Data preprocessing noise is used to extract the eigenvalue of the signals collected by the sensor array.Firstly, the data collected by the sensor array are preprocessed, secondly, the eigenvalues are selected, and finally, BP neural network is used to identify the data. The construction of BP neural network determines the structure of BP neural network based on the characteristics of input and output data of the system. Because the input signal of gas eigenvalues has 15 dimensions and 3 types of apple fruit surface features are classified, the structure of BP neural network is 15-9-3. The training process of BP neural network includes the following steps:(1)
Network initialization(2)
Hidden layer output calculation(3)
Output computing in the output layer(4)
Error calculation(5)
Weight update(6)
Threshold update(7)
Determine whether the algorithm iteration is over, and if not, return to the hidden layer to output the calculation stepsIn the process of identifying 16 groups of apples, recognition rate of apples can reach 93.75%, which shows that it is more accurate to identify degree of freshness of apples by using odor recognition combined with the ordinary matrix multiplication method in fuzzy comprehensive evaluation and can effectively identify degree of freshness of apples and categories. The identification result of number 11 in the experimental results is inconsistent with the actual freshness of apples. Due to data error caused by influence of external noise in the course of data collecting, the freshness of some apples cannot be correctly identified.


## 2.1. Technical Principle

The odor recognition system consists of two parts: hardware system and software system. The software system is the host computer, mainly the pattern recognition module as well as the signal reprocessing unit. As a key part of converting gas signals into electrical signals, the gas detector has to be sensitive enough to identify and collect the mixture of gases produced by apples. The signal processing circuit preprocesses the signals collected by the sensors, such as filtering, amplifying, A/D conversion, etc. to reduce noise and signal errors. The obtained analog voltage signal is changed into a binary number that can be processed by a computer. The function of the signal reprocessing unit of the upper computer is to convert the binary signals collected by the computer into digital/analog signals and smoothen the signals. Finally, the signal recognition process is performed by the pattern recognition module to realize the quantitative and qualitative analysis of the measured gas. The basic workflow is shown in Figure1.Figure 1
Odor recognition system flow.As a core component of the odor recognition system, the performance of the gas detector directly determines the function of the odor recognition system. The gas detector is a key bridge for shifting gas signals into electrical signals, and when measuring the gas produced by the apples, the sensor adjusts the gas sample to filter out extraneous interference. The gas detector with good performance indicators can greatly improve the detection sensitivity of odor recognition systems. In an odor recognition system, the gas detector and its arrays must satisfy the following conditions:(1)
Gas detectors are able to identify different odors among the gas mixture, with strong gas detection generality, and also able to identify various odors at the molecular level(2)
When a gas sensor detects a kind of gas, the reaction to the gas odor molecule must be rapid and repeatable, without any “memory effect”The smell of apples is another important indicator of their freshness. So far, more than 300 volatile compounds have been identified in apples, but only a small number of compounds can characterize the freshness of apples. In order to more accurately identify the changes of mixed gases during the process of apple deterioration, it is necessary for apple odor recognition system to be sensitive to distinguish the changes of different gases. The odor recognition system identifies the apple gas by the chemical reaction between the volatile gas mixture of apples to be measured and the sensitive material of gas sensor. So that the gas sensor generates resistance value, current, and other electrical signal changes to realize the acquisition from nonelectrical gas signal to the electrical signal. The collected electrical signals are transmitted to the host computer system, and after processing the signals, the characteristics of the apple odor signals are extracted. The changes of gas were identified by the system pattern recognition unit, and the results of freshness of apples were compared by the analysis system.


## 2.2. Technical Methods

Our research team has done a lot of relevant research work on odor recognition technology and completed the related system design, algorithm research, experimental data analysis, and so on. The system consists of host, ZigBee transmitter, ZigBee receiver, airtight box, and sensor array, as shown in Figure2.Figure 2
Composition of odor recognition system.PC computer as the host is used as the controller of the experiment system and the memory of the experiment data, and the display can show the change of the gas concentration during the experiment. The ZigBee sensor array is used to collect gas concentration in the sealed box. The ZigBee transmitter sends gas concentration collected by sensor array to the ZigBee receiver; the computer processes the data and identifies the freshness. The system uses wireless sensor network nodes to realize data transmission. The use of wireless transmission technology increases the universality and convenience of the system. The airtight box has conductor grounding, used for shielding outside electromagnetic wave.The types of sensors and performance indicators are shown in Table1.Table 1
Gas sensor array.
No.Sensor modelMeasured gasMeasuring rangeWorking voltage (V)S1MQ3Ethanol25–500 ppm5.0S2MG811Carbon dioxide0–10000 ppm6S3ME2-O2Oxygen0–25% vol3.3S4ME3-C2H4Ethylene0–100 ppm5.0Because performance of gas sensor is affected by temperature and humidity, the experiment is carried out under the condition that the temperature and humidity are relatively stable. The gas collection steps are as follows:(1)
Put the gas sensor collection array into the sealed box, power up, and preheat(2)
The apple sample is placed in an airtight box, the gas is evenly diffused, and the smell emitted by apple to be measured reacts with the sensor array in the airtight box to produce an electric signal, and the data is collected and stored in the PC by ZigBee transmitter and receiver(3)
Preprocess the collected data and repeat the steps above by introducing clean air to restore the sensor to its original state after each measurementFor apples of different freshness, final response signal size is different. The CO2 concentration is measured among fresh, not-fresh, rotten, and severely rotten apples as shown in Figure3.Figure 3
Curve of carbon dioxide concentration with different freshness on fruit surface.From the graph, the concentration of carbon dioxide in apples increases with time, reaching a certain value, and freshness of apples is directly related to the concentration of carbon dioxide. Ranging from fresh, not stale, rotten to severely decayed, CO2 concentration is getting higher and higher. Other gases are collected and treated in a manner similar to carbon dioxide. In different test environments, the single gas concentration does not have unique identification characteristics, so it is necessary to collect data from other gas sensors and fuse the data to judge the freshness of apple.


## 2.3. Experimental and Data Processing Techniques

Sixteen apples were measured and the training data were normalized. According to the fresh characteristics of apples, the expected output vector of fresh apples is set as [1, 0, 0, 0]; the expected output vector of not-fresh apples is set as [0, 1, 0, 0]; and the expected output vector of rotten apples is set as [0,0,1,0]. The 16 apple charts are shown in Figure4.Figure 4
Sixteen Fuji apples.The original data collected by the sensor cannot be used directly for training and recognition because of great noise caused by the interference of the system itself and the external electromagnetic wave. Data preprocessing noise is used to extract the eigenvalue of the signals collected by the sensor array.Firstly, the data collected by the sensor array are preprocessed, secondly, the eigenvalues are selected, and finally, BP neural network is used to identify the data. The construction of BP neural network determines the structure of BP neural network based on the characteristics of input and output data of the system. Because the input signal of gas eigenvalues has 15 dimensions and 3 types of apple fruit surface features are classified, the structure of BP neural network is 15-9-3. The training process of BP neural network includes the following steps:(1)
Network initialization(2)
Hidden layer output calculation(3)
Output computing in the output layer(4)
Error calculation(5)
Weight update(6)
Threshold update(7)
Determine whether the algorithm iteration is over, and if not, return to the hidden layer to output the calculation stepsIn the process of identifying 16 groups of apples, recognition rate of apples can reach 93.75%, which shows that it is more accurate to identify degree of freshness of apples by using odor recognition combined with the ordinary matrix multiplication method in fuzzy comprehensive evaluation and can effectively identify degree of freshness of apples and categories. The identification result of number 11 in the experimental results is inconsistent with the actual freshness of apples. Due to data error caused by influence of external noise in the course of data collecting, the freshness of some apples cannot be correctly identified.


## 3. Fast Freshness Identification Technology

At present, the experimental method and algorithm research are mainly carried out in the laboratory condition, and gas concentration collection method in the closed environment, using the traditional BP neural network recognition technology, has the good effect. Therefore, feasibility of the odor recognition technology in the identification of apple freshness is verified. However, in the current information acquisition process, with the process of exhaust, sensor preheating, and acquisition information stability, the more complicated the procedure is, the longer the detection time is. The technology is still lacking field practicality. It is hoped that apple freshness can be identified quickly and related work such as experiment method, sensor array optimization, and algorithm optimization can be carried out on the basis of the research.


### 3.1. Experimental Apparatus

A gas sensor array is placed in a test vessel in a small container, put one apple at each time, and the gas emitted from the apple is detected at room temperature of 20°C and humidity of 50% Rh. The experimental equipment is shown in Figures5 and 6. The odor recognition system is used to detect and analyze apples with different freshness.Figure 5
Physical diagram of data acquisition.Figure 6
PC wireless transmission and reception node.A preheated sensor array is used to detect change of gas concentration in the process of apple aroma emission. In Figure5, a battery powered wireless transmission module and a gas sensor array integrated circuit board are attached to the top of the glass bottle to capture apple smell. A wireless sending node is integrated into the circuit board of the sensor array, the apple test sample is placed on the test-bed, and the test bottle clasp after the sensor prediction is placed over the sample to collect all kinds of gases emitted by the sample. Figure 6 is another ZigBee wireless transmission node connected to the host computer, which receives the gas concentration data collected by the gas sensor array and saves it to the PC.The steps are as follows:(1)
Establish a data acquisition platform and wireless transmission ZigBee network(2)
Preheat sensor array for 5 min according to the requirements of the sensor, and observe the data of the sensor collected by PC through serial port until it becomes stable, and then start the sample detection(3)
300 groups of fresh, moderately rotten, and severely rotten apples are placed in the test box for 5 minutes in sequence, and the residual gases in the test box are removed by headspace method or drainage method between samples to ensure the consistency of the test environment and the accuracy of the sample data(4)
The collected 900 sets of data are classified and saved according to different freshness characteristics


### 3.2. Data Acquisition and Preprocessing

Among the odor recognition sensor arrays, the ethylene gas sensor is a ME3-C2H4 galvanic cell type sensor with an output current proportional to concentration, but a maximum output current is only 140 UA and a load voltage is 100 ohms, so it is necessary to enlarge original signal and control its output voltage in 0–3.3 V for follow-up processing. The ethylene concentration calculation formula is shown in the following formula in PPM.(1)P=832.207−0.608∗Vout−0.608.In the open environment, the concentration of carbon dioxide, ethylene, ethanol, and oxygen in three kinds of apples is measured by gas identification system. Figure7 shows the experimental results.Figure 7
60S apple gas concentration contrast. (a) Carbon dioxide concentration. (b) Ethylene concentration. (c) Ethanol concentration. (d) Oxygen concentration.
(a)(b)(c)(d)The original data collected by the sensor cannot be directly used for training and recognition because of interference of system itself, temperature sensitivity of sensor, and even interference of external electromagnetic wave. The data preprocessing process is to preprocess sensor array signal to extract eigenvalues. The process is as follows.


#### 3.2.1. Data for Removing Singularities

The data of carbon dioxide, ethylene, ethanol, and oxygen concentration are obtained by eliminating singularity of original data of apples with different freshness.


#### 3.2.2. Least Square Filtering

Because of interference of the system and temperature sensitivity of the sensor, the data are filtered by linear least square filter to remove noise and get a relatively smooth image.


#### 3.2.3. Extraction of Eigenvalues

Take the first 60 seconds and every 5 seconds to take a data eigenvalue, multipoint eigenvalue extraction to do data training, then take the data filter processing. The results are shown in Figure8.Figure 8
60s filter apple gas concentration contrast. (a) Carbon dioxide concentration. (b) Ethylene concentration contrast. (c) Ethanol concentration. (d) Oxygen concentration.
(a)(b)(c)(d)As can be seen from the diagram, after preprocessing, concentration information of carbon dioxide, ethanol, and ethylene after 30 seconds is used as determining factor to determine freshness of apple based on stability of the sensor. The extracted data are trained and tested by extracting the eigenvalues.The original data volume of gas sensor array is very large, dimension is correspondingly large, so complexity of classifier is also increasing; and it is easy to produce explosion. The performance of classifier can be improved by reducing dimension and improving extraction of eigenvalues. The extraction of sensor data eigenvalues is to transform the samples from high-dimensional space to low-dimensional space by mapping or transformation and extract main information which reflects essential attributes of target signal. The optimal value of BP neural network optimized by hybrid frog-leaping algorithm is used to train the network, which can accurately distinguish apples with different freshness.


### 3.3. Optimization of Sensor Array

In the process of odor recognition, sensor array is the key of information collection. Using reasonable gas sensor can not only improve recognition accuracy, but also improve collection efficiency. Continuous projection algorithm (SPA) is a forward variable selection method, which is used to solve classification problem. The purpose of SPA is to select a small set of variables with less redundancy and minimum collinearity, with elimination of redundant information in original matrix. The correlation contribution of each sensor to different freshness of apple is studied by PCA analysis. Figure9 is a bar chart of the contribution rates. Figure 10 is a histogram comparison of RMSEP (Root-Mean-Square Error of Prediction).Figure 9
Sensor contribution load diagram in first two principal component analyses.Figure 10
RMSEP values for different variables.As can be seen from the diagram, values of all sensors on PC1 are greater than 0.8, and the load coefficients of S2, S3, and S4 are very close, which means that these sensors have similar recognition functions and some overlapping information. Therefore, redundant sensors can be removed from the array. By retaining useful sensors and eliminating redundant ones, the sensor array platform of the system is reconfigured by using sensor array optimization SPA algorithm. Figure10 shows RMSEP with different number of variables (number of sensors), in which three sensors (S1, S2, and S4) in the array are selected according to the relatively low RMSEP.


### 3.4. Hybrid Leapfrog Algorithm

Leapfrog algorithm (SFLA) is a heuristic group evolutionary algorithm with high computational performance and excellent global search ability. The flow of hybrid leapfrog algorithm is shown in Figure11.Figure 11
Flowchart of mixed leapfrog algorithm.The algorithm works like this:(1)
Initialize the population information to determine the population sizeF, as shown in the following formula:(2)F=m∗n.Among them,m is for the number of subgroups, and n is for the number of frogs in each group.(2)
Compute fitness, the objective function value for each solution.(3)
According to descending order of fitness, write down location of the first best frog as the first global optimal solution.F frogs are assigned to m groups and each group has n frogs. Then start population optimization (local optimization). The positions of the best and worst frogs in the subpopulations are recorded as Pb and PW, respectively. Trigonometric probability distribution is used to assign more weights to frogs with better fitness values and lower weights to frogs with worse fitness values. So the highest probability of a frog being selected as a subgroup is P1=2/n+1 , and the lowest probability is P1=2/nn+1. Update position of the frog by optimizing the position of the worst frog in the subgroup in formulas (3) and (4).(3)DS=rand∗Pb−PW,rand is a random number of [0, 1].(4)DS=minintrand∗Pb−PW,Smax=maxintrand∗Pb−PW,−Smax,−Dmax≤¯DS≤¯DmaxSmax represents the maximum step allowed by an individual frog.Replace the bad frog with the better frog, and if you do not get a better frog after the update, randomly generate a frog to replacePW and return to the loop. The algorithm outputs the optimal solution and ends until the number of cycles or the stop condition is met.


### 3.5. Optimizing BP Neural Network

The structure of BP neural network is determined according to characteristics of input and output data of the system. Because the input signals of odor characteristics have 9 dimensions, there are 3 kinds of freshness characteristics to be classified. According to Kolmogorov’s theorem, the range of hidden layer nodes is [4, 13], and the optimum number of hidden layers n is 10. So the structure of BP neural network is 9-10-3; that is, there are 9 nodes in input layer and 10 nodes in hidden layer; the output layer has three nodes.After pretreatment, 900 groups of fresh degree characteristic signals are selected, from which 750 groups of data are randomly selected to train the network, and 150 groups of data are used to test the network classification ability. The expected output vector of fresh apple is set to [1, 0, 0]; the expected output vector of moderately rotten apple is set to [0, 1, 0]; the expected output vector of severely rotten apple is set to [0, 0, 1]. The training data are normalized according to the following formula:(5)Xn=xn−xminxmax−xmin.The training error of BP neural network is shown in Figure12, and the training error of optimized network is shown in Figure 13.Figure 12
BP training error.Figure 13
Optimizing BP training error.The unoptimized network reaches the minimum system error4.21e−12 after 15 iterations, and the optimized network reaches the minimum system error 3.49e−10 after 12 iterations. The optimized network has fewer iterations than the unoptimized network, and the optimized algorithm is better than the original algorithm in training times and error.Through 750 sets of data trained network, 150 sets of data are classified and 150 sets of sample data are randomly mixed to test accuracy and stability of the network. The results show that freshness of apples is divided into three grades; 148 out of 150 groups of test data could correctly identify the freshness of apple, and the classification accuracy is as high as 98.67%.


## 3.1. Experimental Apparatus

A gas sensor array is placed in a test vessel in a small container, put one apple at each time, and the gas emitted from the apple is detected at room temperature of 20°C and humidity of 50% Rh. The experimental equipment is shown in Figures5 and 6. The odor recognition system is used to detect and analyze apples with different freshness.Figure 5
Physical diagram of data acquisition.Figure 6
PC wireless transmission and reception node.A preheated sensor array is used to detect change of gas concentration in the process of apple aroma emission. In Figure5, a battery powered wireless transmission module and a gas sensor array integrated circuit board are attached to the top of the glass bottle to capture apple smell. A wireless sending node is integrated into the circuit board of the sensor array, the apple test sample is placed on the test-bed, and the test bottle clasp after the sensor prediction is placed over the sample to collect all kinds of gases emitted by the sample. Figure 6 is another ZigBee wireless transmission node connected to the host computer, which receives the gas concentration data collected by the gas sensor array and saves it to the PC.The steps are as follows:(1)
Establish a data acquisition platform and wireless transmission ZigBee network(2)
Preheat sensor array for 5 min according to the requirements of the sensor, and observe the data of the sensor collected by PC through serial port until it becomes stable, and then start the sample detection(3)
300 groups of fresh, moderately rotten, and severely rotten apples are placed in the test box for 5 minutes in sequence, and the residual gases in the test box are removed by headspace method or drainage method between samples to ensure the consistency of the test environment and the accuracy of the sample data(4)
The collected 900 sets of data are classified and saved according to different freshness characteristics


## 3.2. Data Acquisition and Preprocessing

Among the odor recognition sensor arrays, the ethylene gas sensor is a ME3-C2H4 galvanic cell type sensor with an output current proportional to concentration, but a maximum output current is only 140 UA and a load voltage is 100 ohms, so it is necessary to enlarge original signal and control its output voltage in 0–3.3 V for follow-up processing. The ethylene concentration calculation formula is shown in the following formula in PPM.(1)P=832.207−0.608∗Vout−0.608.In the open environment, the concentration of carbon dioxide, ethylene, ethanol, and oxygen in three kinds of apples is measured by gas identification system. Figure7 shows the experimental results.Figure 7
60S apple gas concentration contrast. (a) Carbon dioxide concentration. (b) Ethylene concentration. (c) Ethanol concentration. (d) Oxygen concentration.
(a)(b)(c)(d)The original data collected by the sensor cannot be directly used for training and recognition because of interference of system itself, temperature sensitivity of sensor, and even interference of external electromagnetic wave. The data preprocessing process is to preprocess sensor array signal to extract eigenvalues. The process is as follows.


### 3.2.1. Data for Removing Singularities

The data of carbon dioxide, ethylene, ethanol, and oxygen concentration are obtained by eliminating singularity of original data of apples with different freshness.


### 3.2.2. Least Square Filtering

Because of interference of the system and temperature sensitivity of the sensor, the data are filtered by linear least square filter to remove noise and get a relatively smooth image.


### 3.2.3. Extraction of Eigenvalues

Take the first 60 seconds and every 5 seconds to take a data eigenvalue, multipoint eigenvalue extraction to do data training, then take the data filter processing. The results are shown in Figure8.Figure 8
60s filter apple gas concentration contrast. (a) Carbon dioxide concentration. (b) Ethylene concentration contrast. (c) Ethanol concentration. (d) Oxygen concentration.
(a)(b)(c)(d)As can be seen from the diagram, after preprocessing, concentration information of carbon dioxide, ethanol, and ethylene after 30 seconds is used as determining factor to determine freshness of apple based on stability of the sensor. The extracted data are trained and tested by extracting the eigenvalues.The original data volume of gas sensor array is very large, dimension is correspondingly large, so complexity of classifier is also increasing; and it is easy to produce explosion. The performance of classifier can be improved by reducing dimension and improving extraction of eigenvalues. The extraction of sensor data eigenvalues is to transform the samples from high-dimensional space to low-dimensional space by mapping or transformation and extract main information which reflects essential attributes of target signal. The optimal value of BP neural network optimized by hybrid frog-leaping algorithm is used to train the network, which can accurately distinguish apples with different freshness.


## 3.2.1. Data for Removing Singularities

The data of carbon dioxide, ethylene, ethanol, and oxygen concentration are obtained by eliminating singularity of original data of apples with different freshness.


## 3.2.2. Least Square Filtering

Because of interference of the system and temperature sensitivity of the sensor, the data are filtered by linear least square filter to remove noise and get a relatively smooth image.


## 3.2.3. Extraction of Eigenvalues

Take the first 60 seconds and every 5 seconds to take a data eigenvalue, multipoint eigenvalue extraction to do data training, then take the data filter processing. The results are shown in Figure8.Figure 8
60s filter apple gas concentration contrast. (a) Carbon dioxide concentration. (b) Ethylene concentration contrast. (c) Ethanol concentration. (d) Oxygen concentration.
(a)(b)(c)(d)As can be seen from the diagram, after preprocessing, concentration information of carbon dioxide, ethanol, and ethylene after 30 seconds is used as determining factor to determine freshness of apple based on stability of the sensor. The extracted data are trained and tested by extracting the eigenvalues.The original data volume of gas sensor array is very large, dimension is correspondingly large, so complexity of classifier is also increasing; and it is easy to produce explosion. The performance of classifier can be improved by reducing dimension and improving extraction of eigenvalues. The extraction of sensor data eigenvalues is to transform the samples from high-dimensional space to low-dimensional space by mapping or transformation and extract main information which reflects essential attributes of target signal. The optimal value of BP neural network optimized by hybrid frog-leaping algorithm is used to train the network, which can accurately distinguish apples with different freshness.


## 3.3. Optimization of Sensor Array

In the process of odor recognition, sensor array is the key of information collection. Using reasonable gas sensor can not only improve recognition accuracy, but also improve collection efficiency. Continuous projection algorithm (SPA) is a forward variable selection method, which is used to solve classification problem. The purpose of SPA is to select a small set of variables with less redundancy and minimum collinearity, with elimination of redundant information in original matrix. The correlation contribution of each sensor to different freshness of apple is studied by PCA analysis. Figure9 is a bar chart of the contribution rates. Figure 10 is a histogram comparison of RMSEP (Root-Mean-Square Error of Prediction).Figure 9
Sensor contribution load diagram in first two principal component analyses.Figure 10
RMSEP values for different variables.As can be seen from the diagram, values of all sensors on PC1 are greater than 0.8, and the load coefficients of S2, S3, and S4 are very close, which means that these sensors have similar recognition functions and some overlapping information. Therefore, redundant sensors can be removed from the array. By retaining useful sensors and eliminating redundant ones, the sensor array platform of the system is reconfigured by using sensor array optimization SPA algorithm. Figure10 shows RMSEP with different number of variables (number of sensors), in which three sensors (S1, S2, and S4) in the array are selected according to the relatively low RMSEP.


## 3.4. Hybrid Leapfrog Algorithm

Leapfrog algorithm (SFLA) is a heuristic group evolutionary algorithm with high computational performance and excellent global search ability. The flow of hybrid leapfrog algorithm is shown in Figure11.Figure 11
Flowchart of mixed leapfrog algorithm.The algorithm works like this:(1)
Initialize the population information to determine the population sizeF, as shown in the following formula:(2)F=m∗n.Among them,m is for the number of subgroups, and n is for the number of frogs in each group.(2)
Compute fitness, the objective function value for each solution.(3)
According to descending order of fitness, write down location of the first best frog as the first global optimal solution.F frogs are assigned to m groups and each group has n frogs. Then start population optimization (local optimization). The positions of the best and worst frogs in the subpopulations are recorded as Pb and PW, respectively. Trigonometric probability distribution is used to assign more weights to frogs with better fitness values and lower weights to frogs with worse fitness values. So the highest probability of a frog being selected as a subgroup is P1=2/n+1 , and the lowest probability is P1=2/nn+1. Update position of the frog by optimizing the position of the worst frog in the subgroup in formulas (3) and (4).(3)DS=rand∗Pb−PW,rand is a random number of [0, 1].(4)DS=minintrand∗Pb−PW,Smax=maxintrand∗Pb−PW,−Smax,−Dmax≤¯DS≤¯DmaxSmax represents the maximum step allowed by an individual frog.Replace the bad frog with the better frog, and if you do not get a better frog after the update, randomly generate a frog to replacePW and return to the loop. The algorithm outputs the optimal solution and ends until the number of cycles or the stop condition is met.


## 3.5. Optimizing BP Neural Network

The structure of BP neural network is determined according to characteristics of input and output data of the system. Because the input signals of odor characteristics have 9 dimensions, there are 3 kinds of freshness characteristics to be classified. According to Kolmogorov’s theorem, the range of hidden layer nodes is [4, 13], and the optimum number of hidden layers n is 10. So the structure of BP neural network is 9-10-3; that is, there are 9 nodes in input layer and 10 nodes in hidden layer; the output layer has three nodes.After pretreatment, 900 groups of fresh degree characteristic signals are selected, from which 750 groups of data are randomly selected to train the network, and 150 groups of data are used to test the network classification ability. The expected output vector of fresh apple is set to [1, 0, 0]; the expected output vector of moderately rotten apple is set to [0, 1, 0]; the expected output vector of severely rotten apple is set to [0, 0, 1]. The training data are normalized according to the following formula:(5)Xn=xn−xminxmax−xmin.The training error of BP neural network is shown in Figure12, and the training error of optimized network is shown in Figure 13.Figure 12
BP training error.Figure 13
Optimizing BP training error.The unoptimized network reaches the minimum system error4.21e−12 after 15 iterations, and the optimized network reaches the minimum system error 3.49e−10 after 12 iterations. The optimized network has fewer iterations than the unoptimized network, and the optimized algorithm is better than the original algorithm in training times and error.Through 750 sets of data trained network, 150 sets of data are classified and 150 sets of sample data are randomly mixed to test accuracy and stability of the network. The results show that freshness of apples is divided into three grades; 148 out of 150 groups of test data could correctly identify the freshness of apple, and the classification accuracy is as high as 98.67%.


## 4. Conclusion

In this paper, quick detection and analysis of apple freshness is completed by the optimization of odor recognition system, data preprocessing, sensor array, and BP neural network algorithm optimized by mixed frog leaping. The experimental results show that the algorithm has advantages of strong overall searching ability, fast training speed, and high recognition efficiency. The sensor array has reasonable composition and high accuracy and also can distinguish apples with different freshness. However, there are some limitations in the application of the system. To identify freshness of different kinds of fruits, it is necessary to pass a large number of experimental data, and the experimental testing time is slightly longer, and further optimization design is needed to realize the fast freshness detection of different kinds of fruits.



---

*Source: 5861326-2022-03-08.xml*