DOI: 10.5061/dryad.hhmgqnkrh
title: Comparative analysis of RNN versus IIR digital filtering to optimize resilience to dynamic perturbations in pH sensing for vertical farming

description: Vertical Farming (VF) refers to systems of agriculture where crops are
 grown in trays stacked vertically by exposing them to artificial light and
 using sensing technology to improve product quality and yield. In this
 work, we propose an advanced filtering scheme based on Recurrent Neural
 Networks (RNNs) and Deep Learning to enable efficient control strategies
 for VF applications.  We demonstrate that the best RNN model
 incorporates five neuron layers, with the first and second containing
 ninety Long Short-Term Memory neurons.  The third layer
 implements one Gated Recurrent Units neuron.  The fourth segment
 incorporates one RNN network, while the output layer is designed by using
 a single neuron exhibiting a rectified linear activation
 function.  By utilizing this RNN digital filter, we introduce two
 variations: (1) A scaled RNN model to tune the filter to the signal of
 interest, and (2) A moving average filter to eliminate harmonic
 oscillations of the output waveforms. The RNN models are contrasted with
 conventional digital Butterworth, Chebyshev I, Chebyshev II, and Elliptic
 Infinite Impulse Response (IIR) configurations.  The RNN digital
 filtering schemes avoid introducing unwanted oscillations, which makes
 them more suitable for VF than their IIR counterparts.  Finally,
 by utilizing the advanced features of scaling of the RNN model, we
 demonstrate that the RNN digital filter can be pH selective, as opposed to
 conventional IIR filters.
description: # Comparative Analysis of RNN Versus IIR Digital Filtering to Optimize
 Resilience to Dynamic Perturbations in PH Sensing for Vertical Farming
 [https://doi.org/10.5061/dryad.hhmgqnkrh](https://doi.org/10.5061/dryad.hhmgqnkrh) ## Description of the data and file structure The algorithms used for the comparative analysis of an RNN versus IIR digital filters are contained in two compressed files in .rar format. Each file includes the datasets used, which consist of pH measurements for both ideal and real scenarios, corresponding to the absence and presence of mechanical disturbances, respectively. The files also contain the algorithms used for their training, analysis and application. ### Files and variables #### RAR File 1: RNN.rar ##### **Description**: This .rar file contains the results of the Recurrent Neural Network (RNN) for filtering perturbations in pH measurements. Inside the file, you’ll find the datasets used, the Python source code for training the RNN, notebooks with result analysis, and graphs showing the network's performance. **.csv files with training data**: The CSV files provided in the folder correspond to data collected from various pH experiments under different conditions. The naming convention follows the structure: Perturbation Data (with disturbances): * `"1_pH4_BL_Golpes_ON.csv"` * `"2_pH4_BL_Agitador_ON.csv"` * `"3_pH4_Mult_Golpes_ON.csv"` * `"4_pH4_Mult_Agitador_ON.csv"` * `"5_pH7_BL_Golpes_ON.csv"` * `"6_pH7_BL_Agitador_ON.csv"` * `"7_pH7_Mult_Golpes_ON.csv"` * `"8_pH7_Mult_Agitador_ON.csv"` * `"9_pH10_BL_Golpes_ON.csv"` * `"10_pH10_BL_Agitador_ON.csv"` * `"11_pH10_Mult_Golpes_ON.csv"` * `"12_pH10_Mult_Agitador_ON.csv"` * `"13_pHCoke_BL_Agitador_ON.csv"` - `"14_pH7-pH4_BL_Agitador_ON.csv"` * `"15_pH7-pH4_BL_Golpes_ON.csv"` No Perturbation Data (without disturbances): * `"1_pH4_BL_Golpes_OFF.csv"` * `"2_pH4_BL_Agitador_OFF.csv"` * `"3_pH4_Mult_Golpes_OFF.csv"` * `"4_pH4_Mult_Agitador_OFF.csv"` * `"5_pH7_BL_Golpes_OFF.csv"` * `"6_pH7_BL_Agitador_OFF.csv"` * `"7_pH7_Mult_Golpes_OFF.csv"` * `"8_pH7_Mult_Agitador_OFF.csv"` * `"9_pH10_BL_Golpes_OFF.csv"` * `"10_pH10_BL_Agitador_OFF.csv"` * `"11_pH10_Mult_Golpes_OFF.csv"` * `"12_pH10_Mult_Agitador_OFF.csv"` * `"13_pHCoke_BL_Agitador_OFF.csv"` * `"14_pH7-pH4_BL_Agitador_OFF.csv"` * `"15_pH7-pH4_BL_Golpes_OFF.csv"` Each file name is composed of five parts: *Number*: The first digit in the file name represents the index of the experiment (1, 2, 3, etc.). It is a sequential identifier. *pH Level*: The next part, such as pH4, pH7, or pH10, indicates the pH level used in the experiment. "pH4-pH7" refers to alternating measurements between these two pH levels. Measuring instrument: * *BL*: Refers to measurements taken by a microcontroller. * *Mult*: Refers to measurements taken by a multimeter. Perturbation Type: * *Golpes* (Spanish for "Hits"): Physical impacts were applied to the system. * *Agitador* (Spanish for "Agitator"): Mechanical agitation was applied to the system. State: * *ON*: Indicates the perturbation was active during the experiment. * *OFF*: Indicates the perturbation was not active during the experiment. Each CSV file contains three columns with data from the experiments, structured as follows: 1. *Temporal sample*: Instead of exact timestamps, temporal samples are recorded. 2. *Voltage*: The voltage measured in the system, which is correlated with the behavior of the pH sensor. 3. *pH*: The pH level measured at each point in time. **"testtFINAL.csv"**: During the training phase, different neural network configurations were explored. This file contains the results of each tested model. Below is a description of the columns: * *run*: Identifier of the run. * *operation*: Type of operation. * *started*: Start date. * *Time*: Duration of the training. * *label*: Information about the trained model. * *l1*: Number of neurons in the first layer. * *l2*: Number of neurons in the second layer. * *l3*: Number of neurons in the third layer. * *l4*: Number of neurons in the fourth layer. * *samples_prev*: Total number of samples used for training. * *step*: Iteration number at which the model stopped improving. * *epoch_cosine_similarity, epoch_loss, epoch_lr, epoch_mae, epoch_mape, epoch_mse*: Metrics calculated at the end of each epoch to monitor the model's performance during training. * *evaluation_cosine_similarity_vs_iterations, evaluation_loss_vs_iterations, evaluation_mae_vs_iterations, evaluation_mape_vs_iterations, evaluation_mse_vs_iterations*: Metrics for evaluating the model on the validation or test set after each iteration. * *loss_test, loss_train, loss_val*: Metrics representing the final loss after training. **.py Files**:\ `"train.py"`: Python algorithm for training. **.ipynb Files**:\ `"resultsbestmMSE2.ipynb"`: Jupyter notebook for tests and validations. `"resultsbestmMSE.ipynb"`: Notebook for comparing metrics from the training process **.h5 Files**:\ `"best_model_(90, 90, 1, 1).h5"`: The model with the best metrics resulting from the training. The name indicates that the model contains 4 layers, with 90 units in the first two layers and 1 unit in the last two layers. * *Backend*: The model was trained using TensorFlow. * Keras Version: The model was trained using Keras version **2.10.0**. * *Model Configuration* : * The model architecture is defined as a **Sequential model** with the following layers: * **InputLayer**: Takes a sequence input with a shape of `(20, 1)`. * **LSTM (2 layers)**: Both LSTM layers have 90 units, `tanh` activation, and recurrent `sigmoid` activation. * **GRU**: Has 1 unit with `tanh` and `sigmoid` activations. * **SimpleRNN**: Contains 1 unit and `tanh` activation. * **Dense**: Contains 1 unit with `relu` activation. * *Training Configuration*: * **Loss Function**: `mean_squared_error (MSE)` * **Monitored Metrics**: * `MSE`: Mean Squared Error. * `MAE`: Mean Absolute Error. * `MAPE`: Mean Absolute Percentage Error. * `Cosine Similarity`: Cosine similarity between predictions and actual values. * **Optimizer**: `Adam` with: * Learning rate: `0.0093` * Tuning parameters: `beta_1 = 0.9`, `beta_2 = 0.999`, `epsilon = 1e-07`. #### RAR File 2: IIR\_Digital\_Filtering.rar **Description**: This .rar file contains a MATLAB implementation of IIR digital filters (Infinite Impulse Response Filter), along with text files containing pH measurements. The goal is to apply the IIR filters to the pH signals to analyze the filtered response. * **.txt Files**: `"SignalWithoutPerturbations.txt"`,`"SignalWithPerturbation-Agitator.txt"`,`"SignalWithPerturbations-Hits.txt"`Datasets with pH signals at various levels with and without perturbations. * **.m Files**: `"iir_filters.m"`: MATLAB algorithm for filtering pH signals.