# S-PDR: SBAUPT-Based Pedestrian Dead Reckoning Algorithm for Free-Moving Handheld Devices
## 3 SBAUPT-Based Pedestrian Dead Reckoning (S-PDR)
### Heading Estimation
#### 3.3.2 Reduced-Set Acceleration PCA  
With the elimination of the outlier accelerations, the remaining reduced set of accelerations from the acceleration window are more precise in describing the direction of motion. Alternatively to averaging the heading angles from the reduced-set accelerations, PCA can be applied to the reduced-set to obtain the main direction of motion. As discussed earlier, the principal components returned from the PCA suffer from directional ambiguity as they represent the correlation of the data. The effect of the outlier accelerations is evident in Figure 15, where the first principal component from the reduced set is less affected by the outliers in comparison the first principal component based on the full accelerations window. The heading derived from the PCA is computed based on the components of the unity vector representing the correlation of the data as shown in Equation (5) but is also representative of the forward or backward direction of motion. Hence, two candidate headings are derived from the PCA that are \(\pi\) radians apart, where the second candidate is computed as in Equation (6), and the candidate coinciding with heading from the histogram matching process is chosen to be the PCA derived heading for forward motion as in Equation (7). \[\theta_{PCA_{41}}=\text{arctan2}\big{(}p_{1_{E}},p_{1_{N}}\big{)} \tag{5}\]  
\[\theta_{PCA_{42}}=\text{RoundToPi}\big{(}\theta_{PCA_{41}}+\pi\big{)} \tag{6}\]  
\[\theta_{PCA}=\min\big{(}abs\big{(}\theta_{PCA_{41}}-\theta_{H}\big{)},abs \big{(}\theta_{PCA_{42}}-\theta_{H}\big{)}\big{)} \tag{7}\]  
where \(p_{1_{E}}\) is the \(1\)st principal component in east direction, \(p_{1_{N}}\) is the \(1\)st principal component in North direction, \(\theta_{PCA_{41}}\) and \(\theta_{PCA_{42}}\) are the candidate headings from PCA, \(\theta_{PCA}\) is the PCA heading, the min function returns the candidate angle with minimum delta from \(\theta_{H}\) which is the heading from the histogram, and RoundToPi is a function that rounds the angles to a \([-\pi,\pi]\) range. Since there are two heading estimates--the first being the analytical heading from the histogram and the second being the reduced-set PCA-based heading, it is desirable to apply a fusion phase to combine the information from both estimates. The fusion is done by means of a complementary filter with an adaptive gain based on the covariances of each of the derived angles. First, the heading derived from the histogram is computed as the average of all the headings in the bins representing the forward direction of motion computed as in Equation (8), and the variance of the headings in the bins are computed based on Equation (9). For the PCA-based heading, the variance of the data points from the principal component is computed to represent how good the fit is, which is based on the residuals (\(r_{m}\)) that are shown in Figure 16 and computed by Equation (10). The weights used for the filter are then computed as the ratio of each variance to the total variance of both estimates as shown in Equation (11). The weights are cross correlated, so the weight computed from the PCA is used for the histogram-derived angles and vice versa. As one  
Figure 15: Principal Component Analysis (PCA) for full step window vs. reduced step window. estimate has a higher variance and a consequently higher ratio, the higher weight should be given to the other estimate. The fusion angle is computed based on Equation (12). \[\theta_{H}=\frac{\sum_{i=1}^{n}\theta_{i}}{n} \tag{8}\]  
\[var_{H}=\frac{\sum_{i=1}^{n}(\theta_{i}-\theta_{H})^{2}}{n-1} \tag{9}\]  
\[var_{PCA}=\frac{\sum_{i=1}^{m}{r_{m}}^{2}}{m-1} \tag{10}\]  
\[w_{PCA}=\ \frac{var_{PCA}}{var_{H}+var_{PCA}}\qquad\qquad\qquad w_{H}= \frac{var_{H}}{var_{H}+var_{PCA}} \tag{11}\]  
\[\theta_{F}=w_{H}\times\theta_{PCA}+w_{PCA}\times\theta_{H} \tag{12}\]  
The block diagram for the heading estimation algorithm is shown in Figure 17, the algorithm for heading estimation is shown in Algorithm 1, and the used notations are shown in Table 1.