# IoT Implementation of Kalman Filter to Improve Accuracy of Air Quality Monitoring and Prediction
## 4 Results
### Kalman Filter Algorithm Implementation
#### 4.2.3 Setting Parameters  
In the Kalman filter-based air quality prediction model proposed in this paper, it is assumed that all kinds of pollutants do not change state every hour and there are no control variables, so in Equation (5), \(F_{k}\) can be set as an identity matrix and the value of \(B_{k}u_{k}\) is zero. In Equation (6), \(R_{k}\) is the covariance matrix of the measurement error of sensors, and \(z_{k}\) is an observation matrix consisting of observations of various pollutant concentrations by 100 samples in first 10 min/h (100 samples are required because, after several experiments, the algorithm can achieve optimal convergence and steady state after 100 iterations). In Equation (6), the process noise error \(Q_{k}\) is usually difficult to predict as we typically do not have the ability to directly observe the process we are estimating. Statistically speaking, excellent filter performance can be obtained by tuning the filter parameter \(Q_{k}\). The tuning is usually performed off-line, frequently with the help of another (distinct) Kalman Filter in a process generally referred to as system identification. Then, under the condition that \(Q_{k}\) is actually constant, both the estimation error covariance \(P_{ikk}\) and the Kalman gain \(K_{k}\) will stabilize quickly and then remain constant [49]. In this paper, assuming that \(Q_{k}\) is a constant value \(Q\), then we can determine the value of \(Q\) for each pollutant. The smaller the \(Q\) value, the higher the trust in the prediction model. If \(Q\) is 0, it means that only the prediction model is trusted. And as \(Q\) decreases, the system will converge more easily, but when \(Q\) is reduced to a certain extent, continuing to decrease may cause the system to start diverging. Conversely, a larger \(Q\) value indicates a lower degree of trust in the predictive model, and accordingly,the degree of trust in the measured value is increased. If \(Q\) tends to infinity, it means that only the measured value is trusted. This paper uses the grid search method to tune the \(Q\), the specific process is as follows. (1) Select data. The Panyu Middle School (PMS) in Guangzhou, Guangdong Province, China, is an official monitoring site, so we assume that the data published on this site is true and accurate [50]. we select the air pollutant concentration data released by the monitoring site from 0:00 on 12 February 2019 to 23:00 on 15 February 2019 as the actual value (a total of 96 data points in four days). Each data point in the data set corresponds to the concentration value of each type of pollutant at each hour. At the same time and place, by using the sensor network of our system to monitor, the observation data of various pollutant concentrations during this period is obtained, which is used as the measured value (similarly, a total of 96 data points in four days). (2) Define search interval. When \(Q=0\), since the proportion of the observations is very small, the value of the posterior estimate \(x_{k}\) is basically not updated during the iterative process, and the trend tends to be gentle. Taking the Kalman Filter to predict the CO concentration as an example. Figure 6a shows the iterative convergence process at \(Q=0\) (a total of 96 iterations). In the figure, the blue line is the output of the KF algorithm in each iteration (a posterior estimate \(x_{k}\)), the plus sign is the observed value with errors by the sensors, and the green line is the data of the monitoring site, indicating the true value. When \(Q=1\), the model trusts the observations at this time, and the update of the posterior estimate \(x_{k}\) is more affected by the observations. Therefore, the trend will basically coincide with the measured values, as shown in Figure 6b. (3) Calculate the predicted value. \(Q\) performs 1000 searches in the range of \((0,1)\). In each search process, for each \(Q\), the KF algorithm performs 96 iterative updates in conjunction with 96 measurements.