# TwSense: Highly Robust Through-the-Wall Human Detection Method Based on COTS Wi-Fi Device
## 4 System Architecture
### Motion Segmentation and Feature Extraction  
We classified the representative motion states when someone is present into four types, as shown in Figure 6: walking, sitting down, stooping, and getting up. They correspond to the Doppler frequency shifts caused by each action. From the figure, we can see that the Doppler shift changes with the action, and the Doppler shift caused by different actions are different, and the different Doppler effects caused by different actions simultaneously are the factors that distinguish the presence of the human body whether or not. Doppler images need to be extracted with corresponding features to improve the final classification results. In this paper, first, we used the K-Means algorithm to segment the action subject in the image that causes the Doppler shift, and the pixels of RGB images were divided into three classes by calculating the Euclidean distance. The results showed that the K-Means algorithm segmented the action occurring part accurately. The feature extraction part used the Histogram of Oriented Gradient (HOG) feature. The HOG feature obtained the local feature of the detected object by detecting the gradient and edge direction information of the local object. Compared with other feature extraction methods, HOG can better capture the local shape information, and can maintain good invariance and stability to the geometric and optical changes of Doppler frequency shift images, so different distances or similar content of the same action can be extracted by using the HOG feature when testing with different people. Therefore, this paper extracted the HOG feature of a Doppler frequency shift image. \begin{table}
\begin{tabular}{c c} \hline \hline
**Building Materials** & **5 GHz** \\ \hline Glass wall 1.18 inches & 3 dB \\ Wooden Door 1.75 inches & 6 dB \\ Gypsum wall 11 inches & 13 dB \\ Concrete wall 15 inches & 15 dB \\ \hline \hline \end{tabular}
\end{table} 
Table 1: RF attenuation of different materials at 5 GHZ. Figure 5: Through-the-wall Wi-Fi signal conversion to Doppler shift map: (**a**) Raw CSI; (**b**) Optimal subcarriers extracted by OR-PCA; (**c**) Doppler shift map. K-means clustering was used to convert the Doppler image into a grayscale image and, at the same time, reduced the local shadow of the image, reduced the impact caused by the attenuation of the signal in the process of penetrating the wall so that during feature extraction, the image features were more apparent, which is necessary for gamma space normalization. The standardized Gamma compression equation is:  
\[I(x,y)=I(x,y)^{Gamma} \tag{12}\]  
where \(x,y\) are the horizontal and vertical coordinates of the pixel, respectively. This method can well reduce the influence of image feature extraction. Then, the horizontal and vertical gradients of each pixel were calculated in the image. Operations can effectively record the look of the graph based on color and luminance changes. The gradient size and gradient direction for each pixel were calculated, more clearly outlining the action signals in the graphics:  
\[G(x,y)=\sqrt{G_{x}^{2}(x,y)+G_{y}^{2}(x,y)} \tag{13}\]  
\[\xi(x,y)=\tan^{-1}\frac{G_{y}(x,y)}{G_{x}(x,y)} \tag{14}\]  
where \(G_{x}(x,y)\) and \(G_{y}(x,y)\) are the horizontal and vertical gradients of the image pixels, respectively, and \(G(x,y)\) and \(\xi(x,y)\) are the gradient magnitude and direction, respectively. Then, the picture was divided into several cells of the same size. It consisted of tiny unit pixels. Gradient information for 6 \(\times\) 6 pixels in each cell was collected using a histogram of 9 cells. All pixels in the cell were multiplied by the gradient magnitude to project the gradient direction; their projections were then summed to form a histogram of cell gradient directions.