# A Novel Device-Free Counting Method Based on Channel Status Information
## 3 Crowd Counting Based on CSI
### Crowd Counting Algorithm  
Our work aims to achieve crowd counting indoors (i.e., laboratory, corridor and office) settings at the Xi'an University of Technology, that is, the relationship between the number of moving people and CSI amplitude and phase variances is found, respectively. In PEM, presented in [14], the percentage of non-zero Element, can demonstrate the crowd size. PEM can adaptively reflect the relationship between CSI and the people number. In other words, it can intuitively represent different numbers of people. Neverthless, the FCC system [14] only considers amplitude information and directly uses the raw amplitude, i.e., the CSI phase information is ignored. Therefore, we propose to further improve the FCC system. In particular, it proposes to mitigate the environmental noise by wavelet denoising, extract CSI amplitude and phase covariance matrix as feature matrices and convert them into two-dimensional matrix, and expand the two-dimensional matrix using an algorithm and calculate the non-zero elements percentage of dilatation matrix. The idea of the expansion matrix method is that when a point expands to a certain size in the form of a circle, it will coincide with other points, and the size of these coincidence areas is contrary to the change of CSI strength. It should be noted that, our proposed method is with small amount of calculations and the data amount is less, leading to a counting time in the magnitude order of milliseconds. In Algorithm 1, \(C[i][j]\) represents the processed two-dimensional matrix \((S\times P)\), with and being the number of subcarriers and packets, respectively. \(C_{min}\) and \(C_{max}\) are the maximum and minimum value of covariance matrix, respectively, and \(D\) is the dilatation coefficient and \(q\) is percentage.  
Figure 5: Phase before and after linear transformation. (**a**) random raw phase measurements; (**b**) phase after linear transformation.  
The aforementioned crowd counting approach can be listed as follows:  
* We adopt wavelet transforms to remove the random noise, and then extract both the CSI amplitude and phase covariance matrix as the feature vector.
* All elements in the CSI amplitude or phase covariance matrix \(M_{0}\) are initialized to \"0\", and each CSI value \(C[i][j]\) is converted into integer \(k\) by \(k=\lceil\frac{C[i][j]-C_{min}}{C_{max}-C_{min}}\cdot(R-1)\rceil\). Then, the elements in row \(k\) and column \(j\) of \(M_{0}\) is set to be \"1\".
* The elements around \(D\) are set to \"1\", which is called matrix expansion. The size of the expansion is related to the \(D\). After dilation, the \(M_{0}\) is transformed into matrix \(M\). The matrix \(M\) is occupied by more \"1\", and usually comes along with the CSI changes drastically.
* The number of \"1\" in the matrix \(M\) is counted, and the percentage of non-zero elements in the matrix \(M\) of each subcarrier is calculated by \(q=q/(P\times S)\). This percentage is a guideline that the relationship between the CSI and the number of moving people.  
```
1:Sample Data \(([H_{1},H_{2},\cdots,H_{k}],k\in(1,30))\), Matrix Resolution \((R)\), Dilatation Coefficient \((D)\), Number of Subcarrier \((S)\), Number of Packets \((P)\), Covariance Matrix \((C(i,j))\), Maximum Value of Covariance \((C_{max})\), Minimum Value of Covariance \((C_{min})\), Expansion Matrix \((M)\)
2:Percentage of Element \((q)\)
3:the covariance matrix is extracted from wavelet transformed data
4:for\(i=1\) to S do
5: the integer \(k\) is calculated
6: the matrix \(M\) is dilated // the element in row \(k\) and column \(j\) is set to be \"1\"
7:for\(u=-D\) to \(D\)do
8:for\(v=-D\) to \(D\)do
9: the matrix \(M\) is dilated // the element in a radius of \(D\) is set to be \"1\"
10:endfor
11:endfor
12:for\(l=1\) to \(P\)do
13:for\(h=1\) to S do
14:\(M=M\) \((1,h)\) // the percentage of the matrix \(M\) of each subcarrier
15:\(q=q/(P\times S)\) // the percentage is calculated
16:endfor
17:endfor
```  
**Algorithm 1** Crowd Counting based on Channel State Information