Algorithm Design for Accurate Steps Counting Based on Smartphone Sensors for Indoor Applications

Article history: Received: 09 October, 2020 Accepted: 18 November, 2020 Online: 24 November, 2020 This paper aims to design an accurate and robust algorithm for counting the steps based on the smartphone's accelerometer for indoor applications. Different daily activities have been considered in the experimental scenarios, including normal walking with various smartphone positions and running activities. The detection process's accuracy is ensured by setting an appropriate segregation approach and defining a fixed threshold for each experiment. The algorithm generates a new envelope signal that mimics the collected steps signal without the vibrations and noise elements to avoid miscounting the exact steps. The followed approach results have been compared with the pedometer applications on the android platform and HUAWEI Watch GT-731. The proposed algorithm showed improved detection accuracy in contrast to the other literature approaches. The obtained accuracy was around 99% for the standard walking scenario and approximately 97% for the running activity scenario.


Introduction
Lately, the step count has been extensively used in various applications, such as health monitoring, auxiliary positioning, and gaming. Earlier, the Pedestrian Dead Reckoning (PDR) was used as a localization method based on advanced built-in sensors [1] that exist these days in Smartphones. These sensors found in the smartphones include accelerometers, proximity sensors, gyroscopes, magnetometers, and Global Positioning System. The accuracy of the steps count is one of the challenges of the PDR. Therefore, several studies have been addressed, increasing the accuracy of steps count while walking using the smartphone's accelerometer [2][3][4].
One of the aspects has been considered in the literature: smartphone placement's impact on measurement accuracy. The smartphone's position and placement might cause jitter during the human motion, which leads to counting false steps [5]. Also, remaining still, watching videos, playing games, and many other activities can lead to a wrong step count [6]. In [7], it was recommended to place the smartphone at the user the fingertips with the view screen point upwards while using the phone. If the smartphone is placed in the jacket or trouser pocket, it is recommended to put the top of the smartphone upright. One of the challenges of this approach is getting rid of the noisy signals accompanying the detected steps. Therefore, a discrete Kalman filter was used in the literature to minimize the smartphone accelerometer's noise during human motion [8]. The Footsteps are usually calculated using an algorithm in the smartphone on the android platform, which can count precisely by dividing the measurement processes into two phases. The first phase includes collecting the linear acceleration and the gravity values from the accelerometer of the smartphone. These values are then used to derive the horizontal components and identify possible start points of regular periodical fluctuations. The second phase includes finding the correlation coefficients to determine if the collected sensing measurements exhibit similar tendencies, and accordingly, it finds the steps count. The results showed higher measurement accuracies if the user holds the phone statically [9]. Although several approaches have been proposed and used for step counting, most of these approaches are not validated with robust methods. Therefore, this work aims to design a robust algorithm for step count purposes with high accuracy. The proposed algorithm will distinguish between false steps and real steps to reduce the measurement error and enhance its credibility. This paper is structured as follows. In section II, a concise overview of related work. In section III, the proposed approach to count the steps is presented. The obtained results are discussed in section IV, and the paper ends with conclusions.

Related Work
Several algorithms have been proposed to enhance the step count based on the smartphone's sensors in-state of the art. In [6,10], a window peak detection algorithm has been proposed based on the smartphone's accelerometer. The algorithm could afford an average accuracy of 95%, considering the different ways that a ASTESJ ISSN: 2415-6698 smartphone can be carried. The algorithm's parameters have been optimized and applied to measured data from three different volunteers holding the smartphone at different positions. A new algorithm based on the smartphone sensor has been proposed in [11] to estimate the traveled distance by walking accurately. The algorithm counts the number of peaks in the measured signal by the smartphone's accelerometer. The next step is to detect the steplength, which varies from one step to another. Many adaptive algorithms have been designed to count the footsteps based on LSM (Lifestyle modification). These approaches rely on measuring the movement by a 3-axis accelerometer.
The proposed designs can enhance the step detection accuracy using step amplitude with accuracies, which can reach up to 99%. In [12], two adaptive algorithms have been proposed to count human steps using only the gyroscope. Accordingly, the Fast Fourier Transform (FFT) was applied to the measured data to obtain real-time walking frequency. The proposed algorithms' average accuracy ranged from 95% to 97%, considering different walking speeds. Further, the step counting based on the smartphone's accelerometer has been developed in Indoor Positioning System as proposed in [5]. The approach relies on pattern recognition for step detection and counting. Different scenarios for the smartphone placement and the number of steps higher than one hundred steps have been considered in the validation stage. The result showed high accuracy regardless of the smartphone position. In many step counting approaches, the noninvasive option depends on utilizing the accelerometer to determine the arm movement like a seizure sufferer. In these approaches, the algorithm depends on employing low-power, embedded microcontroller devices in real-time, and they are not intrusive to the patient's life. Therefore, they are less likely to become non-compliant with monitoring [13]. These approaches are applied in wireless biomedical networks that attempt to monitor patients in a completely non-invasive, non-intrusive manner for a specific condition. Nowadays, the Global Positioning System (GPS) is employed to detect and count the steps outdoor. The GPS showed low accuracy in indoor scenarios due to the indoor equipment's electromagnetic interference and the building structures [14]. Therefore, the PDR and smartphone's sensors have been integrated to detect and count the steps accurately in indoor scenarios as in [15].
The power consumption of steps counting algorithms is one of the research topics, especially in smartphones with small battery capacity. In [16], the accelerometer Tap Interrupt algorithm was used to reduce power consumption. The accuracy and measured power consumption at the system level have been compared with a periodic sensor-reading algorithm. The tap interrupt approach presented a lifetime of the battery that is 175 % longer than that of a non-gyroscope 30 ms polling method. The battery life can be extended to 863 % by putting both the processor and the gyroscope in a sleep mode during most operating time. The average power consumption may be reduced by reducing the wake-up frequency from the sleep state and shortening the processing time at each wake-up. Recently, machine learning algorithms have been introduced for step length estimation based on the smartphone's sensors. Utilizing these tools aims to improve the steps detection, counting, and step length estimation accuracy.
In [1], the neural network is implemented in a multi-mode intelligent recognition approach based on the smartphone's sensors. The empirical results presented a maximum positioning error lower than 1% of the total path distance. In [17], an adaptive algorithm has been proposed to enhance the steps counting accuracy in indoor positioning services. The algorithm aims to solve the limitations by introducing four mains parameters. These parameters include the minimal peak distance, minimal peak prominence, thresholding, and vibration elimination. The algorithm presented an improved average accuracy of 97%. Also, the results were better than the results obtained by commercial steps counting applications. This paper aims to introduce an algorithm to obtain accurate and robust step counting for indoor applications. The results of this work will be compared with state of the art to validate the followed approach.

Methodology
In this work, the smartphone accelerometer is used to collect the acceleration value during human movement. The collected data is transferred to the MATLAB drive using an application installed on the users' smartphones, called "MATLAB on mobile." MATLAB on mobile offers accessibility on the available sensors in the user smartphone. The obtained data by the accelerometer of the smartphone include four parameters. The first parameter represents the timestamp values, where it will indicate the (date, time in Hours: Minutes: Seconds). The second parameter represents acceleration values on the X-axis. The third parameter defines the acceleration on the Y-axis, and the fourth parameter represents the acceleration on the Z-axis. Most of the available accelerometer modules measure the value of acceleration quantity as a vector, and many modules can detect both linear and angular acceleration [18]. Angular acceleration can be defined as the time rate of change in angular velocity.
In contrast, the linear acceleration is the time rate of change in linear velocity. In this work, only the linear acceleration vector is used to estimate the number of steps elapsed. The angular acceleration caused by the human steps has a small value and can be neglected. Hence, the linear acceleration within a short period can be calculated as follows according to [18]: where a is the acceleration in [m/s 2 ], ∆v represents the change in velocity in [m/s], ∆t is the time interval in [s]. The accelerometer is used to measure the linear acceleration on the x-axis, y-axis, and z-axis independently. It is hard to predict the accelerometer's orientation every time a user operates the count steps functionality. Therefore, the acceleration vector is converted at each time point into an overall scaler value. Hence, Acceleration values will be determined like human walking or running regardless of the accelerometer's orientation. The overall acceleration value is calculated as the square root of three acceleration values, as expressed by equation (2) as in [11].
Indeed, the gravitational force affects the acceleration value due to the architecture of the accelerometer module. So, it is hard to estimate the axis affected by gravity since it depends on the smartphone's orientation when it is carried by hand or placed in the pocket. Fig.1 depicts the acceleration signals of the three axes. Therefore, the gravitational has been removed from the overall acceleration signal as follows. The human steps generate little height peaks in the acquired acceleration data. These peaks have limited heights, which might vary depending on the movement's behavior while walking, as shown in figure 2. Also, electromagnetic interference can turn the measured signal into a noisy signal. This noise might result from the surrounding appliances. Therefore, finding maximum local peaks over a specifically tuned threshold can be employed to estimate the number of detected steps.
The previous stage can be fulfilled by generating an envelope function MATLAB, which is determined using spline interpolation over local maxima separated by at least the samples (np). The number of samples (np) can be calculated using MATLAB. Consequently, the unwanted vibrations and fake steps are removed, making the steps counting much more accessible, as depicted in figure 3. In this approach, it is found that the main parameter which impacts the estimation's accuracy is the threshold definition. This threshold depends on the sampling rate, the step rate, and the average of the orthogonal accelerations' envelope function. Therefore, the threshold is defined by equation 4. where * * * ,, x y z a a a represent the upper peaks envelope, d is a correction factor, np is the number of samples, and it is defined as follows: ( / ) p s r n round R S = (5) In this work, the step rate r S is assumed to equal five steps per second. This assumption valid since this value represents the average of the human steps per second. The sampling period s  has been calculated using the new signal data's timestamp by finding the difference between every two values in seconds.
The segregation approach in this work is performed by generating a new signal based on the envelope function, which returns the upper limit for the average of the measured accelerations signals to remove the impact of vibrations and noise to ease counting the number of the steps, as shown in Fig.3 in red. This transformation will lead to an accurate detection process. The next step is to find the maximum difference value to represent the sampling period and is given by equation (6). The stages and the procedures of the proposed algorithm for steps counting purposes are summarized in Table 1.

Results and Discussion
The experiments were conducted at a public institution, which contains many electronic devices. These devices radiate electromagnetic noise, which interferes with measured data. The accelerometer of Huawei P30 has been used to collect the measurement data. Four different scenarios have been considered in this work and summarized in Table 2. The position of the smartphone during the experiments is depicted in figure 4.

Symbol Activity
A Walking at varying speeds with the smartphone is carried by the hand B Walking at varying speeds with the smartphone is placed in the Jacket pocket C Walking at varying speeds with the smartphone is placed in the trousers' front pocket D Running at varying speeds with the smartphone is carried by the hand

Steps Counting During Different Daily Activities
In this part, the accuracy of the proposed algorithm for steps counting during different daily activities is investigated. The accuracy of steps detection can be expressed as follows: 1 100% where Se is the number of the estimated steps, and Sa is the actual step number. Therefore, ten experiments with different speeds and path lengths have been considered for each case study, as summarized in Table 3. The algorithm could detect the number of steps with an average accuracy higher than 99% for normal walking when the smartphone is carried by the participant's hand.
The miscount was only for one or a maximum of two steps regardless of the path length. In the next scenario, the smartphone is placed horizontally in the pocket of the participant's jacket. The results presented an average accuracy of about 98%. The third scenario considered putting the smartphone in the front pocket of the participant's trouser.
The result showed a reduction in the average accuracy due to the smartphone's position, and it was around 96.7%. Finally, the running activity has been investigated, considering the smartphone is carried by the participant's hand. The average accuracy of the different tested scenarios is depicted in figure 5. The proposed algorithm showed an average accuracy of 96.9%. The algorithm presented a reduction of 1% accuracy than the standard walking scenario. figure 6 depicts the detected steps and actual steps in the different tested scenarios. In figure 6(a), the number of the detected steps was 19, which is lower than the actual steps by one step in scenario A. This error might result from miscounting one of the real steps by the proposed algorithm due to the set threshold value. figure 6(b) depicts the proposed algorithm's ability to detect the exact number of the actual steps with zero error. The smartphone placement in the trouser pocket might lead to unwanted vibration, leading to counting more steps than the number of the actual steps, as depicted in figure 6 (c). In the running scenario, the error might result during the transition from the movement to still during the experiments, increasing the number of the detected steps, as shown in figure 6 (d).

Comparison with other Pedometers
In this section, the proposed algorithm has been investigated in terms of its accuracy compared to other pedometers. Therefore, two Android platform applications have been used to detect the number of steps during normal walking and running activity. Also, a HUAWEI Watch GT-731 is used to validate the proposed approach. The first application was Pedometer by King Brain Inc., and the second application was a Pedometer for Walking. Both applications are available on the google play store. The tests have been conducted under the same conditions to validate the comparison study. The proposed algorithm results showed improved detection compared to other methods with at least 3%.  The average accuracy of the HUAWEI Watch GT-731 was in second place, with 96.12% for the typical walking scenario and 93.73% for the running scenario. It is worth to mention here the HUAWEI watch does not utilize the smartphone accelerometer, which is the case for the other applications. The result of this study are depicted in figure 7.

Conclusion
This work aims to propose a robust algorithm for step detection with high accuracy for indoor systems. Mainly, the proposed algorithm will collect the acceleration data from the smartphone's accelerometer. In the proposed algorithm, a new signal based on the envelope function has been generated to return the upper limit for the average of all measured accelerations signals. The previous phase will remove the impact of vibrations and noise, and it will ease counting the number of steps and obtaining accurate results. It is found that the setting of the threshold will affect the accuracy of the detection process. Therefore, a new formula for the set threshold was created based on the acceleration signals' envelope and the number of samples. The proposed algorithm has been investigated for two case scenarios: the normal walking scenario and the running scenario considering different smartphone's positionthe obtained accuracy based on the proposed algorithm higher than 97% for all considered scenarios, as summarized in Table 4. The results of the proposed approach presented improved accuracy compared to other works. Finally, the proposed algorithm can be used for online and offline step counting with a maximum step rate of 5 steps per second. The sampling rate can be set from 50 Hz to 100 Hz. The threshold's value depends on the measured accelerations signal and the correction factor.