Design of Electronic Nose Detection System for Apple Quality Grading Based on Computational Fluid Dynamics Simulation and K-Nearest Neighbor Support Vector Machine

Apples are one of the most widely planted fruits in the world, with an extremely high annual production. Several issues should be addressed to avoid the damaging of samples during the quality grading process of apples (e.g., the long detection period and the inability to detect the internal quality of apples). In this study, an electronic nose (e-nose) detection system for apple quality grading based on the K-nearest neighbor support vector machine (KNN-SVM) was designed, and the nasal cavity structure of the e-nose was optimized by computational fluid dynamics (CFD) simulation. A KNN-SVM classifier was also proposed to overcome the shortcomings of the traditional SVMs. The performance of the developed device was experimentally verified in the following steps. The apples were divided into three groups according to their external and internal quality. The e-nose data were pre-processed before features extraction, and then Principal Component Analysis (PCA) and Linear Discriminant Analysis (LDA) were used to reduce the dimension of the datasets. The recognition accuracy of the PCA–KNN-SVM classifier was 96.45%, and the LDA–KNN-SVM classifier achieved 97.78%. Compared with other commonly used classifiers, (traditional KNN, SVM, Decision Tree, and Random Forest), KNN-SVM is more efficient in terms of training time and accuracy of classification. Generally, the apple grading system can be used to evaluate the quality of apples during storage.


Introduction
A considerable number of countries in the world regard apples as a major consumer fruit because of their strong ecological adaptability, high nutritional value, good storability, and long supply cycle [1]. In terms of the fruit industry, the study focusing on the detection of apple quality is crucial and urgent. The chemical analysis method is used because the traditional fruit quality assessment method has shortcomings of sample damage, complicated operation procedures, long testing periods, and the inability to achieve real-time detection. Among non-destructive testing methods, physical detection methods (e.g., near-infrared spectroscopy and hyperspectral imaging) have emerged and rapidly developed in recent years and have become popular in this field [2][3][4][5]. Nevertheless, the information obtained by near-infrared spectroscopy and hyperspectral spectroscopy is easily obscured by the spectral changes caused by the physical properties of food [6]. Furthermore, most of the instruments used in this method are complicated and expensive. Table 1. Descriptions of the three levels of apple quality: L1, L2, and L3.

Level
External Quality Internal Quality

L1
No stab wounds, broken skin, crushed wounds, disease wounds, insect wounds, rot, or shrinkage on the surface of apples; smooth and rosy surface.
No rot, shrinkage, or dryness inside the apples, which can be eaten normally.

L2
Slight skin damage, stab wounds, or frostbite appear on the surface of the apple, and there are a few black spots. No rot, shrinkage, or dryness inside apples.

L3
The surface of the apple is obviously damaged, with pests and disease, and there is decay or shrinkage.
Rot, shrinkage, or dryness inside the apples, which cannot be eaten normally. Figure 1 is the schematic illustration of the developed e-nose system. The system consists of two subsystems: the hardware that reacts with gases and the software that analyzes the data. The hardware includes a gas cylinder, a gas pipe, regulating valves, a sensor array, control circuits, an A/D acquisition card, and a computer. The software was developed to pre-process the data obtained by the sensor array and extract the features from these datasets. The KNN-SVM method was used to grade the quality of apples.

Design of the Device 2.2.1. Overall Design of the Device
(3) The features of the 18-dimensional gas data were extracted from the data collected by the designed e-nose, and then the KNN-SVM classifier was proposed in this study to achieve accurate and non-destructive apple grading.

Materials
Red Fuji apples of different qualities were used as the research objects. The fruits were graded by human experts on the basis of their external quality and internal quality into three grades, i.e., L1, L2, and L3, as detailed in Table 1. The volatilized gases of apples mainly include CO2, alcohols, hydrocarbons, lipids, and a small number of amines and nitrogen gases. The odor of an apple is closely related to its quality [23,24]; when apples are degraded (e.g., rotted or broken), there is a change in the concentration of the gases they emit, such as ethylene. Table 1. Descriptions of the three levels of apple quality: L1, L2, and L3.

External Quality
Internal Quality No stab wounds, broken skin, crushed wounds, disease wounds, insect wounds, rot, or shrinkage on the surface of apples; smooth and rosy surface.
No rot, shrinkage, or dryness inside the apples, which can be eaten normally.
light skin damage, stab wounds, or frostbite appear on the surface of the apple, and there are a few black spots.
No rot, shrinkage, or dryness inside apples. The surface of the apple is obviously damaged, with pests and disease, and there is decay or shrinkage.
Rot, shrinkage, or dryness inside the apples, which cannot be eaten normally. Figure 1 is the schematic illustration of the developed e-nose system. The system consists of two subsystems: the hardware that reacts with gases and the software that analyzes the data. The hardware includes a gas cylinder, a gas pipe, regulating valves, a sensor array, control circuits, an A/D acquisition card, and a computer. The software was developed to pre-process the data obtained by the sensor array and extract the features from these datasets. The KNN-SVM method was used to grade the quality of apples.   The device was designed as a highly-symmetrical circular tube to guarantee a uniform and stable gas flow inside of the device [24]. The structure of the nasal cavity is detailed in Figure 2, where the left part is the gas inlet and the right part is the exhaust outlet. The device was designed as a highly-symmetrical circular tube to guarantee a uniform and stable gas flow inside of the device [24]. The structure of the nasal cavity is detailed in Figure 2, where the left part is the gas inlet and the right part is the exhaust outlet.

Gas Sensor Array
The core component of the sensor unit is an array of sensitive devices consisting of six SnO2 gas sensors (MQ-9, MQ-3, MQ-6, MQ-8, MQ-2, and MQ-135). According to the gases emitted by the apples, six gas sensors were selected to form a circular sensor array for detecting the concentrations of CO, CO2, alcohols, hydrocarbons, harmful gases (including ammonia, sulfides, benzene vapors, etc.), and hydrogen gas. The details of the sensor are shown in Table 2. The six sensors were evenly mounted on the ring to reduce the error caused by the sensor position. The specific structure of the sensor array is detailed in Figure 3.

Gas Sensor Array
The core component of the sensor unit is an array of sensitive devices consisting of six SnO 2 gas sensors (MQ-9, MQ-3, MQ-6, MQ-8, MQ-2, and MQ-135). According to the gases emitted by the apples, six gas sensors were selected to form a circular sensor array for detecting the concentrations of CO, CO 2 , alcohols, hydrocarbons, harmful gases (including ammonia, sulfides, benzene vapors, etc.), and hydrogen gas. The details of the sensor are shown in Table 2. The six sensors were evenly mounted on the ring to reduce the error caused by the sensor position. The specific structure of the sensor array is detailed in Figure 3.

Steady Flow Plate
The SnO 2 sensor detects the gas through the change in the conductivity caused by the adsorption and desorption of gas molecules on the semiconductor surface [25]. The flow condition in the sensing chamber strongly influences the e-nose's ability to recognize and quantify odors [26]. Therefore, the detection accuracy of the sensor is related to the stability of the gas flow. Porous steady flow plates were designed in this study, as shown in Figure 4. The two kinds of nasal cavity structures with and without steady flow plates were compared and simulated by CFD simulation to select the optimal one.

Air Inlet Dimensions
The size of the inlet is required for the calculation of the Reynolds number for flow field simulation; hence, we demonstrate the size of the inlet in Figure 5. According to the size and other characteristics of this device, it is appropriate to use laminar flow for simulation.

Steady Flow Plate
The SnO2 sensor detects the gas through the change in the conductivity caused b adsorption and desorption of gas molecules on the semiconductor surface [25]. The condition in the sensing chamber strongly influences the e-nose's ability to recognize quantify odors [26]. Therefore, the detection accuracy of the sensor is related to the st ity of the gas flow. Porous steady flow plates were designed in this study, as show Figure 4. The two kinds of nasal cavity structures with and without steady flow p were compared and simulated by CFD simulation to select the optimal one.

Air Inlet Dimensions
The size of the inlet is required for the calculation of the Reynolds number for field simulation; hence, we demonstrate the size of the inlet in Figure 5. According to size and other characteristics of this device, it is appropriate to use laminar flow for ulation.

Steady Flow Plate
The SnO2 sensor detects the gas through the change in the conductivity caused by the adsorption and desorption of gas molecules on the semiconductor surface [25]. The flow condition in the sensing chamber strongly influences the e-nose's ability to recognize and quantify odors [26]. Therefore, the detection accuracy of the sensor is related to the stability of the gas flow. Porous steady flow plates were designed in this study, as shown in Figure 4. The two kinds of nasal cavity structures with and without steady flow plates were compared and simulated by CFD simulation to select the optimal one.

Air Inlet Dimensions
The size of the inlet is required for the calculation of the Reynolds number for flow field simulation; hence, we demonstrate the size of the inlet in Figure 5. According to the size and other characteristics of this device, it is appropriate to use laminar flow for simulation.

Experimental Verification by CFD Simulation
CFD is a discipline that uses numerical methods to solve governing equations to discover the laws of various flow phenomena. The designed e-nose system was analyzed by CFD simulation to explore whether the addition of the steady flow plates could improve the detection accuracy of the e-nose. ANSYS 2019 R1 software was used for grid division, model solving, and post-processing for CFD simulation in this study with an Inter (R) Core (TM) i5-6500 CPU @ 3.20 GHz × 4, 16 G memory, NVIDIA GeForce GTX 750 Ti graphics card.

Construction of the 3D Electronic Nose Model
The 3D e-nose model was designed using SolidWorks according to the above analysis, as demonstrated in Figure 6, where (a) is a model without steady flow plates, and (b) is a model with steady flow plates.

Experimental Verification by CFD Simulation
CFD is a discipline that uses numerical methods to solve governing equations to discover the laws of various flow phenomena. The designed e-nose system was analyzed by CFD simulation to explore whether the addition of the steady flow plates could improve the detection accuracy of the e-nose. ANSYS 2019 R1 software was used for grid division, model solving, and post-processing for CFD simulation in this study with an Inter (R) Core (TM) i5-6500 CPU @ 3.20 GHz × 4, 16 G memory, NVIDIA GeForce GTX 750 Ti graphics card.

Construction of the 3D Electronic Nose Model
The 3D e-nose model was designed using SolidWorks according to the above analysis, as demonstrated in Figure

Experimental Verification by CFD Simulation
CFD is a discipline that uses numerical methods to solve governing equations to discover the laws of various flow phenomena. The designed e-nose system was analyzed by CFD simulation to explore whether the addition of the steady flow plates could improve the detection accuracy of the e-nose. ANSYS 2019 R1 software was used for grid division, model solving, and post-processing for CFD simulation in this study with an Inter (R) Core (TM) i5-6500 CPU @ 3.20 GHz × 4, 16 G memory, NVIDIA GeForce GTX 750 Ti graphics card.

Construction of the 3D Electronic Nose Model
The 3D e-nose model was designed using SolidWorks according to the above analysis, as demonstrated in Figure 6, where (a) is a model without steady flow plates, and (b) is a model with steady flow plates.

Governing Equations
The governing equations of gas molecule transmission include continuity Equation (1), mass conservation Equation (2), and component mass conservation Equation (3) [27], as expressed by: where x i is the position vector, u i is the velocity vector, ρ is the fluid density, t is the time, u, v, and w are the components of the velocity vector in the x, y, and z directions, respectively, c s is the volume concentration of component s, ρc s is the mass concentration , where u in is the average velocity at the inlet, D in is the inlet diameter, and µ is the dynamic viscosity.

Meshing
Meshing was performed using the ANSYS workbench mesh. The physics preference was divided by CFD. Because of the complex internal structure, FILL was used to obtain the internal watershed in the DM, and non-structural meshing was adopted for the watershed. where is the position vector, is the velocity vector, is the fluid density, is the time, u, v, and w are the components of the velocity vector in the x, y, and z directions, respectively, is the volume concentration of component s, is the mass concentration of the component, is the diffusion coefficient of the component, and is the mass of the component produced by the chemical reaction per unit volume in unit time. The Reynolds number is = , where is the average velocity at the inlet, is the inlet diameter, and is the dynamic viscosity.

Meshing
Meshing was performed using the ANSYS workbench mesh. The physics preference was divided by CFD. Because of the complex internal structure, FILL was used to obtain the internal watershed in the DM, and non-structural meshing was adopted for the watershed. The model without steady flow plates was divided into 813,176 nodes and 4,271,631 cells, as shown in Figure 7a. The model with steady flow plates was divided into 1,907,501 nodes and 9,878,409 cells, as shown in Figure 7b.

Setting Boundary Conditions
The parser uses Fluent in the ANSYS component. The Reynolds number obtained in the calculation of the e-nose model was less than 2320, so the numerical simulation process was a laminar flow process. The boundary conditions for simulating the flow field are shown in Table 3.

Setting Boundary Conditions
The parser uses Fluent in the ANSYS component. The Reynolds number obtained in the calculation of the e-nose model was less than 2320, so the numerical simulation process was a laminar flow process. The boundary conditions for simulating the flow field are shown in Table 3.

. Data Collection and Feature Extraction
Before the formal test, MQ-135 was used to conduct a pre-collection test to compare the data collection before and after the optimized design of the e-nose. As can be seen in Figure 8, the data collected by the optimized device were more stable than those before optimization, which is conducive to feature extraction later.
The odor information of the three groups of apples was collected using the designed device. Firstly, the gas in the sample box was exhausted. After the apples were placed in the sample box for 2 min, the device began to extract the gas in the sample box, and the gas passed through the steady flow plates then contacted the sensor array, causing a change in the output voltage of the sensor, and the output voltage ranged from 0 V to 3.3 V. The output voltage was then transferred to the computer after AD conversion. Take the change in the sensor data for L1 apple quality over time as an example. Figure 9 shows that the data were gradually stable after 20 s. The data were selected as the response data of the sensor after 20 s to facilitate the extraction of data features. Figure 10 demonstrates the raw response curves of six sensors for L1, L2, and L3. The ordinate is the voltage value output of the sensor, and the abscissa is the frequency of collection.

Data Collection and Feature Extraction
Before the formal test, MQ-135 was used to conduct a pre-collection tes the data collection before and after the optimized design of the e-nose. As ca Figure 8, the data collected by the optimized device were more stable than optimization, which is conducive to feature extraction later. The odor information of the three groups of apples was collected using t device. Firstly, the gas in the sample box was exhausted. After the apples we the sample box for 2 min, the device began to extract the gas in the sample gas passed through the steady flow plates then contacted the sensor arra change in the output voltage of the sensor, and the output voltage ranged fro V. The output voltage was then transferred to the computer after AD convers change in the sensor data for L1 apple quality over time as an example. Fig that the data were gradually stable after 20 seconds. The data were selecte sponse data of the sensor after 20 seconds to facilitate the extraction of data f ure 10 demonstrates the raw response curves of six sensors for L1, L2, and L3. is the voltage value output of the sensor, and the abscissa is the frequency of    The features were extracted from the original curves to verify whether the device could grade the quality of apples. Jitter was observed in the sampled value because of the existence of interference, as indicated in Figure 10. The SG (Savitzky-Golay) filtering algorithm [28] was used to obtain the final data. The SG algorithm uses the least squares method and moves the window on the basis of a polynomial in the time domain. This method preserves the detailed features of signals while filtering out the noise. Figure 11 is the pre-processed curve. After repeated comparisons, the maximum value, the stable value, and the average value were extracted from the curve as a set of features. Thus, the 18-dimensional features were obtained by the six sensors. For each apple, ten features were collected, and a total of 300 sets of the feature were collected. In order to observe the relationship between feature parameters of each sensor more intuitively, the feature values were visualized, as shown in Figure 12. The features were extracted from the original curves to verify whether the device could grade the quality of apples. Jitter was observed in the sampled value because of the existence of interference, as indicated in Figure 10. The SG (Savitzky-Golay) filtering algorithm [28] was used to obtain the final data. The SG algorithm uses the least squares method and moves the window on the basis of a polynomial in the time domain. This method preserves the detailed features of signals while filtering out the noise. Figure 11 is the pre-processed curve. After repeated comparisons, the maximum value, the stable value, and the average value were extracted from the curve as a set of features. Thus, the 18-dimensional features were obtained by the six sensors. For each apple, ten features were collected, and a total of 300 sets of the feature were collected. In order to observe the relationship between feature parameters of each sensor more intuitively, the feature values were visualized, as shown in Figure 12.
existence of interference, as indicated in Figure 10. The SG (Savitzky-Golay) filteri gorithm [28] was used to obtain the final data. The SG algorithm uses the least sq method and moves the window on the basis of a polynomial in the time domain method preserves the detailed features of signals while filtering out the noise. Figu is the pre-processed curve. After repeated comparisons, the maximum value, the value, and the average value were extracted from the curve as a set of features. Thu 18-dimensional features were obtained by the six sensors. For each apple, ten fea were collected, and a total of 300 sets of the feature were collected. In order to observ relationship between feature parameters of each sensor more intuitively, the featur ues were visualized, as shown in Figure 12.

Principal Component Analysis (PCA)
PCA transforms multidimensional indicators into a few comprehensive indicators [29]. Since gas sensors often have cross-sensitivity with each other [30], the sole analysis at the variable level ignores the potential link between variables. When using PCA to analyze the data, the raw data can be transformed into a set of linearly independent dimensions. The method for extracting PCA feature vectors is described as follows.
Step 1: Calculate the population mean u of the sample by: Step 2: Calculate the covariance matrix S of the sample by:

Principal Component Analysis (PCA)
PCA transforms multidimensional indicators into a few comprehensive indicators [29]. Since gas sensors often have cross-sensitivity with each other [30], the sole analysis at the variable level ignores the potential link between variables. When using PCA to analyze the data, the raw data can be transformed into a set of linearly independent dimensions. The method for extracting PCA feature vectors is described as follows.
Step 1: Calculate the population mean u of the sample by: Step 2: Calculate the covariance matrix S of the sample by: Step 3: Perform feature decomposition on the covariance matrix and select the largest features in S to form a new feature vector.

Linear Discriminant Analysis (LDA)
The basic idea of LDA is to project high-dimensional samples into the optimal discriminant vector space to achieve the purpose of extracting classification information and compressing the dimensions of the feature space [17]. The LDA method can find the optimal projection direction of the feature vector, which can maximize the ratio of the inter-class matrix to the intra-class dispersion matrix of the post-projection vector, thereby improving the recognition accuracy. The LDA feature vector was extracted using the following steps.
Step 1: Calculate the inter-class dispersion S b of the dataset x in the d-dimensional feature space by: where u i is the mean vector of the i th sample category, and L is the number of categories.
Step 2: Calculate the intra-class dispersion S w of the d-dimensional feature space by: Step 3: Solve the features of the matrix S −b w S b and select the vector consisting of the largest features as the new feature vector.

KNN-SVM Classifier
The K-nearest neighbor (KNN) algorithm is a popular machine learning algorithm. The principle of this algorithm is that if the majority of the k samples closest to a sample in a feature space belong to a specific category, then the sample also belongs to this category [31,32]. The distance can adopt the Euclidean distance, Manhattan distance, norm, etc. This study uses Euclidean distance, as given by: SVM [33] focuses on how to build a learning machine and how to implement classification on the basis of statistics and optimization. The idea of SVM is to find the best separation hyperplane in the feature space so that the intervals of the positive and negative samples on the training set are the largest, thus minimizing the structural risks. SVM is mainly used to research the classification of two categories. The commonly used methods are the one-to-one method and the one-to-many method for multi-classification problems [34]. The one-to-many method is the earliest and currently the most extensively used. This study adopts the one-to-many approach.
The SVM solves support vectors using quadratic programming, where storage and computation consume substantial machine memory and runtime. Therefore, SVM al-gorithms are challenging to use for processing large-scale training samples. Because of this problem, this study proposes a KNN-SVM classifier. The KNN-SVM classifier was constructed as follows: For the classification of the samples to be tested, first, the KNN algorithm was used to select K values from the training samples that were the nearest neighbors of the samples to be tested. If K values belong to the same category, the samples to be tested belong to this category. If K values do not belong to the same category, K sample values are taken as the new training set, and the SVM training model is used. The kernel function of the SVM adopts the Gaussian radial kernel function, expressed by: The optimal values of the k in the KNN, the kernel width of the kernel function in the SVM, and the error multiplication parameter C were selected by the cross-validation of the sample. The classification model trained by the new training set had a better classification effect on the samples to be tested compared with the model trained by the original large-scale data. The process of the KNN-SVM algorithm is shown in Figure 13. Experimental results showed that compared with the traditional SVM algorithm, KNN-SVM was improved in both classification accuracy and speed, and it is suitable for largescale data.

Classic Classifiers
Commonly used classification algorithms include the KNN algorithm, SVM algorithm, Decision Tree, Random Forest, etc. Decision Tree analysis is a classification algorithm for data mining. Decision Tree exists logically in the form of a tree, including root nodes, internal nodes, and leaf nodes. The root nodes contain a set of all data in the da-

Classic Classifiers
Commonly used classification algorithms include the KNN algorithm, SVM algorithm, Decision Tree, Random Forest, etc. Decision Tree analysis is a classification algorithm for data mining. Decision Tree exists logically in the form of a tree, including root nodes, internal nodes, and leaf nodes. The root nodes contain a set of all data in the dataset. Each internal node is a judgment condition and includes a set of data in the dataset that satisfies all the conditions from the root node to the node. The data corresponding to the internal node are classified into two or more child nodes according to the testing result of the judgment condition of the internal node. The leaf node is the final category, and the data contained in the leaf node belong to the category [35]. Random Forest is constructed on the basis of multiple Decision Trees. The integrated learning idea of Bagging is adopted in a Decision Tree, and random feature selection is adopted in the process of training a Decision Tree. The steps for implementing a Decision Tree are as follows. Firstly, N samples are randomly selected from the original dataset, and then the training algorithm is performed on the N samples to obtain N decision trees. When using Random Forest for classification, the N Decision Trees are used for prediction, and the final classification is determined by voting for the final prediction result of each Decision Tree [36]. In the experiment, the above classic classifiers were compared with the proposed KNN-SVM classifier.

Simulation Results of the Flow Fields in Two Nasal Cavity Structures
The flow field simulations of the two nasal cavity structures are shown in Figures 14 and 15. In the simulation, the inlet velocity was set at 0.1 m/s. It can be seen from the figures that for the device without steady flow plates, the gas inside the device returned after hitting the pipe wall, causing a disorder in the airflow around the sensor. Therefore, the measured gas data were unstable. By contrast, for the device with steady flow plates, the gas inside the device smoothly and evenly passed through the sensor array. As a result, there was a need to add steady flow plates in the nasal cavity structure. after hitting the pipe wall, causing a disorder in the airflow around the sensor. Therefore, the measured gas data were unstable. By contrast, for the device with steady flow plates, the gas inside the device smoothly and evenly passed through the sensor array. As a result, there was a need to add steady flow plates in the nasal cavity structure.  The gas molecules must smoothly pass through the sensor array to make sure the odorous gas can be accurately detected by the gas sensor in the nasal cavity. It can be seen from the simulation results that the second nasal cavity structure was superior to the first one. Therefore, the second structure was selected to verify the feasibility of the designed e-nose. The overall design is shown in Figure 16. after hitting the pipe wall, causing a disorder in the airflow around the sensor. Therefore, the measured gas data were unstable. By contrast, for the device with steady flow plates, the gas inside the device smoothly and evenly passed through the sensor array. As a result, there was a need to add steady flow plates in the nasal cavity structure.  The gas molecules must smoothly pass through the sensor array to make sure the odorous gas can be accurately detected by the gas sensor in the nasal cavity. It can be seen from the simulation results that the second nasal cavity structure was superior to the first one. Therefore, the second structure was selected to verify the feasibility of the designed e-nose. The overall design is shown in Figure 16. The gas molecules must smoothly pass through the sensor array to make sure the odorous gas can be accurately detected by the gas sensor in the nasal cavity. It can be seen from the simulation results that the second nasal cavity structure was superior to the first one. Therefore, the second structure was selected to verify the feasibility of the designed e-nose. The overall design is shown in Figure 16. Figure 15. The flow field simulation cavity structure with steady flow plates.
The gas molecules must smoothly pass through the sensor array to make sure t odorous gas can be accurately detected by the gas sensor in the nasal cavity. It can be se from the simulation results that the second nasal cavity structure was superior to the fi one. Therefore, the second structure was selected to verify the feasibility of the design e-nose. The overall design is shown in Figure 16.  PCA and LDA were performed on the 300 sets of 18-dimensional data, and the partial features, variance contribution rates, and cumulative variance contribution rates corresponding to PCA and LDA were obtained, as shown in Table 4. For the LDA, since the contribution rate of the component from the third item was much lower than 1, it is not listed in the table. It can be seen in Table 4 that the variance contribution rate of the second component after PCA processing was not more than 1, the cumulative contribution rate of PC1 and PC2 was 97.8%, and the cumulative contribution rate of LD1 and LD2 by LDA was 99.96%. Thus, the cumulative contribution rates were all greater than 95%, indicating that the first two components of the two analytical methods could reflect all the information of the collected data. The grading results by PCA and LDA are shown in Figure 17. It can be seen from the figure that more than 90 percent of the data have no overlap, and the same kind of data are clustered together, which indicates that the designed e-nose system could accurately measure the odor data of one category of apples. In the data analysis section. we used Python 3.7 language and Pycharm 2020 (JetBrains, CZE).

Rapid Classification of Apple
In this study, the dataset was divided with a ratio of 4:1; 240 sets of independent sample data were used as the training set to train the model in the test, and 60 sets of independent sample data were used as the test set. The PCA 2D feature vector, the LDA 2D feature vector, and the original 18-dimensional feature vector were input into the KNN-SVM classifier. Since LDA belongs to supervised dimensionality reduction, the projection vector obtained from the training set was used in the dimensionality reduction of the test set, and the data were input into the classifier after dimensionality reduction. The results are shown in Table 5. The recognition rate in the table takes an average of the recognition results in the test set. It can be seen that after the dimensions of the data were effectively reduced, the recognition accuracy was improved, and the training time was significantly reduced. Because of the cross-sensitivity of the gas sensors, the features of the original data affect each other. The generation of 2D linear independent feature vector groups using PCA and LDA not only reduces the data training time but also improves recognition accuracy. ysis section. we used Python 3.7 language and Pycharm 2020 (JetBrains, CZE).    The KNN algorithm was used as the training sample, and the model parameters of the SVM were constantly adjusted to learn the optimal classification hyperplane, which is the advantage of this algorithm. The proposed algorithm was compared with four popular classifiers: KNN, SVM, Decision Tree, and Random Forest. The data whose dimensions were reduced by PCA and LDA were used as the input, and the result with the highest accuracy was taken as the final result. The results are shown in Table 6. The data in the table expresses that the proposed classification method has certain advantages in accuracy and training time compared with other classification methods. The recognition accuracies of the four classic classifiers were 93.3%, 83%, 93%, and 91%, respectively. By contrast, the recognition accuracy of the proposed method was 97.78%. The training times of the four classic classifiers were 0.307 s, 0.858 s, 0.860 s, and 0.350 s, respectively, while that of the proposed method was 0.614 s. Overall, the training time of the proposed method was slightly longer than that of the traditional KNN and Decision Tree, whereas the recognition accuracy of the former was significantly improved. The e-nose device used in this study had a higher recognition rate for determining apple quality than the device used by Nturambirwe [33]. Compared with the studies of Rasekh et al. [37] and Tatli et al. [38], the e-nose technology applied in apple detection in this study achieved higher accuracy.

Conclusions
In this study, an e-nose system with an optimized nasal cavity structure was designed. The flow fields of the two nasal cavity structures with and without the steady flow plates were simulated. It was found that the airflow of the nasal cavity with the constant flow plates was more even and stable. Therefore, the steady flow plate was adopted in the e-nose to grade the apples on the basis of their quality. PCA and LDA were performed for the data collected from the designed e-nose. The features of the 18-dimensional gas data were extracted. Although some data were overlapped, they could still be generally distinguished. Then, the KNN-SVM classifier was constructed, and the original 18-dimensional data, dimension-reduced PCA data, and dimension-reduced LDA data were used as the input of the classifier. The accuracy of classification for the LDA data was 97.78%. On the basis of a comparison between the proposed classifier and other popular classifiers, it was discovered that the former had a better performance in both accuracy and speed. The e-nose device only took several seconds for data processing after the pre-work of detection was ready, which demonstrates the effectiveness of the device for apple grading. The method might be applicable to other fruit quality assessments.