The Effect of Light Intensity, Sensor Height, and Spectral Pre-Processing Methods When Using NIR Spectroscopy to Identify Different Allergen-Containing Powdered Foods

Food allergens present a significant health risk to the human population, so their presence must be monitored and controlled within food production environments. This is especially important for powdered food, which can contain nearly all known food allergens. Manufacturing is experiencing the fourth industrial revolution (Industry 4.0), which is the use of digital technologies, such as sensors, Internet of Things (IoT), artificial intelligence, and cloud computing, to improve the productivity, efficiency, and safety of manufacturing processes. This work studied the potential of small low-cost sensors and machine learning to identify different powdered foods which naturally contain allergens. The research utilised a near-infrared (NIR) sensor and measurements were performed on over 50 different powdered food materials. This work focussed on several measurement and data processing parameters, which must be determined when using these sensors. These included sensor light intensity, height between sensor and food sample, and the most suitable spectra pre-processing method. It was found that the K-nearest neighbour and linear discriminant analysis machine learning methods had the highest classification prediction accuracy for identifying samples containing allergens of all methods studied. The height between the sensor and the sample had a greater effect than the sensor light intensity and the classification models performed much better when the sensor was positioned closer to the sample with the highest light intensity. The spectra pre-processing methods, which had the largest positive impact on the classification prediction accuracy, were the standard normal variate (SNV) and multiplicative scattering correction (MSC) methods. It was found that with the optimal combination of sensor height, light intensity, and spectra pre-processing, a classification prediction accuracy of 100% could be achieved, making the technique suitable for use within production environments.


Role of Powdered Foods in the Food Industry
Powdered foods represent a significant share of the modern human diet, mostly as ingredients in food products or cooked meals. Powdered food materials can be baked (e.g., cakes), used as seasoning (e.g., spices), or added to liquids to produce drinks (e.g., powdered milk). Powdered foods can even be made from basic chemicals, such as water and CO 2 [1], and are essential for future endeavours, such as space exploration [2]. Powders can be defined as, "particulate solid state materials containing discrete particles of size ranging from nanometres to millimetres" [3]. The properties of food powders drastically affect the final product quality and consequently the consumer appreciation. In addition, the primary properties of powders, such as shape and density, have significant effects on product performance, such as rehydration rates of powdered drinks [4]. Therefore, it is important to monitor and measure the primary properties of powdered foods to ensure the final food products have the required performance.

Powder Food Allergens and Digital Technologies in the Food Industry
In addition to monitoring the powdered food properties it is also important to monitor their compositions; this is especially the case when they contain known food allergens. Globally, there is an increase in the number of people with food allergies, and it has been estimated that 4% of the total world population now suffers from food allergies, with an even higher percentage in infants and children (8%) [5]. The consequences of food allergies are sometimes debilitating, such as celiac disease, and can often be life threatening. There are 14 identified major types of food allergens-celery, cereal containing gluten, crustaceans, eggs, fish, lupin, milk, molluscs, mustard, tree nuts, peanuts, soybeans, and sulphur dioxide [6]. It is important to state that allergen compounds are mostly just proteins or proteinaceous materials and can even be found in low concentrations in products such as fresh fruits and vegetables [7,8]. The majority of allergens listed above can be found in powdered form and are used as ingredients in food products. Despite the significant advances in medical treatments for many diseases, there is no cure for food allergies [5]. Although medicines exist to treat the symptoms of allergic reactions [9], the best method for people with allergies is to ensure they do not eat food containing these allergens. The current techniques for detecting the presence of food allergens are all laboratory-based, requiring a significant amount of time from a skilled individual [10]. For better allergen control within food production environments, there is a need for new technologies to identify materials which naturally contain allergens non-invasively in real-time [11]. Manufacturing is experiencing the fourth industrial revolution, which is the advanced use of data and Industrial Digital Technologies (IDT), such as sensors, artificial intelligence, the Industrial Internet of Things (IIoT), and robotics, to optimise manufacturing processes. Although these technologies are beginning to see widespread use within discrete manufacturing sectors (e.g., automotive), their adoption within process manufacturing environments (e.g., food and drink) is lower, due to barriers such as cost and suitability to operate in challenging industrial environments [12].

NIR Technology Applications in the Food Manufacturing
Near-infrared (NIR) spectroscopy is an optical method, which uses light with wavelengths between 780 and 2500 nm, and is a common method for the quality evaluation of food products [13,14]. Examples of its uses within food and drink manufacturing include identifying the chemical composition of fruits [15,16], vegetables [17,18], and meats [19,20]. NIR spectroscopy has been used to assess several quality parameters for various powder food types. Examples include using NIR to assess the geographical origin of flours [21]. In that study, NIR (1100-2000 nm) was used to scan wheat grain and flour samples, and classification models were built using partial least squares discriminant analysis (PLSDA), with prediction accuracies of 90-96%. The authentication of various powder samples has been performed using NIR spectroscopy [22][23][24][25][26]. Cocchi et al. [23] utilised a Vis/NIR system (400-2500 nm) Sensors 2020, 20, 230 3 of 24 to identify traces of bread wheat flour in durum wheat flour using soft independence modelling of class analogy (SIMCA) classification models. Ghosh et al. [14] used NIR spectroscopy to differentiate between several cereals (wheat, wheat, oats, spelt, rye, rice, and corn), legumes (soy, white chickpea, poppy, sesame, chia, rapeseed, sunflower seed), and peanut powder. Principal component analysis (PCA) was used as an effective unsupervised clustering technique to identify flours from other samples. In that work, PLSDA was then successfully applied to identify peanut samples from pint nut samples. Another study by Haughey et al. [15] explored the application of NIR spectroscopy (833-2632 nm) to determine soya meal adulteration by melamine, a recently reported adulterant in powdered milk, infant formula, and feed products leading to kidney illnesses and failure. Regression models developed using partial least squares regression (PLSR) had determination coefficient values (R 2 ) of 89-99%. Albanell et al. [16] used an NIR technique (1100-2500 nm) to detect low gluten concentrations (0-4.5%) in several gluten-free flours. Modified PLSR models yielded R 2 values of 68.2-96.7% depending on the adulterant concentration. NIR spectroscopy was also used for determining several quality attributes of flours, such as gliadin, gluten, protein, and moisture contents [27][28][29][30]. Badaró et al. [18] studied the feasibility of using a portable NIR sensor (900-1700 nm) to detect the presence of different dietary fibres (psyllium, bamboo, cellulose) added to semolina flour to enhance their nutritional profile. Classification models developed by the SIMCA technique resulted in 100% classification prediction accuracy, while R 2 values for regression models were as high as 98%. Wesley et al. [19] applied Vis/NIR spectroscopy (400-2500 nm) to estimate the content of gliadin and gluten content in wheat flour. The regression models developed by PLSR had R 2 values of 78 and 83% for gliadin and gluten, respectively.

Limitations of Online Applications of the NIR Technology
Although NIR technologies have extensive capabilities for measuring various quality parameters of food products in production environments, there are numerous challenges that must be addressed. Ensuring a representative sample of the material to be measured is a critical factor often affecting the features of the acquired spectra and, consequently, the performance of any classification or regression models developed [31]. Moreover, in powder foods, variations in physical properties (e.g., particle size) will significantly affect the chemical information identified by the NIR system [31]. In the case of diffuse reflectance NIR techniques, light penetrates and scatters inside the material before being reflected back and received by the detector [32]. Determining the optimal configuration of the NIR system for rapid and/or online monitoring of quality attributes is not a trivial task and preliminary experiments are required. It is known that the penetration depth of light into biological materials such as fruit tissues decreases exponentially. This penetration depth is also much less in the NIR region (780-2500 nm) than in the visible region (400-780 nm) [33]. Consequently, any factor that affects the penetration depth should be carefully studied in order to obtain the best configuration for diffuse reflectance measurements. The optimal height distance between the sensor and sample and the sensor light intensity are two important parameters that have to be determined experimentally. These factors are extremely important to consider for NIR systems designed to work in industrial manufacturing environments, where there may be limitations to the minimum distance the sensor can be located from the food sample (to avoid contact with the food and potential safety issues). Near-infrared spectroscopy methods are known to acquire large amounts of spectral data, which need to be pre-processed and analysed using data processing methods, often referred to as chemometrics [34]. General steps for using NIR technology are sample preparation, spectral acquisition, spectral pre-processing, followed by the development of classification and/or regression models [33]. It is known that the pre-processing method applied before the classification algorithms significantly affects the performance of the models [35]. Often, noisy or coarse spectra are acquired by the NIR sensors due to environmental effects (e.g., temperature and humidity), which affects the performance of the models [36]. Therefore, the acquired spectra should be pre-processed using mathematical techniques before being utilised in the machine learning models. Common pre-processing techniques include mean centring, Savitzky-Golay, first derivative smoothing, second derivative smoothing, normalisation, and multiplicative scattering Sensors 2020, 20, 230 4 of 24 correction (MSC) [34,35]. The appropriate pre-processing method is not always consistent and it differs between sample conditions, data acquisition protocol, and surrounding conditions, such as temperature and moisture. In addition, some spectra pre-processing methods may be more suitable for specific classification models and tests must be performed to determine the most suitable pre-processing methods for a specific application.
This work will focus on the development of an NIR spectroscopy method which utilises machine learning models to identify different powdered food samples which naturally contain allergens such as gluten. The work will focus on measurement parameters and data processing methods, which must be considered when performing measurements in industrial environments. The specific parameters studied are the height between the NIR sensor and the food sample, the sensor light intensity, and the spectra pre-processing methods utilised. A host of different powdered food samples will be studied, including flours, spices, and other materials relevant to the food and drink sector, in addition to a range of different classification machine learning methods.

Raw Materials
In this study, various powdered food materials were tested, some of which naturally contained allergens and others which were naturally allergen-free and not modified after purchasing. All of the samples were purchased from local markets in Nottingham, United Kingdom. A complete list of the materials is available in Table 1. A total of 53 materials were measured in this study. There were 13 gluten-containing flours, 8 gluten-free flours, 7 types of nuts, 4 animal-based powders, and 3 other powdered food materials (salt and sugars). Samples included several different brands of the same powdered food type, to determine if this had any effect of the recorded spectra and classification performance. Each sample was placed inside a 3 cm diameter petri dish. The fine powder samples were compressed by hand using a second empty petri dish to ensure the top surface was flat. Examples of the sample materials in petri dishes are shown in Figure 1a. It should be noted that the tested samples included powders, flakes, and seeds, which have different shapes and would produce differences in the recorded spectra [13,31]. Although some samples could easily be identified by their visible features (colour and shape), this was not possible for many, especially the flours (Figure 1a). The recorded spectral data were divided into two main groups, the Spices Group (SG), which contained 18 different materials, and the Flours Group (FG), which contained flours, nuts, and other non-spice samples. The FG contained 35 different materials. A complete description of the ingredients of each type, adopted from the nutritional labelling, inside the FG is provided in Table 2. Excluding the mixed herbs, which contained thyme, basil, marjoram, and oregano, any material in the SP contained only the named spice, either as a seed or ground to a powder.

Measurement System and Experimental Procedure
The measurement system used for the experiments is shown in Figure 1b. The system comprised a 3Dprinted plastic enclosure especially designed for the study. This included slotted groves at different vertical levels (1.5 cm apart), so the height between the food samples and the NIR sensor could be varied. A bespoke holder for the NIR sensor was designed and built to fit into the groves in the plastic enclosure. The NIR sensor used was a NIRONE S2.0, obtained from Spectral Engines, Oulu, Finland. This sensor had a compact shape and light weight (25 × 25 × 17.5 mm 3 , 15 g) making it suitable for integration with manufacturing technologies, such as robots and conveyor systems. The sensor contained two tungsten vacuum lamps with a peak power of 1 W and a single element extended InGaAs detector. The signal-to-noise ratio (SNR) of the sensor was 38.75 dB. The sensor was connected to the laptop via a USB cable. The sensor had a detection range of 1550-1950 nm and a spectral resolution of 1 nm, which made the number of acquired wavelengths 401 for each sample measured. A total of seven different height levels were possible with the holder. However, in this study only six levels were used, as the lowest level was too close to the sample surface to record a stable measurement. In this study, the six levels of sensor heights ranged from 1.5 to 10.5 cm. The light intensities used in the study were 30-90% of the maximum lamp power in 10% increments, resulting in seven levels of light intensities. Consequently, there were 42 possible combinations for height level and light intensity. Each sample was scanned for each combination using five replicates. Before scanning the first sample on a particular day, the sensor was turned on for 10 minutes at a light intensity of 90% to obtain a uniform absorbance. Moreover, at each height level, a reference spectrum was recorded using a white reference disk at 90% light intensity and a dark background measurement at 0% light intensity.

Measurement System and Experimental Procedure
The measurement system used for the experiments is shown in Figure 1b. The system comprised a 3D-printed plastic enclosure especially designed for the study. This included slotted groves at different vertical levels (1.5 cm apart), so the height between the food samples and the NIR sensor could be varied. A bespoke holder for the NIR sensor was designed and built to fit into the groves in the plastic enclosure. The NIR sensor used was a NIRONE S2.0, obtained from Spectral Engines, Oulu, Finland. This sensor had a compact shape and light weight (25 × 25 × 17.5 mm 3 , 15 g) making it suitable for integration with manufacturing technologies, such as robots and conveyor systems. The sensor contained two tungsten vacuum lamps with a peak power of 1 W and a single element extended InGaAs detector. The signal-to-noise ratio (SNR) of the sensor was 38.75 dB. The sensor was connected to the laptop via a USB cable. The sensor had a detection range of 1550-1950 nm and a spectral resolution of 1 nm, which made the number of acquired wavelengths 401 for each sample measured. A total of seven different height levels were possible with the holder. However, in this study only six levels were used, as the lowest level was too close to the sample surface to record a stable measurement. In this study, the six levels of sensor heights ranged from 1.5 to 10.5 cm. The light intensities used in the study were 30-90% of the maximum lamp power in 10% increments, resulting in seven levels of light intensities. Consequently, there were 42 possible combinations for height level and light intensity. Each sample was scanned for each combination using five replicates. Before scanning the first sample on a particular day, the sensor was turned on for 10 minutes at a light intensity of 90% to obtain a uniform absorbance. Moreover, at each height level, a reference spectrum was recorded using a white reference disk at 90% light intensity and a dark background measurement at 0% light intensity.

Data Analysis
The relative reflectance for each sample was calculated from the light intensities of the samples (I s ), the reference target (I r ), and the dark (I d ) using the following Equation: Relative re f lectance = I s − I d I r − I d . To overcome the effect of noise, either due to electronic sources or natural variations within the samples and the experimental environment, the acquired spectra should be pre-processed [33]. The pre-processing techniques implemented in this study were multiplicative scatter correction (MSC), first derivative smoothing, second derivative smoothing, standard normal variate (SNV), Savitzky-Golay, mean centring, scaling, and robust auto scaling in addition to using the raw spectra without any pre-processing. Such methods are effective in reducing the effect of noise on the spectra quality [37]. Multiplicative scatter correction is designed to reduce the effect of light scattering in spectroscopic data, whereas first and second derivative are smoothing techniques that are mainly applied to minimise the random noise and narrow spikes in spectra [34]. Standard normal variate is based on normalising the rows in the spectra by mean-centring them, then dividing by the standard deviation [34]. Savitzky-Golay is another smoothing method that uses localised polynomial regression to reduce the spikes in the spectra [36]. In this study, the window length for the Savitzky-Golay was chosen as 25. Although multiple different pre-processing methods could be applied to recorded spectra in series, in this work each method was applied individually to understand its effect on classification performance.
Principle component analysis (PCA) is an exploratory data analysis method used for dimension reduction in the case of high dimensional data, where there are more predictors than observations [34,38]. In PCA, the original data is simply transformed into another domain or space, such that the transformed data, usually called scores, are orthogonal [36]. Additionally, PCA also enables better visualisation of the transformed data, making it easier to identify clusters of materials with similar properties based on the recorded spectra. Principle component analysis was performed for each sensor height and light intensity level combination, such that the principal components (PC) could explain at least 99% of the variance between the different powdered food samples. As the number of classes or materials for the FG was relatively high, it was decided to divide the materials into five classes based on either the origin or the main allergen they contain. The first class was gluten-containing materials, and included flours made from wheat, barley, rye, spelt, in addition to oatmeal and wheat gluten. The second class included non-gluten flours, which were flours made from rice, buckwheat, coconut, corn, and tapioca. The third class included animal-based proteins, which were egg white, egg yolk, whole egg, and milk powder. The forth class contained nuts (almond, peanut butter powder, and peanut flour). The fifth class contained caster sugar, icing sugar, and table salt. In the case of the SG, no subgrouping was performed and there were 18 classes, with each class representing one type of spice.
Classification of samples was conducted using several classification machine learning methods, including Linear Discriminant Analysis (LDA), K-nearest neighbour (KNN), SIMCA, PLSDA, and feed forward artificial neural networks (ANN). It should be noted that the classification task was implemented on both the FG (5 classes) and SG (18 classes). Linear discriminant analysis depends on establishing a linear classification threshold and each new object is assigned a class after comparing its discriminant score to the threshold [34]. For the SIMCA method, each class is described by features extracted via PCA such that the PCs for each class are selected irrespective of the PCs for other classes. This enables the optimal feature selection for each sample [34]. The PLSDA technique depends on applying partial least squares regression (PLSR) and assigning the sample to the correct group based on the values of the predicted dependents (y) values, such that the correct class has a predicted value of 1 or −1 [35]. An ANN is a nonlinear, supervised classification technique [34]. The ANN implemented in this study comprised three layers, an input layer that had all pre-processed spectral data, a hidden layer with 50 neurons, and an output layer that contained the sample classes. KNN is a nonlinear classifier that is based on assigning a point to a class whose Euclidean distance to the unknown point is the minimum [34]. The Euclidean distance was chosen in this study to be 4. For all models, data were divided into a training set (75%) and a test set (25%). To increase the robustness of the deduced classification models, a four-fold cross validation technique was applied only on the training set of data and the optimal classification model obtained was the one that produced the minimum classification error. This optimal model was then used with the test data set. Cross validation is a common technique used when the number of predictors is larger than the number of objects. Thus, the parameters of the obtained models were such that the number of PLS and PCA components were optimised [34].

Effect of Sensor Height on Spectral Signature of Samples
The relative reflectance spectra for different food materials at different sensor heights and light intensities showed a similar trend (Figures 2 and 3). Figure 2a-j shows the relative reflectance spectra for the FG materials, where each sub figure illustrates the relative reflectance at all sensor height levels and one light intensity (either 90% or 30%). Due to the relatively large number of tested materials, only five FG materials are shown, with each one representing one sample from the aforementioned classes. A consistent reduction in the relative reflection was observed around 1780 nm for all samples, especially when the sensor was close to the sample (Levels 1 and 2). This reduction was related to the absorption of water, which was present in all samples [39]. This reduction was not clear for sensor levels beyond H2 (4.5 cm) due to the large level of noise. Additionally, it was found that the intensity of the acquired spectra decreased as either the light intensity reduced or the distance between the sensor and the sample increased.
The SG samples in general showed similar absorption peaks to the FG samples ( Figure 3). Relative reflectance spectra are only shown for five materials from the SG in Figure 3 (chili flakes, cinnamon, cumin, and garlic granules). It was found that light intensity drastically affected the amplitude of the acquired spectra, as the relative reflectance spectra at light intensity of 30% was around 20% of the value at the light intensity of 90%. Assuming the air in between the sensor and the sample surface was a uniform gas, then based on Beer-Lambert's Law, the intensity of the transmitted light decreased exponentially with the path length through the absorbing material.    The SG samples in general showed similar absorption peaks to the FG samples ( Figure 3). Relative reflectance spectra are only shown for five materials from the SG in Figure 3 (chili flakes, cinnamon, cumin, and garlic granules). It was found that light intensity drastically affected the amplitude of the acquired spectra, as the relative reflectance spectra at light intensity of 30% was around 20% of the value at the light intensity of 90%. Assuming the air in between the sensor and the sample surface was a uniform gas, then based on Beer-Lambert's Law, the intensity of the transmitted light decreased exponentially with the path length through the absorbing material.

Effect of Light Intensity on Spectral Signature of Samples
The effect of light intensity on relative reflectance at two height levels, H1 (3 cm) and H6 (10.5 cm), is shown in Figures 4 and 5 for FG and SG, respectively. For consistency, only the spectra for the same powdered food samples as Figures 2 and 3 are shown. It is clear that the moisture absorption peak around 1780 nm had almost disappeared at height H6 for all samples as a result of the more dispersed signals in the surrounding air. However, at heights closer to the sensor, i.e., H1, it was observed that the absorption peaks could still be clearly distinguished for all light intensities. In general, the relative reflectance was proportional to the light intensity for most materials, which follows Beer-Lambert's law.
Generally, the higher the light intensity the more reflected light acquired from samples. Thus, using the sensor at further distances from the sample surface will mostly not help identify some chemical constituents, especially if only low concentrations of the compounds are present.
The effect of light intensity on relative reflectance at two height levels, H1 (3 cm) and H6 (10.5 cm), is shown in Figures 4 and 5 for FG and SG, respectively. For consistency, only the spectra for the same powdered food samples as Figures 2 and 3 are shown. It is clear that the moisture absorption peak around 1780 nm had almost disappeared at height H6 for all samples as a result of the more dispersed signals in the surrounding air. However, at heights closer to the sensor, i.e., H1, it was observed that the absorption peaks could still be clearly distinguished for all light intensities. In general, the relative reflectance was proportional to the light intensity for most materials, which follows Beer-Lambert's law. Generally, the higher the light intensity the more reflected light acquired from samples. Thus, using the sensor at further distances from the sample surface will mostly not help identify some chemical constituents, especially if only low concentrations of the compounds are present.

Effect of Sensor Height and Light Intensity on the Spectra Principle Components
The scatter plots for the PC scores for the five groups of flours samples that illustrated the best and worst class separation are displayed in Figure 6a,b, respectively. For PCA plots it is desirable to have clear separation between different classes so they can be distinguished from each other more easily. The best separation was achieved for height level H4 (7.5 cm) and light intensity 90%, whereas the worst separation was found to be for height level H6 (10.5 cm) and light intensity 30%. It is noted that some materials are well separated in the PCA figures such as icing sugar, caster sugar, and nuts, as a result of the distinguishable composition of such materials. Most nuts contain fatty acids, such as saturated fatty acids, poly saturated fatty acids, and monosaturated fatty acids [40], while the caster or icing sugars solely contain sucrose [41]. However, it was difficult to separate some materials from others at all heights, especially with a higher sensor level or lower light intensity. Moreover, with the highest sensor position from the sample (H6 = 10.5 cm) and the lowest light intensity (30%), the PCs were condensed and represented a situation where identifying the different classes of materials would be challenging. It was found that height level H4 (7.5 cm) along with a light intensity of 90% yielded the best separation of different classes based on the PCA scatter plot (Figure 6a). These results show that different groups were well separated from others, except for almond flour, which was clustered amongst the gluten-containing flours. Two gluten-free flours were also located within the gluten-containing flours cluster. As gluten-free flours mainly contain mixtures of flours of rice, potato, tapioca, maize, and buckwheat, one or more of these individual flours contains common compounds with gluten-containing flours, such as amino acids including phenylalanine, histidine, isoleucine, and leucine [42]. It was found that the effect of light intensity was less important than the sensor height to obtain more separated groups of materials. In a study conducted by Ghosh et al. [24], where several cereals, legumes, nuts, and oilseeds were measured using an NIR sensor (896-1686 nm), the scatter plot of PCs yielded a similar trend, where cereals were well separated from nuts. It is worth stating that with the best combination of height and light intensity shown in Figure 6a, it was possible to separate most allergen-containing foods from foods which did not include allergens, except for the two gluten-free flours discussed above. Thus, it is necessary to also depend upon results obtained from classification models which produce more conclusive results and can be used to quantify the effects of experimental parameters, such as sensor height and light intensity.
For the SG, the PCA scatter plots at height levels H4 (7.5 cm) and H6 (10.5 cm), along with light intensities of 90% and 30%, respectively, are presented in Figure 7a,b. The separation of spice samples showed visibly better results than that for flour groups considering the relatively high number of classes (18 for the SG). The light intensity affected the separation more than the sensor height, as can be seen at height levels H1 and H6. Non-separated classes were associated more with light intensities of 30%, with worse results when combining the furthest sensor height with the lowest light intensity. It was clear that samples like mixed herbs, basil, and oregano were clustered together for most height levels, as mixed herbs already contain basil, oregano, and thyme. Celery and mustard were the only materials specified as allergens SG, and both were successfully separated from other samples at the height of 7.5 cm and light intensity of 90%. According to the UK national health service [43], Echinacea triggers allergic reactions for children under the age of 12. In this study, Echinacea was clustered with cinnamon, which illustrates the need to either improve the experimental method (more replicates or wider wavelength range) or combine the PCA results with classification models.

Effect of Sensor Height, Light Intensity, and Pre-Processing Technique on Classification Prediction Accuracy
Classification results for the test data sets of the flour group for all possibilities of sensor height and light intensity combination are shown in Table 3 using KNN, PLSDA, SIMCA, and ANN classification methods. Linear discriminative analysis classification results had much lower classifciation performance and are not displayed here. The clasification prediction accuracies shown are stated as values of minimummaximum and vary dependeing on the pre-processing technique applied to the spectra. In general, a consistent dependency was found for classification prediction accuracy on sensor height. The further the sensor was from the sample, the more a considerable decrease in classification performance was observed. Classification prediction accuracy also decreased with the lower light intensities at the same sensor height, especially when the sensor was futher from the samples, which matches the results illustrated with the PCA

Effect of Sensor Height, Light Intensity, and Pre-Processing Technique on Classification Prediction Accuracy
Classification results for the test data sets of the flour group for all possibilities of sensor height and light intensity combination are shown in Table 3 using KNN, PLSDA, SIMCA, and ANN classification methods. Linear discriminative analysis classification results had much lower classifciation performance and are not displayed here. The clasification prediction accuracies shown are stated as values of minimum-maximum and vary dependeing on the pre-processing technique applied to the spectra. In general, a consistent dependency was found for classification prediction accuracy on sensor height. The further the sensor was from the sample, the more a considerable decrease in classification performance was observed. Classification prediction accuracy also decreased with the lower light intensities at the same sensor height, especially when the sensor was futher from the samples, which matches the results illustrated with the PCA scatter plots (Figures 6 and 7).
In addition, KNN generally had the most accurate classification performance over all heights and light intensities studied, and was affected the least by the different pre-processing technqiues. Classification prediction accuracies of up to 100% were obtained for most light intensities for the lowest sensor height (H1 = 3 cm). Furthermore, classification models developed using the KNN method had higher classification performance than other modelling methods for all sensor height and light intensity combinations. The reason KNN resulted in the best classification perormance can be attributed to its simplicity and suitability for multiclass problems [34]. The effect of pre-processing method was more obvious on further sensor heights, where the classification accuracy range was larger. Classification results from the ANNs had fairly consistent values for classification prediction accuracies, although they had the lowest accuracy of all models presented in Table 3. This may be a result of the slightly lower number of samples per class compared with the number of features [44]. In a study conducted by Nawi et al. [44], several pre-processing techniques were used on three different datasets before applying an ANN, and the classification accuracies changed by only a small amount (94.32-99.87%). PLSDA and SIMCA showed similar classification results that decreased to less than 10% prediction accuracy with sensor heights greater than 3 cm. In addition, the different pre-processing methods had significant effects, at all light intensity and height combinations. Classification results obtained in this study are comparable to those by previous studies. Badaró et al. [28] achieved model prediction accuracies of up to 100% for detecting the presence of different dietary fibres added to semolina flour using NIR. Ziegler et al. [45] illustrated that NIR can be used for differetiating between different flours, such as bread, durum, and spelt, with prediction accuracies up to 100%. Althougth the classification results presented in this current work are positive and higlight the potential of the techniques, further work is still required to investigate the effects of other parameters, such as sample particle size and moisture content and enviromental conditions (e.g., temeprature).  The classification prediction accuracy results for spices at different sensor heights and light intensity combinations are shown in Table 4. Results from the ANN models are not shown, as they had poor classification performance. This was possibly due to the relatively large number of classes compared with the number of samples, thus not enabling the effective tuning of network parameters (weights) required to achieve effective models [38]. Linear discriminative analysis and KNN methods yielded the highest classification prediction accuracies. Again, the classification performance decreased with increased sensor height, especially for the measurements at lower light intensities. For sensor heights H1 and H2 (3 cm and 4.5 cm), samples in general were classified correctly (100%), irrespective of light intensity. Starting from sensor height 6 cm, classification prediction accuracies decreased with a consistent reduction with lower light intensities. The classification prediction accuracies were found to be similar when comparing the results from the FG and the SG. Classification results obtained for spices were similar to those available in other published work using spectroscopic measurements. Hu et al. [46] used FT-MIR (4000-40,000 cm −1 ) to assess the adulteration of black pepper by sorghum or Sichuan pepper, with reported classification prediction accuracies between 98-100%. Anibal et al. [47] used a UV/Vis (260-600 nm) to detect Sudan dyes in turmeric, curry, mild paprika, and hot paprika, with resulting classification prediction accuracies up to 99.3%. It is worth stating that PLSDA was generally more affected by the pre-processing techniques than LDA or KNN, and showed considerably reduced classification prediction accuracy when the sensor height was greater than 3 cm. PLSDA mainly depends on using PLS to assign each sample to a class, and thus suffers from the negative effect of small sample sizes when trying to obtain the optimal latent variables. Additionally, PLSDA tends to produce lower prediction accuracy in multiclass problems than binary classification [34]. An example of the confusion matrix obtained from the classification analysis is shown in Table 5. It shows that all groups were classified correctly, except the gluten-containing group, which had 1 sample out of 12 classified as gluten-free. The results illustrate the need for a larger number of samples to improve the classification prediction accuracies. Due to the large number of classes for the spice group, the confusion matrix is not shown.

94%
The pre-processing methods applied to the recorded NIR spectra in this study played a significant role in the performance of the classification models. Amongst all applied pre-processing techniques, SNV and MSC contributed to better classification performance for both FG and SG. Other methods showed slightly lower prediction performance, including Savitzky-Golay, mean centring, and robust auto centring. However, first and second derivatives resulted in the lowest classification prediction accuracy values for the FG and SG. Only the values of classification prediction accuracy for SNV and the second derivative are shown in Table 6, as these methods had the most extreme effects on the classification results. For the models deduced from either technique, it is clear that the prediction accuracy generally decreased the further the sensor was from the sample or with a lower light intensity at the same height level, which agrees with the general results obtained from Tables 3 and 4. Additionally, it is shown that the data treated with SNV were less affected by the sensor height than those treated with the second derivative. SNV provides a sample-by-sample treatment such that the data will have a zero mean and unit variance, which provides a baseline correction to overcome the problem of having artefacts or noise in the spectra due to any surrounding or uncontrolled conditions produced during measurements [34,35,48]. A possible reason for such low performance for derivative smoothing is the fact that although differentiation might lead to noise removal by minimizing narrow spikes, it might also increase noise that has not presented in the actual spectra [34]. Table 6. Maximum classification prediction accuracies for flour samples using KNN and spice samples using Linear Discriminant Analysis (LDA) at different sensor heights and light intensities using SNV and second derivative pre-processing on the recorded NIR sprectra.

Conclusions
This work investigated the use of NIR spectroscopy and machine learning models to identify different powdered food materials which naturally contain allergens, such as gluten. The sensor utilised was small, low cost and had a low power requirement, making it suitable for use within production environments. This work specifically focussed on some crucial measurement parameters which ought to be considered when using NIR in real-world environments. These were the height between the sensor and the sample, the light intensity of the sensor, and the pre-processing techniques applied to the recorded spectra. Measurements were made on a range of different powdered food samples, which were split into two main groups, flours and spices. The work showed that using features extracted from the recorded spectra with classification machine learning methods was a suitable approach to identify materials containing allergens, with classification prediction accuracy as high as 100%. It was found that placing the sensor further than 7.5 cm away and using an illumination power less than 70% resulted in poor classification performance. This highlights that users should always identify the most suitable measurement conditions when using these sensors in the laboratory or factory. The study also concluded that amongst the different machine learning methods utilised, KNN and LDA yielded a stable performance of classification prediction accuracy under the studied conditions. Moreover, pre-processing techniques had a significant effect on the classification performance. Methods such as SNV, MSC, and Savitzky-Golay consistently resulted in a more than 100% increase in classification prediction accuracy compared with methods like first and second derivatives. Measurements from the NIR sensor under the optimal combination of sensor height and light intensity resulted in 100% classification prediction accuracy using KNN and LDA methods. However, future work needs to be conducted to cover additional factors that would affect the measured spectra and classification performance. Such factors include the effect of particle size, moisture content, and compositional variations in materials, which may vary between brands. Additionally, to develop measurement systems suitable for real-time data collection within production environments, the ability to perform measurements on moving materials is desirable. Finally, work should be performed to determine the capability of the technique to identify powdered materials adulterated with small quantities of other materials.