# IoT Implementation of Kalman Filter to Improve Accuracy of Air Quality Monitoring and Prediction
## 3 Materials and Methods
### Kalman Filter Algorithm  
The traditional statistical method-based prediction model [43] has the advantage of high interpretability and low computational cost. Its prediction principle is based on linearly fitting historical data. Therefore, the predicted result can have higher precision when the trend of change is not severe. However, it is no longer applicable when the concentration of various air pollutants is not a stable sequence. For example, the concentration of pollutants, such as PM2.5, PM10, and SO, will suddenly increase due to the increase in vehicle exhaust emissions when traffic is at a peak in the morning and evening [44]. Therefore, models such as SMA, EWMA, and ARIMA [29; 30; 31; 32] cannot effectively predict these change points, but these data have higher predictive value (directly corresponding to measures). In the application scenario of AQ prediction based on IoT devices, the prediction model is limited by the storage capacity and computing power of the device itself. In order to achieve higher prediction accuracy, many ML models not only require a large amount of historical data for training (storage problem), but also have a high time complexity throughout the training process (calculation problem) [45]. For example, the decision tree model [21; 35] can improve the prediction accuracy via the increase in the number of training samples and the depth of the tree, however, the time complexity \(O(N\times M\times D)\) is also multiplied (\(N\) is the number of samples, \(M\) is the vector dimension, and \(D\) is the tree depth). The ANN [23; 36; 37] also has the similar problem. Therefore, although the ML model  
Figure 2: The architecture of air quality monitoring and prediction system. has higher prediction accuracy, it cannot meet the requirements of the edge computing node for the lightweight model. In order to solve the shortcomings of the above models, and in the case of ensuring the prediction accuracy, the space complexity (storage) and time complexity (calculation) of the model are simplified as much as possible, making it adaptable to the application scenario of edge computing. This paper proposes an AQ prediction model based on the Kalman Filter (KF) algorithm. The KF is an efficient autoregressive filter model (recursive filter model) [46]. It occupies very little memory and only needs to retain data for one state on the system, rather than a long span of historical data. The actual measured data are used to correct the prediction results, which can reflect the objective results in the most realistic way. The operation speed of the KF is very fast, so it is very suitable for solving real-time problems and applying to the edge computing of IoT. The core idea of the KF is to use a set of state-space expression equations to represent a dynamic system, and to predict the system state \(\hat{x}_{kjk-1}\) (called prior estimate) at the next moment \(k\) according to the optimal estimate (prediction) \(\hat{x}_{k-1}\) of the system state at time \(k-1\). At the same time, the system state at time \(k\) is observed, and the observed value \(z_{k}\) is obtained. Due to the observation error, \(z_{k}\) and \(\hat{x}_{kjk-1}\) deviate from the truly accurate system state, so the predicted value \(\hat{x}_{kjk-1}\) needs to be corrected by the observed value \(z_{k}\). Then the optimal estimate (prediction) \(\hat{x}_{k}\) of the system state at time \(k\) is obtained. The KF algorithm is different from the general timing prediction method [47]. Firstly, there is no need to assume that the error term satisfies the normal distribution. Secondly, it can estimate the system state based on a set of incomplete observations (some time points missing in time series data) or that contain noise (measurement error). Furthermore, compared with the model based on single observations, the KF considers the joint distribution of observations according to time series data at different times and estimates the unknown factors that may affect the system. Therefore, the prediction of the KF will be more accurate.