# An IoT-Based COVID-19 Prevention and Control System for Enclosed Spaces
## 3 Materials and Methods
### Indoor Positioning  
In an enclosed place, the relationship between a location and corresponding RSSI vector is built by selecting reference points and collecting RSSI values from iBeacon nodes at each reference point. \(R=\left[r_{1},r_{2},\ r_{3}\ldots r_{p}\right]^{T}\) denotes a series of RSSI values; \(r_{i}\) represents the RSSI value from node \(i\). At each point, a receiver (usually a mobile phone) gets RSSI values steadily in a period from iBeacon nodes. The vector \(r=\left[r_{1},r_{2},\ r_{3}\ldots r_{n}\right]^{T}\) is a vector \begin{table}
\begin{tabular}{c c c c c} \hline \hline  & **A** & **B** & **C** & **D** \\ \hline
12:00 & In & Not Arrived & Not Arrived & Not Arrived \\
12:01 & Left & In & Not Arrived & Not Arrived \\
12:02 & Left & In & Waiting & Not Arrived \\
12:03 & Left & In & Waiting & Not Arrived \\
12:04 & Left & In & Waiting & Waiting \\
12:05 & Left & Left & Waiting (\(r=1.35\)) & In (\(r=1.59\)) \\ \hline \hline \end{tabular}
\end{table} 
Table 3: Process of the example in Table 2.  
of RSSI values from an iBeacon node via repeated measurements. The simplest way is to average the values in the vector \(r\) (in Equation (9)). \[RSSI=\frac{1}{m}\sum_{i=1}^{m}r_{i} \tag{9}\]  
Nevertheless, this simple method is unable to adapt to the real situation, especially when the indoor environment is complex and volatile. Kalman filtering (KF), a linear, minimum variance estimation method, is required to be used; the KF algorithm consists of a gain calculation loop (filter gain, estimation error, and prediction error) and a filter calculation loop (state prediction and state estimation) [53; 54]. The covariance of the observation noise \(R\) is calculated by averaging the variance of the RSSI at each reference point. The system process noise is \(Q\), and the state transition is \(T\) (the RSSI value is expected to be stable). The observation is \(H\). The first estimated error covariance of the point is shown in Equation (10). \[P_{1}=\frac{1}{N}\sum_{i=1}^{N}\left(Z_{1}^{l}-E\Big{[}Z^{l}\Big{]}\right)^{2} \tag{10}\]  
\(Z_{l}^{1}\) is the first sample RSSI of reference point I. \(E[Z^{l}]\) is the expected RSSI value of the corresponding point. N is the number of elements of the vector \(r\). The prediction error covariance of the \(t\)-th sample RSSI is shown in Equation (11). \[P_{t,t-1}^{l}=P_{t-1}^{l}+Q \tag{11}\]  
The filter gain of the \(t\)-th sample RSSI is denoted by \(J_{t}^{l}\) (Equation (12)). \[J_{t}^{l}=P_{t,t-1}^{l}\Big{[}P_{t,t-1}^{l}+R\Big{]}^{-1} \tag{12}\]  
The estimated error covariance of the \(t\)-th sample RSSI is confirmed by Equation (13) (\(U\) is the unit vector). \[P_{t-1}^{l}=\Big{[}U-J_{t}^{l}\Big{]}P_{t,t-1}^{l}\Big{[}U-J_{t}^{l}\Big{]}^{T }+JRJ_{t}^{IT} \tag{13}\]  
The predicted value of the \(t\)-th RSSI is calculated via Equation (14). \[X_{t,t-1}^{l}=TX_{t-1}^{l} \tag{14}\]  
In order to gain the predicted value of the \(t\)-th sample of RSSI, we put the filter gain into the filter calculation (Equation (15)). \[X_{t}^{l}=X_{t,t-1}^{l}+J_{t}^{l}\Big{[}Z_{t}^{l}-X_{t,t-1}^{l}\Big{]} \tag{15}\]  
Through the KF algorithm, the error of RSSI measurement can be reduced so that we can gain more accurate RSSI values. For the fingerprinting database, a more reliable offline fingerprinting database is established. Figure 2 shows the process of building a fingerprint database (offline stage) and real-time positioning (online stage). The distance between a received RSSI vector and fingerprint vector \(R_{i}\) needs to be calculated. The corresponding location for \(R_{i}\) is \(P_{i}(x_{i},y_{i})\). Firstly, we calculate the first \(k\) largest distances and record the corresponding \(P_{i}\), then we generate an ascending distance vector \(D=(d_{1},d_{2},\ d_{3}\ldots d_{n})\). The method of calculation is shown below Equations (16)-(18). \[x_{predict}=\frac{\sum_{i=1}^{k}(w_{i}*x_{i})}{\sum_{i=1}^{k}\frac{1}{d_{i}}} \tag{16}\]Table 2.0 Table 2.1  
The implementation of an indoor positioning system requires some experiments.