# IoT Implementation of Kalman Filter to Improve Accuracy of Air Quality Monitoring and Prediction
## 5 Discussion
### Predictive Trend Comparison  
This section presents the predictive trend of four algorithms KF, SMA, EWMA and ARIMA via comparing the predicted values with the published values by the official monitoring site. As shown in Figure 11, the predicted values of four algorithms and real values at different moments reveal whether the four algorithms can accurately reflect the characteristics of the data. It is a 24 h prediction trend for the concentration of six pollutants SO\({}_{2}\), NO\({}_{2}\), CO, O\({}_{3}\), PM2.5 and PM10 on 16 February 2019, in PMS. The black solid line represents the data collected in PMS, as a benchmark for comparison. The dashed line in four different colors is the predicted value according to four different algorithms, including SMA, EWMA, ARIMA and KF. As illustrated in Figure 11, compared with the data of the official monitoring site, the prediction results of the KF for six kinds of air pollutant concentrations are the closest to the real data. The KF shows the best prediction effect reflecting the characteristics of real data at different times. In detail, the blue dotted line reflects the trend of SMA algorithm for various pollutants. On the whole, SMA is only effective when dealing with horizontal historical data, such as the time from 2:00  
Figure 11: 24 h prediction trend of various air pollutant concentrations by Kalman Filter, SMA, EWMA and ARIMA. (**a**) SO\({}_{2}\); (**b**) NO\({}_{2}\); (**c**) CO; (**d**) O\({}_{3}\); (**e**) PM2.5; (**f**) PM10. to 5:00 in Figure 11c and the time from 2:00 to 23:00 in Figure 11e,f. However, data with trend or step characteristics, such as Figure 11b,d, the moving average does not always reflect its trend well, showing obvious hysteresis. Since it is an average value, the predicted value always stays at the past level, and it cannot be expected to cause higher or lower fluctuations in the future. However, fluctuations in the concentration of various air pollutants are not always horizontal, so the results of SMA predictions will produce very large deviations. The orange dotted line reflects the predicted trend of the EWMA algorithm among various pollutants. As can be seen from the figure, the EWMA algorithm is very effective for the processing of horizontal historical data. Although the prediction of trend or step data has been greatly improved compared with SMA, there is still significant hysteresis. The results of each pollutant concentration prediction are still far from the data released by the official monitoring site. The green dotted line reflects the predicted trend of the ARIMA algorithm for various pollutants. Overall, compared with SMA and EWMA, the ARIMA can better reflect the trend of data, whether for horizontal or step data. However, ARIMA requires that the time series data be stable or to be stable after being differentiated, so in a short period of time, ARIMA can get a good prediction effect. When the data suddenly fluctuates, as illustrated in Figure 11a, the concentration of SO2 suddenly rises at 6:00 and 8:00, ARIMA still shows obvious hysteresis, resulting in large errors in the prediction results. The red dotted line reflects the prediction trend of the KF for various pollutants. It can be seen from the figures that even though the system uses inexpensive sensors with low precision, the correction of the KF algorithm can make the prediction results of various pollutant concentrations very close to the data of the official monitoring site. The KF can well reflect the trend of the data both in step-type data (Figure 11b) and horizontal data (Figure 11e), showing no obvious hysteresis or very large volatility. Based on the above analysis and comparison results, the KF is very suitable for the air quality monitoring and prediction system proposed in this paper. After the hyperparameter is determined, the KF does not need to train the historical data. Therefore, the calculation amount of the model is so small during each iteration and update process that it can be completed quickly on the RPi.