# THz Data Analysis and Self-Organizing Map (SOM) for the Quality Assessment of Hazelnuts
## 4 Results
### Statistical Data Analysis Methods  
As a tested in the analysis of the hazelnut condition, a simple algorithm was implemented to distinguish between 'healthy' and 'rotten' or defective hazelnuts. The available data consist of measurements taken with the THz instrumentation described in paragraph 1. The experimental dataset consists of 9 points per sample given by measurements at frequencies between 36 and 40 GHz. The samples are those described in paragraph 2, which are appropriately classified ex post. The algorithm, implemented using the Python 3 language, was developed and then verified on the available dataset. To gain an understanding and enable a comparison with data analysis using a neural network, as will be seen in the next paragraph, details of the steps taken to achieve the final selection result are provided here. The aim is to compare not only the results achieved but also the 'effort' required to achieve them. In this approach, the observation of experimental data is fundamental in determining the identifying parameters of the hazelnut's 'condition'. Therefore, it starts with the representation of the collected experimental data. The raw trend of the values obtained in the 'transmission' configuration (volts) acquired in the specified frequency range (36-40 GHz) does not seem, as initially hypothesized, to allow for the definition of a threshold value to discriminate between samples. This is also due to the measurement configuration and the variable sizes of the samples. In Figure 4, the trend of the measured voltage value in transmission for various samples as a function of frequency is shown. The curve with the highest values is related to the 'petri-dish', i.e., the measurement without the sample. The curves associated with various samples are represented with two different colors: red for samples classified ex-post as 'bad' and blue for 'good' ones. Although theoretically, it may seem that one can easily distinguish based on the measured intensity, the complexity and variability of hazelnut geometries, combined with the measurement configuration, make this differentiation impossible to achieve 'as is'. However, if we average the signals obtained at various frequencies and represent hazelnuts as 'good' and 'bad' using the same colors as in Figure 5, it appears that average transmission values can be determined to allow discrimination between different hazelnuts. Figure 4: Transmission values expressed in millivolts over frequency (in GHz) of the dataset A—50 hazelnut samples. A color for each sample, including the reference in red (upper curve). It seems possible to establish threshold values below which hazelnuts can be considered 'good' and above which they can be considered 'bad'. Assuming the primary goal is to eliminate the bad hazelnuts that can affect the quality of an entire batch, attention will be focused on detecting bad hazelnuts to remove them from the general set of hazelnuts. The analysis will be based on the percentage of hazelnuts classified as 'bad' compared to the number of hazelnuts that were actually verified to be 'bad' and the number of 'good' hazelnuts that would be'sacrificed' under these criteria--in other words, the percentage of good hazelnuts that would be classified as 'bad'. The full procedure developed for hazelnut classification consists of two steps: one based on the average value at the measured frequencies (A), Figure 5, and a second step based on the verification of the presence of a peak (maximum) at the frequency of 36.46 GHz in the trends over frequency. In the measurement configuration used, a difference between 'good' and 'bad' is indeed highlighted at this frequency, particularly observing that 'good' hazelnuts have a maximum at this frequency. The double condition imposed on the data appears to have an excellent percentage in hazelnut selection. Let us analyze the results obtained on a sample of 212 hazelnuts, including 140 without defects and 72 with some form of defect not visible from the outside (rotten, shriveled, or empty).