# Battery-Free Pork Freshness Estimation Based on Colorimetric Sensors and Machine Learning
## 4 RF Harvesting Experiment
### Kalman Filter for RF Harvesting Evaluation
There was a slight increase in the validation data's accuracy compared to the training data. The loss was also the lowest at 0.0347 in the 113 th epoch, indicating a progressively similar performance. This model has little variation in accuracy and loss for each epoch, and the difference between the results learned from the validation data and test data for the loss is relatively small. ### Long Short-Term Memory Model

LSTM is a type of RNN, a structure connected between internal units to preserve information over time, which consists of functions of sigmoid activation and gate cells [38]. As shown in Figure 15, a gate cell is a function that allows certain information to be read, written, and saved, and it can receive input values between 0 and 1. Information is blocked when the input value is close to 0, and all the information is delivered when the input value is close to 1. Additionally, to prevent problems with vanishing or exploding gradients, the forget gate multiplies the output value by either 0 or 1. The sigmoid function plays a crucial role in coordinating information at the gate by determining how much of the previous state value \(\left(C^{t-1}\right)\) should be disregarded or updated for new cell memory computations when the forget gate (\(\Gamma_{F}\)) and the update gate (\(\Gamma_{u}\)) are used together. Figure 14: Training process of the Vanilla MLP model. Figure 13: Structure of the Vanilla MLP model. At time t of the LSTM unit, the memory cell (C) stores \(C^{t}\) as follows:

\[C^{t}=\left(\Gamma_{u}\times C^{\sim t}\right)+\left(\Gamma_{F}\times C^{t-1}\right) \tag{11}\]

The current memory value is calculated using the previous time step's content value \(C^{\sim t}\) and the memory value \(C^{t-1}\). The forgetting gate is an activation function applied to the vector dot product and bias. The model is characterized by sequential data that are suitable for processing due to these features. The system in this study can be seen as having time continuity due to changes in the state of pork over time, and LSTM can be efficiently operated. Figure 16 shows the structure of the LSTM model used in this study. It is a four-layer LSTM model that includes an input layer, a hidden layer, and a fully connected layer. The activation function was set to ReLU, and the SoftMax function was employed for classification normalization for the network's output. The dropout rate is set at 0.3. Figure 17 shows the LSTM model's learning process. In the 141 st epoch, the highest accuracy value was 0.9814. A relatively stable performance appeared after 78 epochs. The loss was also lowest at 0.0314 in the 146 th epoch. In the validation data, the loss decreased slightly. Figure 16: Structure of the LSTM model. Figure 10:0 Internal structure of the LSTM model. ### 1D-CNN Model

CNN is primarily used for classifying image features, but it is also widely used in the processing of biological signals such as ECG and EMG [39]. In this study, CNN was applied to pork measurement data, so the model was modified for 1D-CNN to apply to a sequence of 1D data. The 1D convolution layer generates a single spatial or time-lapse 1D layer and a kernel that becomes a convolution, producing a tensor of output. The 1D-CNN model employed is shown in Figure 18 and consists of a six-layer structure. The input layer consists of 64 filters, kernel size 2, ReLU as the activation function, and a convolutional 1D Neural network. The hidden layer also consists of 32 filters, kernel size 2, and ReLU. Then, Max-Pooling is applied with a pooling size of 1, followed by a flattened layer. A hidden layer consists of 64-32 nodes and a ReLU activation function. The output layer uses the SoftMax function, and the optimizer used is Adam. The learning rate is set to 0.01, the dropout to 0.5, and the weight decay to 0.0001. Grid search is used to optimize the model layers and each hyperparameter [40; 41; 42]. Table 1 presents the results of applying the Grid Search algorithm for optimizing the parameters of the 1D-CNN model.