# IoT Implementation of Kalman Filter to Improve Accuracy of Air Quality Monitoring and Prediction
## 5 Discussion
### Predictive Ability Analysis  
Although Section 5.1 proves that the KF algorithm can improve the accuracy of the sensors, it does not explain the advantages of the KF in predicting performance. Since most ML-based prediction models are limited by the storage power (requiring a large amount of historical data for training to obtain better prediction results) and computing power (model training and prediction processes are computationally intensive tasks, requiring high computational components like CPU) of edge computing nodes, they are not suitable for use in IoT scenarios [45]. Therefore, this paper designs the comparison experiment between KF algorithm and three other commonly used time series prediction algorithms that are based on statistical methods, including SMA (Simple Moving Average), EWMA (Exponentially Weighted Moving Average) and ARIMA (Autoregressive Integrated Moving Average). SMA, EWMA, and ARIMA need to use historical data for training. In order to have a comparative judgment criterion, this paper selects the data of various air pollutant concentrations per hour from 15 to 16 February of 2019, in PMS, which is used as the training set for model and as the comparison data for the algorithm prediction results. (1) Kalman Filter Prediction. First of all, determine the hyperparameters of the KF algorithm as described in Section 4.2.3. Then, in the actual prediction process, the observation data used by the KF in the correction state is the hourly monitoring data of the air pollutant concentration in PMS (from 0:00 to 23:00 on 16 February 2019). The specific process of each prediction is as follows: (1) during each prediction period, the sensors of the system sample 100 times of the concentration of each air pollutant in the first ten minutes; (2) the KF algorithm is iteratively updated based on the sampling data; (3) the results of the iterative convergence are used as the predicted values of each pollutant concentration in this period. (2) SMA Prediction  
SMA is a method for predicting the average value for a certain period in the future. The method calculates the arithmetic mean of several historical data in the past and uses the arithmetic mean as the predicted value for the later period [51]. SMA can be expressed as:  
\[F_{t}=\left(A_{t-1}+A_{t-2}+A_{t-3}+\ldots+A_{t-n}\right)/n \tag{11}\]  
where \(F_{t}\) is the predicted value for the next period, and \(n\) is the number of periods of the moving average, generally between 3 and 200. \(A_{t-1}\) is the actual value of the previous period, and \(A_{t-2}\), \(A_{t-3}\), \(A_{t-n}\) are the actual values of the first two periods, the first three periods and the first \(n\) periods, respectively. The number of \(n\) is determined by the experimental results of multiple cross-validation [52] on the training set before the SMA prediction. It is found that the prediction effect is best when \(n=3\). Therefore, in the actual prediction process, the model input data of the first period (predicted value at 0:00 on the 16 February 2019) is the three-hour data from the monitoring site, which is from 21:00 to 23:00 on 15 February 2019. The model input data of the second period (predicted value at 1:00 on the 16 February 2019) is the data from 22:00 to 23:00 on 15 February 2019 and 0:00 on 16 February 2019. By analogy, the predicted values of 24 h on the 16 February 2019 are obtained. (3) EWMA Prediction  
EWMA is an improvement to SMA and is a common sequence processing method [53]. This applies a non-uniform weighting to time series data so that a lot of data can be used, but recent data is weighted more heavily. As the name suggests, weights are based upon the exponential function. Formulated as follows:  
\[EWMA_{t}=\lambda Y_{t}+(1-\lambda)EWMA_{t-1}(t=1,2,\ldots,n) \tag{12}\]  
where \(EWMA_{t}\) is the estimated value at time \(t\), \(Y_{t}\) is the observation at time \(t\), \(n\) is the number of observations to be monitored including \(EWMA_{0}\), and \(0<\lambda\leq 1\) is a constant that determines the depth of memory of the EWMA.