# A CSI-Based Multi-Environment Human Activity Recognition Framework
## 2 Materials and Methods
### Data Pre-Processing
#### 2.4.1 Initial Preprocessing Stage  
In this stage, we apply four techniques to reduce the noise and outliers in the CSI signals. These techniques are described below:  
1. Outliers Removal: This technique is used to remove any value that can be considered as an outlier. Outlier values can occur for several reasons: the noise present in the environment incorrect hardware reading, and the sudden change in the environment are possible reasons for such outliers. To exclude these outliers, the Hampel filter [42] was used. The Hampel filter utilizes a sliding window that scans the CSI signals and removes any reading that is more than three times the standard deviation (\(3\sigma\)) by replacing that value with the mean of the values within the sliding window. An example of a processed signal using the Hampel filter is shown in Figure 8.
2. Converting to Stationary signal: A stationary signal is a term used to describe a signal with constant or slowly changing statistical properties as discussed in [43]. In this work, the signals we are dealing with are all non-stationary signals [44]. The term non-stationary signal refers to a signal with statistical values (mean, median, variance) that are changing over time. To transform the non-stationary signal into a stationary signal, the differencing procedure can be applied by subtracting each value of the time-series signal from the one before it as follows [45]: \[y_{new}=y_{t}-y_{t-1}\] (5) where \(y_{t}\) represents a reading at time \(t\), \(y_{t-1}\) represents the previous data reading, and \(y_{new}\) represents the new reading that will replace \(y_{t}\). To determine if this step is necessary or not, we performed the Augmented Dickey-Fuller (ADF) test [46]. The ADF test determines if the signal at hand is stationary or not by testing the null hypothesis (\(\phi=0\)), which refers to a non-stationary signal. To determine if the signal is stationary, we look for a \(p\)-value less than or equal to 0.05. An example of the performed ADF test is provided in the \"Before Segmentation Processing\" Section.
3. Data Reduction: Each receiving antenna records 30 CSI-subcarriers in each of the communication channels. The use of all 30 subcarriers will create a strain on the system. To reduce the number of signals to be analyzed and at the same time to retain the valuable information in these signals, we use the Principal Component Analysis (PCA) [47], which is considered a dimensionality reduction method. To determine the number of principal components to be selected, the following two metrics were considered: (1) The data variance in the selected principal components; (2) The errors  
Figure 8: The effect of using the Hampel filter.  
in the segmentation process. A detailed description of each metrics is provided in the \"Before Segmentation Processing\" section.
* Signal Smoothing: For each of the principal components we selected in the previous stage, we need to reduce the noise in that signal through a smoothing technique. One of the most known techniques to remove such noise, especially in the area of image processing, is known as Gaussian filtering [48]. The basic approach to smooth a signal is by defining a Gaussian window with the point we want to smooth in the middle of the window. To generate the smoothed point, each actual data point has a related Gaussian weight (the summation for the weights must be equal to 1). These Gaussian weights are then multiplied by the actual data values, and the summation of the multiplication results is assumed to be the new value after smoothing.