*4.4. Algorithm Parameter Setting*

We empirically optimize the parameters of each algorithm and show the implementation details in this section.

THR is used for walk detection. We heuristically threshold the magnitude variance of the sensor data. The optimal threshold value is chosen by exhaustively searching within the range of minimum and maximum variance.

FSM is used for step counting. It has four thresholds that determine the state sequence of the input data stream [35]. We conduct a grid search for the four thresholds used in the model and choose the thresholds that have the best accuracy.

PTM is used for step counting. It includes a series of models such as low-pass filter, differentiator, squaring and integrator, which could find the large sloping part in the sensor data. One local maximum of PTM output means one step. We have the best accuracy when the filter order is 200, the cut-off frequency is 50 Hz and integrator window size is 0.5 s.

STFT is used for both walk detection and step counting. Walk detection by STFT in Barralon et al. [50] places the sensor on the chest, while we do not make this restriction. We first compute FFT coefficients in each frame, then detect walk by setting a threshold on the frequency energy in [0.66 Hz, 1.66 Hz], which outperforms the energy ratio method in [50].

For step counting, we also abandon the placement on the waist, as in [28], and place the sensor at various positions. We add a differentiator module after the energy-based filter that accounts for 20% of the full energy to achieve better performance.

DWT is used for both walk detection and step counting. The decomposition is eight levels by the dh10 wavelet. Instead of comparing the ratio of detail power coefficients, we first smooth the whole energy samples of seven and eight levels' details of each sample and then detect the walk by considering the mean energy of each window.

For step counting, we reconstruct the signal by 6, 7, 8 and 2, 3 levels' details, respectively, as two methods, which are denoted as DWT and DWT2, respectively, in the following.

SVM is used for walk detection, and the Gaussian radial basis function (RBF) kernel performs best in our experiments.

k-NN is used for walk detection, and *k* = 5 performs best in our dataset.

Besides the parameters that we mentioned here, there are also many parameters of each algorithm to be decided such as filter order, filter coefficients, differentiator coefficients, etc. In different contexts, we empirically choose these values to achieve the best accuracy.

## *4.5. Counting*

Walking is a repetitive activity, which makes the sensor data cyclic. We could see features such as large slope changes, local maxima, local minima, peaks, valleys and mean-crossing events in the magnitude of each gait cycle, where some features could be used to identify and count step cycles. In fact, we expect to detect only one representative event in a gait cycle. However, those features are generated by physical movements, which is intrinsically not stable or uniform distributed in each gait cycle, might emerge more than once in one gait cycle and be sensitive to contexts. For example, more than one large slope change, local maxima, peaks, etc., are observed in one gait cycle because of the context impacts, as well as noises in the physical movement. Therefore, although the algorithm could detect all those features in each gait cycle, step counting is still not accurate since two or more large slope changes might exist in the signal of one gait cycle. In fact, each SC algorithm could detect one feature, for instance each peak in the output of PTM means a large slope change exists in the corresponding position of the input signal. Therefore, simple features, which might emerge more than once in one gait cycle, are inclined to have high false positives; while complex features, which might not appear in a gait cycle, tend to have low true positives. Thus, we need more approaches to balance false positive rate and true positive rate and evaluate the algorithms.

In an algorithmic view, each feature in the gait cycle has one peak in the output, so there might be multiple peaks in the output of each gait cycle. In order to remove the peaks that are generated by noises, we use not only a threshold, but also the minimum peak distance, minimum peak height and minimum peak prominence. These conditions could remove most false positives without the loss of true positives and achieve a better trade off.
