## 2 Materials and Methods
### Phase-Based Step Frequency Estimator
#### 2.1.1 Gait Phase Variable of Thigh Motion  
The gait phase variable is used to represent a complete gait cycle. Here, we intend to compute the gait phase variable by the motion of the right thigh. The sagittal data of the right thigh IMU are collected and the sample period of IMU is \(t_{s}\). The measured thigh angle and thigh angular velocity are marked as \(q_{t}\) and \(\dot{q}_{t}\). The gait phase variable is defined as  
\[\varphi(t)=\text{atan2}[\dot{q}_{t}(t),q_{t}(t)]+\pi \tag{2}\]  
The phase scatter diagram is shown in Figure 1 with blue points and the gait phase variable of each point is its polar angle. In order to make the phase variable change continuously on [0, 2\(\pi\)], it is necessary to translate the phase diagram so that it wraps the origin. At the same time, the angle and angular velocity of the right thigh are normalized, respectively, to make the trajectory of the phase diagram closer to a circle [12]. Translation and normalization formulas are as follows  
\[ \begin{array}{l}q_{t\_{I}in}(t)=\alpha_{x}(t)[q_{t}(t)+\beta_{x}(t)]\gamma\\ \dot{q}_{t\_{I}in}(t)=\alpha_{y}(t)[\dot{q}_{t}(t)+\beta_{y}(t)]\gamma\end{array}  \tag{3}\]  
where \(\gamma=180\) is the scaling factor, \(\alpha\) is the normalization coefficient and \(\beta\) is the translation coefficient. \(\alpha\) and \(\beta\) are calculated in real-time according to Equation (4) during walking. \(q_{t\_{I}in}\) and \(\dot{q}_{t\_{I}in}\) are the thigh angle and thigh angular velocity after translation and normalization. \[ \begin{array}{l}\alpha_{x}(t)=\frac{1}{|\max[q_{t}(t)]-\min[q_{t}(t)]|}, \quad\beta_{x}(t)=\frac{-|\max[q_{t}(t)]+\min[q_{t}(t)]|}{2},\\ \alpha_{y}(t)=\frac{1}{|\max[\dot{q}_{t}(t)]-\min[\dot{q}_{t}(t)]|},\quad\beta _{y}(t)=\frac{-|\max[\dot{q}_{t}(t)]+\min[\dot{q}_{t}(t)]|}{2}.\end{array}  \tag{4}\]  
The maximum and minimum values in Equation (4) are calculated in real-time from the data of the previous gait cycle. The phase scatter diagrams before and after processing are shown in Figure 1. After processing, the phase diagram is close to a circle centered on the origin. The processed gait phase variable is computed as  
\[\varphi_{tn}(t)=\text{atan 2}[\dot{q}_{t\_{I}in}(t),q_{t\_{I}in}(t)]+\pi \tag{5}\]  
\(\varphi_{tn}(t)\) is the blue dotted line shown in Figure 2. In each gait cycle, the linearity between \(\varphi_{tn}(t)\) and time is poor, mainly due to the noises in the measured thigh angle and angular velocity. Here, Kalman filtering is applied to fuse data to remove noise and improve data accuracy. \(\varphi_{m}(t)\) and \(\dot{\varphi}_{tn}(t)\) are the states which are input into the Kalman filtering equation. \(\dot{\varphi}_{tn}(t)\) is computed as  
\[\dot{\varphi}_{tn}(t)=\frac{\varphi_{tn}(t)-\varphi_{tn}(t-t_{s})}{t_{s}} \tag{6}\]  
Figure 1: Phase scatter diagrams of thigh motion and the pentagram represents the origin. Kalman filtering equation consists of a prediction equation and a correction equation. The system state equation and observation equation are shown in Equation (7). Equation (8) is the covariance prediction equation and Equation (9) is the correction equation. \[ \begin{split}\mathbf{x}_{k|k-1}=\left[\begin{array}{c}\varphi_{ln}(t )\\ \dot{\varphi}_{ln}(t)\end{array}\right]&=\mathbf{A}\mathbf{x}_{k-1}=\left[\begin{array} []{cc}1&t_{s}\\ 0&1\end{array}\right]\left[\begin{array}{c}\varphi_{ln}(t-t_{s})\\ \dot{\varphi}_{ln}(t-t_{s})\end{array}\right]\\ &\mathbf{z}_{k}=\mathbf{H}\mathbf{x}_{k}=\left[\begin{array}{cc}1&0\\ 0&1\end{array}\right]\mathbf{x}_{k}\end{split}  \tag{7}\]  
\[ \begin{split}\mathbf{P}_{k|k-1}=\mathbf{P}_{k-1|k-1}\mathbf{A}^{T}+\mathbf{Q}\\ &\\ K_{k}=\mathbf{P}_{k|k-1}\mathbf{H}^{T}(\mathbf{H}\mathbf{P}_{k|k-1}\mathbf{H}^{T}+\mathbf{R})^{-1}\\ &\mathbf{x}_{k|k}=\mathbf{x}_{k|k-1}+K_{k}(\mathbf{z}_{k}-\mathbf{H}\mathbf{x}_{k|k-1})\\ &\mathbf{P}_{k|k}=(\mathbf{I}-K_{k}\mathbf{H})\mathbf{P}_{k|k-1}\end{split}