**3. Smartphone-Based Unconstrained Step Detection Fusing Variable Sliding Window and Adaptive Threshold**

In order to address the problem of the low accuracy of step detection algorithms in a complex unconstrained state, an unconstrained step detection algorithm for smartphones is proposed in this paper. In this algorithm, the minimum peak filtered by the sliding window is used as the adaptive threshold. The algorithm is a step detection algorithm of a variable sliding window, which ensures the close connection between the windows. At the same time, the cooperative time threshold solves the problem that the initial peak and the final peak are difficult to distinguish the authenticity in the fixed sliding window. The flow chart of the algorithm is illustrated in Figure 6, and the steps of the algorithm are as following:

**Figure 6.** Flow chart of the unconstrained step detection algorithm.

The first step is data preprocessing. The FIR low-pass filter is used to denoise the original overall acceleration signal.

The second step is to identify the motion state and gain the fixed threshold for the third step. The motion state is identified by FFT. The initial peak threshold and time threshold are matched according to different motion states.

The third step is to dynamically update the peak threshold and eliminate the pseudopeak. It is found that the waveform filtered by a sliding window is smaller than that filtered by a FIR low-pass filter. Based on these characteristics, the minimum peak value detected by sliding window filtering in the window is used in this paper as an adaptive threshold, and the adaptive threshold is used to replace the fixed threshold for step detection based on the waveform after the FIR low-pass filter. This peak threshold dynamic updating algorithm is proposed in detail in Section 3.1.

The fourth step is the variable sliding window cooperative time threshold to eliminate the pseudo-peak. Since the fixed sliding window cuts off the connection between the adjacent windows, the discrimination of the initial peak and the final peak of each window is easily missed. To solve this problem, the variable sliding window cooperative time threshold pseudo-peak elimination method is proposed to eliminate the pseudo-peak, and the structure and process of this method will be introduced in detail in Section 3.2.

The fifth step is to calculate the steps for the current window.

#### *3.1. Dynamically Update the Peak Threshold*

When affected by height, weight, health status, walking habits and other factors, it is difficult to adapt to different users and different unconstrained states only by a fixed threshold. It is found that the waveform filtered by a sliding window is smaller than that filtered by the FIR low-pass filter. To dynamically update the peak threshold, this paper takes the minimum peak detected after a sliding window filter as the adaptive threshold based on this feature. If the adaptive threshold is greater than the empirical threshold, the empirical threshold is used as the adaptive threshold.

Figure 7 is a group of experiments running on flat ground. In the experiment, adaptive peak threshold and fixed peak threshold (11.6 m/s2) are used to eliminate pseudo-peak and count steps, respectively. The experimenter ran 29 steps, and the step number results of adaptive peak threshold and fixed peak threshold were 29 steps and 40 steps, respectively.

**Figure 7.** Pseudo-peak elimination by adaptive threshold in running state.

In Figure 7, the arrow marks the pseudo-peak, and the blue horizontal line is the fixed threshold line. The black dots are adaptive thresholds obtained by a sliding window filter. It can be seen that the fixed threshold is difficult to eliminate pseudo-peaks marked by arrows, whereas adaptive thresholds can eliminate them.
