# Wi-Fi Fingerprint-Based Indoor Localization Method via Standard Particle Swarm Optimization
## 3 System Overview
### SPSO Algorithm for Localization
```
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
44:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
54:
55:
55:
56:
57:
58:
59:
60:
59:
61:
62:
63:
64:
64:
65:
65:
66:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
88:
89:
90:
910:
91:
92:
93:
94:
95:
96:
97:
98:
99:
99:
99:
99:
99:
10:
99:
11:
11:
12:
13:
14:
15:
16:
17:
18:
19:
19:10:
19:
11:
19:20:
121:
14:
19:22
15:
19:30:
122:
16:
19:31:

19:32:
17:
18:
19:42:

19:43:
19:44:
19:45:

19:55:
19:56:

19:57:

19:58:

19:69:

10:59:

10:59:
10:59:

11:60:
17:
18:
19:61:

19:70:

19:71:5: Calculate the Euclidean distance and corresponding similarity of \(\text{Fin}_{query}\) and \(\text{Fin}_{train\,i}\) according to Equations (12) and (14)
6: Calculate the cosine distance and corresponding similarity of \(\text{Fin}_{query}\) and \(\text{Fin}_{train\,i}\) according to Equations (13) and (15)
7: **End for**
8: Sort \(sim_{\text{Euc}}\) in descending order, return the \(\text{index}_{\text{Euc}}\);
9: Sort \(sim_{\text{cos}}\) in descending order, return the \(\text{index}_{\text{cos}}\);
10: **SPSO Initialization**
11: Set constants \(N_{ps}\) = 100, \(t\) = 0, \(T_{max}\) = 10,000, \(c_{1}\) = \(c_{2}\) = 1.5, \(\omega_{init}\) = 0.4, \(\omega_{end}\) = 0.9;
12: Set boundary of the particle positions and velocities
13: **For** each particle
14: Randomly initialize the particle positions \(\mathbf{x}_{j}^{0}\);
15: Randomly initialize the particle velocities \(\mathbf{v}_{i}^{0}\);
16: Evaluate the \(i\)th particle according to Equations (16)-(18) and set \(\mathbf{pbest}_{i}^{0}=\mathbf{x}_{i}^{0}\)
17: **End for**
18: \(\mathbf{gbest}^{0}=\arg\min[f(\mathbf{pbest}_{i}^{0})]\)
19: **Particle swarm update process**
20: **While \(t<=T_{max}\)**
21: \(t=t+1,\omega^{t}=\omega_{init}+(\omega_{end}-\omega_{init})(T_{\text{max}}-t )/T_{\text{max}}\)
22: **For** each particle
23: **Update \(\mathbf{v}_{i}^{t}\) and \(\mathbf{x}_{i}^{t}\) according to Equations (2) and (3)**
24: **Evaluate the \(i\)th particle according to Equations (16)-(18)**
25: **If \(f(\mathbf{x}_{i}^{t})<f(\mathbf{pbest}_{i}^{t-1})\)**
26: \(\mathbf{pbest}_{i}^{t}=\mathbf{x}_{i}^{t}\)**
27: **Else**
28: \(\mathbf{pbest}_{i}^{t}=\mathbf{pbest}_{i}^{t-1}\)
29: **End if**
30: **End for**
31: **If \(\min[f(\mathbf{pbest}_{i}^{t})]<f(\mathbf{gbest}^{t-1})\)**
32: \(\mathbf{gbest}^{t}=\arg\min[f(\mathbf{pbest}_{i}^{t})]\)**
33: **Else**
34: \(\mathbf{gbest}^{t}=\mathbf{gbest}^{t-1}\)**
35: **End if**
36: **End while**
37: **Return gbest**
38: **Location estimation**
39: \((x_{p},y_{p})=(x,y)\) of \(\mathbf{gbest}\)
40: **Error evaluation**

## 4 Experiments and Analysis

### Experimental Setup

The experiment was conducted in a 324 m\({}^{2}\) one-floor building, with length of 27 m and width of 12 m. There are two offices, a conference room, an open office area containing five desks and several chairs, and an exhibition area containing six large robots, with relatively high but unintentional and random personnel flow. The spatial layout and indoor localization environment are shown in Figures 2 and 3a, which include 10 APs deployed on the perimeter at a height of 1.2 m above the floor level. Notwithstanding, these APs are also shown, although their coordinates are not necessarily a priority condition. In addition, the data was collected by a mobile robot (product name: TurtleBot 3) with a RTL8188 CUS Wi-Fi Module, as Figure 3b shows. To reflect the actual scenario, the data collection was performed in the presence of obstacles. The localization area was divided into multiple grids of width 1.0 m. In the offline phase, 187 points were set as the RPs. At each RP, the \(RSS\) from each AP was uniquely identified by MAC address and measured 30 times (at 1 min intervals). The IEEE 802.11n with 2.4 GHz band, 40 MHz channel bandwidth and MCS 0, were used during this time. Thus, 56,100 units of \(RSS\) data were processed.