Enhanced PDR-BLE Compensation Mechanism Based on HMM and AWCLA for Improving Indoor Localization

This paper presents an enhanced PDR-BLE compensation mechanism for improving indoor localization, which is considerably resilient against variant uncertainties. The proposed method of ePDR-BLE compensation mechanism (EPBCM) takes advantage of the non-requirement of linearization of the system around its current state in an unscented Kalman filter (UKF) and Kalman filter (KF) in smoothing of received signal strength indicator (RSSI) values. In this paper, a fusion of conflicting information and the activity detection approach of an object in an indoor environment contemplates varying magnitude of accelerometer values based on the hidden Markov model (HMM). On the estimated orientation, the proposed approach remunerates the inadvertent body acceleration and magnetic distortion sensor data. Moreover, EPBCM can precisely calculate the velocity and position by reducing the position drift, which gives rise to a fault in zero-velocity and heading error. The developed EPBCM localization algorithm using Bluetooth low energy beacons (BLE) was applied and analyzed in an indoor environment. The experiments conducted in an indoor scenario shows the results of various activities performed by the object and achieves better orientation estimation, zero velocity measurements, and high position accuracy than other methods in the literature.


Introduction
Indoor location-based services (LBS) have always been of great importance because people live and work in indoor environments most of their lives. Massive wireless networks are built according to the IEEE 802.11 wireless Ethernet standard [1]. LBS are the backbone of indoor mobile positioning techniques [2]. Global navigation satellite systems (GNSS) and global positioning systems (GPS) have helped us provide accurate location services for outdoor environments. Still, these services are impeded by signal absorption and hamper in specific environments (e.g., dense forests, mountainous regions, underground facilities, and high-rise buildings) [3]. GNSS and GPS take the user's three-dimensional information (i.e., longitude, altitude, and latitude) [4]. The accuracy of these services depends upon the line of sight, and if the precision is good, object detection is possible within meters. Therefore, to come up with an overall location service, a number of technologies have emerged for indoor positioning; for instance, radio frequency identification (RFI) [5], pseudo-satellites [6], indoor ultrasonic positioning (UIP) [7], indoor positioning approach using iBeacon [8], ultra-wideband (UWB) technology allows micro-positioning of objects along with obstacles [9], and indoor positioning based on ZigBee [10].
A large variety of reconfigured wireless devices (RWD) are already in use, namely Bluetooth low energy (BLE) beacons, smartphones, Wi-Fi, ultra-wideband (UWB) beacons, and digital cameras for indoor positioning [11,12]. For purpose-built installations, The notable contributions of the proposed study is as follows: • Developed mechanism based on complementary filter to integrate roll, pitch, and angular velocity information to obtain orientation tracking information. • Developed HMM-based activity detection approach to recognize the various performed activities. • Smoothing of RSSI measurements by passing through the Kalman filter to remove noise and enhance the accuracy of distance calculation between the beacon and mobile phone user. • Weight assignment based on the power of RSSI measurements and use of AWCLA for the proximity calculation between the BLE beacon and smartphone. • Furthermore, different evaluation metrics were utilized to evaluate the effectiveness of the proposed EPBCM based on HMM and AWCLA, such as a comparison, in terms of position accuracy, confirmation of activity detection by clustering the sensor data to visualize the performed activities and compare with HMM-based activity detection approach, and comparison of the orientation estimation approach based on AHRS and UKF.
The rest of the paper is divided into the following sections. Section 2 presents the related works; Section 3 presents enhanced PDR-BLE compensation mechanism based on HMM and AWCLA for Improving indoor localization. Section 4 presents Compensation mechanism based on AWCLA. Section 6 discusses experimental design, implementation environment, comparison of proposed system with state-of-the-art-techniques, and performance analysis. Section 7 concludes the paper with possible future directions.

Related Work
The internet of things is an evolving field, attracting much attention from the research community [26][27][28][29][30][31][32][33][34][35][36][37][38][39][40][41][42][43]. The systems pertaining to location tracking and intelligent navigation are widely employed to handle specific scenarios related to security, logistic medicine, and mission-critical indoors. Indoor Localization is deemed one of the quintessential areas among all of them because of excessive location-based services [44]. Therefore, indoor positioning is a popular topic that is gaining popularity. It is a network of devices used to locate objects or people where global navigation satellite system (GNSS) and global positioning system (GPS) technologies lack exactness or are completely unsuccessful, particularly parking garages, underground locations, multistory buildings, railway stations, and airports. The dependency of multiple computing concepts on positionings, such as location and context-aware systems and ubiquitous computing, shows how important the indoor positioning systems (IPS) hold [45]. To find the accurate location where the GPS signal is lost, radio-frequency signals have been developed. When compared to the classic Bluetooth, Bluetooth low energy beacons are low in cost, low in energy consumption, and small in size [18]. Distance computation between beacons and smartphones can be done by using BLE beacons. To determine a single point in a two-dimensional space, a minimum of three beacons are required if considering the trilateration scenario [46]. Indirect distance computation involves the measurement of RSSI values.
A microelectromechanical systems (MEMS) are used to offer beacon-free solutions, consisting of a gyrometer, an accelerometer, and magnetometer. Due to the lightweight, smaller size, and lower cost of MEMS, sensors are often employed for the PDR system. Conventionally, the indirect estimation of walking speed and walking direction is conducted by using the PDR approach [47]. PDR can only obtain relative positioning results, has high position accuracy, and cumulative errors. However, PDR is a self-confined approach, but will produce a growing drift as the walking distance increases [48]. To reduce the errors, bias, and bias instability that accumulate through the navigation equation at the output of MEMS sensors can be contained by attaching inertial measurement sensors (IMU) on foot and other body parts to recognize particular activities and by using the zero-velocity update (ZVU) algorithm to predict the position [49,50]. The velocity and the acceleration integral of the foot are practically zero when the stance phase occurs during the motion of the pedestrian [51]. Therefore, an error in the foot orientation increases the position's error to grow linearly with time. Similarly, the calculation of the non-gravitational acceleration is affected by the attitude errors. If the orientation and attitude errors are not tackled rightly, the combined result induces a worse position estimation. The erroneous step increased position error. Therefore, a low false detection rate, in estimating each step's start and end is conducive to improve accuracy. In [52], for precise human body part orientation tracking, the author reviewed the filtering techniques and main sensor fusion. The author in [53] deals with the nonlinear attitude prediction system and linearization of the currently estimated points of the model in the PDR system by using the extended Kalman filter (EKF). For attitude estimation, the author in [54] proposed the hidden Markov model (HMM) based EKF. To enhance the results of the roll, pitch, and yaw for orientation tracking, the author developed a double-stage Kalman filter (KF) in [55]. In attitude estimation of PDR, when the nonlinear characteristic is extreme, for instance, environmental magnetic variation, variation in acceleration based on human motion, the attitude dynamics, etc., causes divergence of the EKF and degrades the accuracy. To enhance the performance of PDR by using a sophisticated ZVU algorithm in [56], the author achieved ∼4% distance error by incorporating the two outputs of the maximum bounds at the stance phase by implementing a binary decision-making rule. The study in [57] shows that the author knows the sensor data, based on sensor knowledge, examines the acceleration-magnitude detector, acceleration-moving variance detector, and the angular rate energy detector. The paper shows that all detectors can be derived by using the general likelihood ratio test (LRT) framework. To accurately distinguish stance phases, the author in [57] proposed a clustering algorithm. In [58,59], the authors suggest that HMM chains classify human activities, and [60] show that there are more computational costs for the hierarchically structured approaches. The author in [61] used a smartphone-based IMU sensor for activity recognition to facilitate the people who had chronic neurodegenerative diseases, such as Alzheimer's.
To identify and track objects automatically, various technologies related to indoor positioning include Wi-Fi, ultra wide band (UWB), radio frequency identification (RFID), and BLE. To achieve better positioning accuracy and to reduce the positioning system cost based on RFID, the authors in [62] presented a hyperbolic positioning algorithm and in [63] convert paths that are non-line of sight (NLOS) to the paths which are line of sight (LOS) by employing a hybrid method based angel of arrival (AOA) and phase difference of arrival (PDOA). Positioning using BLE beacons in an indoor environment, the author suggested a hybrid method, combining dead reckoning and trilateration [64]. In [65], the authors suggested KF, to smooth the RSSI measurements obtained from the installed BLE beacons and developed an android application to locate a user inside a building. There were high computational and processing times in the UWB-PDR-based localization algorithm. Due to the increased numbers of anchors in the localization algorithm, the system cost also increased [66]. In [67], WCL and fingerprint techniques are used for indoor localization based on the least square method. Improvements are being made in the WCL localization algorithm by [68]. However, the estimated error is still significantly high.
To predict and measure the motion of the body based on IMU wearable devices, many machine learning algorithms are used. To reduce the error in an indoor environment, a deep neural network fingerprinting based indoor positioning approach is used [69]. In [70], the author used inertial sensor data to detect step length and step detection by using ANN and RNN. In another paper, the author used the feed-forward NN approach to get the location at the output [71]. Similarly, in [72], based on RSS measurements of Wi-Fi access point nodes, the author suggested a radial basis function to find the location of a user. As mentioned above in Table 1, the critical analysis of indoor localization based on the BLE-beacon, PDR machine learning algorithms, and the combined hybrid approach has many drawbacks in system performance and accuracy. To predict and identify the object or location, these approaches directly use sensor data as an input to the machine learning algorithm. The drifting error and bias in sensor readings affect the accuracy of the position estimation.
To the best of the authors' knowledge, all of the indoor positioning systems are developed based on single or hybrid localization algorithms that have problems of high position errors and more computational costs, particularly for hybrid localization algorithms. Moreover, all of these only determine the location of an object in an indoor environment. In some cases, sensors mounted on the foot, hand, arm, and chest are considered to track the orientation and detect the activity of an object up to the binary level. Furthermore, all of these existing indoor positioning systems face different issues, such as high localization errors, high computational costs, and high hardware costs, to name of few, as mentioned in Table 1. Therefore, a new solution is required to track the position and detect the activities performed by the object, which aims to minimize latency, maximize position accuracy, and provide better orientation estimation. A compensation mechanism is developed to reduce the effect of the drift caused by the dead reckoning localization algorithm. Proximity calculation between beacons and smartphones are also improved by using AWCLA and passing RSSI measurements through the Kalman filter. This enhanced hybrid localization algorithm is presented in the following sections.

Design of Proposed EPBCM Localization Algorithm
In this section, an EPBCM based on HMM and AWCLA was implemented to decrease drift and error in the position caused by navigation algorithms. The details of the proposed EPBCM are shown in Figure 1. A brief explanation of each step and mathematical formulation used to calculate the orientation, x,y coordinates through various localization techniques, and detection of activities of an object in an indoor environment by considering the HMM are presented in the below sub-sections. Table 2 presents notations and symbols used in mathematical formulation.

Quaternions Calculation
The orientation between the inertial navigational frame {in f } and the sensor-body frame {sb f } can be represented by adopting quaternions. The scaler part of quaternions consist of s ∈ R and v ∈ (x, y, z), which is a vector part and are expressed as q ≡ (s, v), where v ∈ R 3 . The vector part of the quaternions can be represented into two different frames q and q * as v in f = q v sb f q * . The vector in the sensor body frame {sb f } refers to v sb f and the inertial navigational frame {in f } refers to vector v in f , and denotes the multiplication operations between vectors. A quaternion number is represented in the form of real and imaginary elements, where i, j, and k are basis elements and α, β, γ and δ are real numbers α + βi + γj + δk. The unit-vector quaternion q sb f in f encoding rotation from the inertial frame to the body frame of the sensor q sb f in f = (α σ 1 σ 2 σ 3 ) T . The unit-vector quaternion encoding rotation from the inertial navigational frame to the body frame of the sensor. α The amount of rotation that should be performed about the vector part . σ 1 , σ 2 , and σ 3 Elements σ 1 , σ 2 , and σ 3 thought of as a vector about which rotation should be performed. φ The angle of rotation. Unit vector representing the axis of rotation.

Q(q)
Rotation matrix. Q Four-dimensional vector space over the real numbers R 4 .

NED
North-east down ψ Rotation around yaw. ξ Rotation around pitch. ϕ Rotation around roll. atan2 Computes the principal value of the argument function applied to the complex number in the quaternion. δφ Prior gyros bias errors. The error between estimated gyroscope bias and true gyroscope bias. δψ Euler angles errors . x State vector of the proposed filter. e q Error quaternions. e Attitude error.
The state equation for the attitude estimation system. u k The noise vector, which refers to the noise related to the rotation error angle. ζ δΨ (t) Noise error, true bias random walk. ζ ∆Φ (t) Noise error, estimated bias random walk.
The estimated rotation rate. acc sb f Output of accelerometer. mag sb f Output of magnetometer. y Measurement of the combination of the accelerometer and magnetometer. η acc sb f and η mag sb f The measurement independent zero-mean Gaussian white-noise. m n and g n True magnetic and gravity vector. The variance of measurement noise.
M R Covariance matrix.

h(q)
Represents the nonlinear equations that convert the magnetometer reference vector r mag ∈ R 3 and accelerometer reference vector r acc ∈ R 3 from INF to the SBF. ρ Sigma points. λ Represents the scaling parameter that shows the sigma points spread around the column vectors of the covariance matrix. K prior x j The prior estimates of covariance.

ρ'
Posterior sigma points. Distribution constructed by the kernel density estimate. wO,t (.) Weight assigned to each activity performed in the various dedicated zones Z i .
The amount of the rotation that should be performed about the vector part specifies by the element α, where as elements σ 1 , σ 2 , and σ 3 , thought of as a vector about which rotation should be performed. q sb f in f = (ασ T ) T . If φ is the angle of rotation and the vector ε = (ε x ε y ε z ) T is a unit vector representing the axis of rotation, then the quaternion elements are defined as a unit quaternion q 2 = α 2 + σ 2 1 + σ 2 2 + σ 2 3 = 1. A simple rotation can transform a vector from one reference frame to another according to Euler's rotation theorem, and this is done by rotating φ about a unit vector . This unit vector representing the axis of rotation, and the quaternion elements are defined as: The set of quaternions, defined within a four-dimensional vector space over the real numbers R 4 is denoted by Q. Quaternions q sb f in f can be used to rotate an arbitrary three-element vector from the inertial frame to the body frame using the matrix multiplication operation To rotate a vector from the inertial navigational frame to the sensor body frame, the attitude quaternion can be used to construct a 3 × 3 rotation matrix, to perform the rotation in a single matrix multiply operation expressed as: The rotation can be reversed by simply inverting the attitude quaternion q sb f in f before performing the rotation. Likewise, the operation can be reversed by negating the vector part of the quaternion vector. Euler angles are intuitive and straightforward for simple analysis and control, but these are limited by a gimbal lock, which prevents Euler angles from measuring orientation when the pitch angle approaches ±90 • .

Quaternions Calculation at North-East Down (NED)
The inertial frame is an unmoving Earth-fixed set of axes reference. In the inertial frame, x-axes point north, y-axes point east, and z-axes point down. This configuration of axes in the inertial frame reference is called north-east Down (NED). The sequence of rotations is used to represent a given orientation, which is the first yaw, then pitch, and finally roll. YAW rotation results in the new coordinate frame as illustrated in the Figure 2a. Yaw represents rotation about the inertial-frame z-axis by an angle ψ. The rotation of yaw around the z-axis produces a new coordinate frame where the z-axis is aligned with the inertial frame, and the yaw angle ψ rotates the x and y axes The orientation of the new coordinate frame after the rotation of yaw is shown in Figure 2b.
Similarly, if the rotation around pitch represents ξ and the pitch is not rotating about the inertial frame Y-axis as shown in Figure 2, it is because that change in orientation occurs due to the changing in frames. This can be seen in Equations (4) and (5).
Performing rotation around the newf 2 x-axis, SBF is obtained. The SBF contains yaw, pitch, and roll, and the rotation matrix for moving from the newf2 to SBF is given by: To complete the rotation matrix for moving from the inertial frame to the body frameit is shown in Equation (7) Q sb f To get the accurate angular rates in the proper frames, the x-axis IMU output must be rotated into the newf2 frame, the y-axis IMU output must be rotated into the newf1 frame, and the z-axis IMU output must be turned into the INF. The resulting transformation matrix for converting body-frame angular rates to Euler angular rates is given by Let ρ represent the smartphone body frame x-axis gyro output, τ represent the smartphone body frame y-axis gyro output, and θ represent the body frame z-axis output. By taking the derivative of the roll, pitch, and yaw, the Euler angle rates are computed as Gimbal lock becomes a problem when using Euler angles and the above operation illustrates mathematically. When the pitch angle ξ approaches ±90 • , the matrix elements diverge to infinity because the zero in the denominator causes the filter to fail.
The quaternions data can be converted to Euler angles on the receiving end, and the exact equations for converting from quaternions to Euler angles depend on the order of rotations. The sensors move from the inertial navigational frame to the sensor body frame using the first yaw, then pitch, and finally roll. The Euler angles can be obtained from the quaternions, and this results in the following conversion equation: To tackle the problem that arose due to the arctan and arcsin, function atan2 computes the principal value of the argument function applied to the complex number in the quaternion. The function atan2 value is in the range (−π, π], that is −π < atan2(y, x) ≤ π. The body attitude matrix can be calculated by Euler angles ϕ, ξ, and ψ. By using the angular velocities of the body frame concerning the inertial navigation frame denoted in the smartphone body frame, the measure angular velocity can be calculated as explained in [48].

Orientation Estimation Based on UKF
In this study, the detailed explanation of orientation estimation based on UKF is presented as shown in Figure 3. As discussed in Section 3.1.1, in the proposed orientation estimation based on UKF, the prior gyros bias errors, and Euler angle errors are expressed as δφ and δψ in the state vector of the proposed filter as x = δψ δφ . Assuming δψ is small and the error quaternions e q is approximated as e q ∼ = 1 δψ 2 The basic idea behind the use of the proposed filter is to use the quaternions as the global attitude representation and use a three-component state vector δψ for the local representation of attitude errors [11]. δΨ = δΨ.e (11) where δψ is the rotation error angle and e t =   e x e y e z   is the rotation axis. The product of estimated and error quaternion gives true quaternion q t = δq(δψ) q. Where e q = δq(δψ) and the cross symbol shows quaternion multiplication [68].The state vector in the proposed filter is chosen as δψ T δφ T , here δψ is the error between the estimated gyroscope bias and true gyroscope bias.

Orientation Calculation System Model
The state equation for attitude estimation system iṡ The process model is adopted as x k+1 = (I + A k × ∆t) x k + u k , where u k is the noise vector, which refers to the noise related to the rotation error angle ζ δΨ (t) and ζ ∆Φ (t) is the noise error between true bias random walk and estimated bias random walk. A k is defined using the estimated rotation rate w b b/n and ζ δΨ (t) R 3 and ζ ∆Φ (t) ∈ R 3 are process noise and are assumed to be a zero mean Gaussian white noise. Then, the process covariance matrix is The measurement equation is represented by, y = h(q) + acc sb f mag sb f T , where y is the measurement of the combination of accelerometer and magnetometer. Here a cc b ∈ R 3 and mag b ∈ R 3 are output of accelerometer and magnetometer, η acc sb f and η magsbf are the measurement independent zero-mean Gaussian white-noise and can be expressed as the true magnetic and gravity vector m n and g n .
The variance of measurement noise is η 2 acc sb f and η 2 mag sb f and its covariance matrix , and h(q) represents the nonlinear equations that convert the magnetometer reference vector r m ag R 3 and accelerometer reference vector r a cc R 3 from INF to the SBF. The values of r a cc and r m ag are constants whose specific values can be found using the method in [84].

Time and Sigma Points Update
For calculating the posterior first and second order statistics of a random variable, which undergoes the unscented transformation. By using a minimal set of deterministically chosen weighted sample points, the state distribution is again represented by a Gaussian random variable (GRV). Covariance and true mean completely capture the prior random variable by using the weighted sample points called sigma-points. In this case, the error state x contains the orientation information q and the gyro bias φ and has zero meanx. The following scheme is used to calculate the sigma points ρ.
where, λ represents the scaling parameter that shows the Sigma points spread around the column vectors of the covariance matrix K andx.
whereas, the augmented state vector dimension is represented by l, µ = (10 −3 , 1], and K = 0. To yield each point of a set, which is expressed through the Equation (52), and transformed samples ρ i,j|j−1 = f ρ i,j−1|j−1 . Here the ith column of the matrix represent i.
The prior estimates of covariance K prior x j and state x prior j are given through the ρ as expressed in equation In the above two equations W m i and W j i are used to calculate the mean and covariance of the posterior ρ', respectively, as follows: To determine posterior covariance, µ determines the spread of the ρ around x prior k , where β accentuate the weighting on the zero ρ [85]. The value of optimal β is obtained from [86].

Measurement Update
Magnetic measurement and gravity vector are not good choices for the reckoning of the horizontal component of the state vector. Moreover, yaw correction is not possible by using a gravity vector. Due to the described issues and to ensure gravity correction, it does not act on the yaw estimate, and as magnetic anomalies only influence the pitch estimates and roll, we divide the measurement update into two steps. For the case of gravity vector measurement update: We set the third part of δψ to zero after the first update step, as q e,j x j = 0 and based on the update K the ρ should be recalculated. Similarly, the magnetic field vector measurement equation can be written as M m i,j|j−1 = h m ρ i,j|j−1 and the first two part of δψ are set to zero after the second update as q e,k [2,3] = 0. In UKF compared to EKF, the system around its current state does not need to linearize.
To adaptively adjust the measurement covariance R, diagonal covariance inflation (CI) approach in [87] is implemented. In this approach, for the residual error (ỹ), the measurement update of the low-confidence hypothesis will inflate in all directions. The proposed covariance inflation approach always guaranteed the Mahalanobis distance r < 1. The CI approach can resolve the inconsistency between the low-confidence hypothesis observation and the proposed filter prediction. The measurement update for the accelerometer and magnetometer isỹ The determination of the error covariance R k is the main issue of implementing this method R a k = c ×ỹ 2 + ζ 2 a (25)

Activity Detection Model Based on HMM
The observation model uses the inertial measurement (IMU) acceleration data received from the different activities performed by the person containing the smartphone. By performing various activities while holding a smartphone in a user's hand, fingerprints are collected of each activity in an offline phase. Let ρ i,k,l be the measurements, having set M j collected in the various designated areas of the 4th floor of JEJU national university, concerning the k activities performed PA k . Whereas l ∈ {0, 1, 2, . . . , M i−1 }. Once new IMU measurements set ρ t collected during random motion, containing all of the mentioned activities in Table 3. The model allocates specific evidence to each zone.

Walking Upstairs
Walking Activity Writing on White Board

Range of Acc Values
In previous research, the observation model's role was to assign a weight wO, t(.) to each activity performed in the various dedicated zones Z i i ∈ {0, 1, 2, . . . , M ( i − 1)} for all measurements in ρ t . By modeling the activities based on the different values of the accelerations computed from various performed actions on the university floor, a distribution D(.) is constructed by the kernel density estimate.
To each PA in each zone K(.) is the kernel and h i,k is the bandwidth of the kernel. Due to the facility of analytical derivations, the Gaussian kernel is considered, and the shape of the kernel has no impact on the model [88].
By maximizing the pseudo-likelihood leave-one-out cross-validation, the bandwidth of h i,k is estimated.
The allocation of weight by the observation model to each performed activity at any time t is computed as the output of the kernel density estimate of each zone followed by a normalization phase, In this activity detection approach, based on the hidden Markov model, the mobility model is constructed. To determine the confidence level that the sensor resides in each zone, the probability is assigned based on the measurements of the accelerometer and combined with the evidence given by the observation model. At first, we provide a general overview of the HMMs and the confidence-based zone estimation combined with the observation model.

Hidden Markov Models
A probabilistic model that can be used to represent observations, and these sequence of observations can either be independent, time-dependent, continuous, or discrete [89]. Let the S N HMM model be denoted by H, and the total states S = {S 1 , S 2 , . . . , S N }. The objective of the Nth order HMM model is to determine the corresponding state sequence S = {S 1 , S 2 , . . . , S α }, whenever the sequence of length α and R = {R 1 , R 1 , . . . , R α } is given. For each present state, the probability of arriving at the next state is designated by the transition probability and termed as matrix A. The actual states are hidden from the observer and determine the likelihood that each type of observation is in each state by using observable data and termed as emission probabilities forming matrix B. Probabilities of starting at different states in HMM are represented as T. Based on the prior knowledge, it can be either random, any vector generated, or uniform. Thus any HMM can be represented as H = (A, B, T). The transition probability from the state a to b can be denoted by P ab a, b ∈ {1, 2, . . . , S N } and forming the matrix A. The output probability distribution forming the matrix B, and can be represented asP a (R), a ∈ {1, 2, . . . , S N }. The complete explanation is in [90].

Activity Detection Approach Architecture
In an indoor environment, the objective is to detect a change in the sensor state from one zone to another in a specific period. To determine the likelihood that the sensor has followed some trajectory, we use the HMMs. Since the states are hidden S = {S 1 , S 2 , . . . , S α }, we can observe a sequence R = {R 1 , R 1 , . . . , R α }, corresponding to a vector of acceleration magnitude measurements at each state. To observe the sequence R, we are interested in determining the probability P(R|H). The probability obtained by the observation model is combined with P(R|H) to determine a confidence level of having the accelerometer sensor values residing in each zone. The transition between two zones Z i to Z j can be represented by S N state HMM H i,j , whereas a set of HMMs denoted as H i,j , i, j ∈ {1, 2, . . . , M z }. In each transition region, the number of states chosen by the user is represented as S N .

Weight Assignment
The aim is to evaluate the probability of observing the sequence P(R|H), given an observation R and S N state HMM model H. When we know the parameters of the HMM, this is a problem for evaluating the observed sequence. For the evaluation purpose of P(R|H), it can be broken down as follows. We can compute the joint probability of the state sequence and the observed sequence, given a state sequence S = {S 1 , S 2 , . . . , S α }, and the range of α values in different zones are In (30) is the product of the probability of the state sequence S given the model H and the likelihood of the observation sequence R given the state sequence S. The first term is obtained from the activity detection matrix B as follows, From the transition matrix A, the second term is obtained as, By taking the summation of P(R, S|H) over all possible state sequences S N , we can then derive P(R|H) [91], The computational cost and feasibility of the system depend on the range of α. To obtain the probability P(R|H) and reduces the computational burden, a forward-backward algorithm can be used. Thus, (33) can be transformed as The probabilities ga(P) and h a (P) mentioned in (35) can be recursively computed; therefore, the probability P(R|H) is given by, In the (36), when a transition between Z i to Z j took place, the objective of the proposed HMM-based activity detection model is to assign evidence. Each HMM H i,j allocate a likelihood based on a sequence R = {R 1 , R 1 , . . . , R α }. For each HMM H i,j , the probabilities P R|H i,j , i, j ∈ {1, 2, . . . , M z } are computed. Based on that, the probabilities of the transitions between different zones are calculated. The probability is zero where no transition is possible. The coefficient of transition c i,j , i, j ∈ {1, 2, . . . , M z } between zones Z i to Z j is as follows, Probabilities that the sensor moves from Z i to Z j are a complement to the probabilities where the likelihood for transition is zero. The calculation for the evidence w M,t (.) is as follows, The weight associated with the observation model O(.) is w O,t−1 . The coefficient c i,j will be large if there is no transition Z i to Z j . All coefficient c i,j values in the case for i = j will be significant. This problem does not cause any issue if we put the values of coefficients in the above equation and, thus, evidence is based on the observation model w O,t−1 Z j .

Zone-Based Confidence Estimation
The evidence was allocated by the mobility model and the observation model combined to get the confidence C t (.). The confidence level shows the zones based on the accelerometer sensor values.
Based on the accelerometer sensor values, the zone with the highest confidence level chosen is shown in (39).

Pedestrian Dead Reckoning
The zero-velocity information is effectual for the error correction because of the sensor drift and fast accumulation of the positioning error. The velocity and angular velocity are almost zero when the pedestrian's foot is totally on the ground. For that purpose, the PDR system based on HMM and ZVU algorithms is introduced. According to the accelerometer and gyroscope readings, rules are defined based on the threshold for ZVU detectors [92]. This method ignores the sensor measurement fluctuations and uses an instantaneous sample that only gives the precise phase judgment. To recognize the phase, the following is used: Obs = (obs 1 , obs 2 , . . . , obs k ). To determine the observation obs k at k time, stance, and swing phase, two indicators are deployed. The accelerometer measurement is constant in the stance phase, the angular rate approximates to zero, and local gravity is approximately equal to the phase magnitude. Therefore, the observation is defined as obs k = Z 1 ∧ Z 2 , whereas where obs k = [0, 1], TH 1 and TH 2 are thresholds. Thresholds are set empirically based on Z 1 and Z 2 calculated from the static test. To classify the observation into stance and swing, a long series of observations are given. To yield better recognition, the HMM is adopted, and to represent stance and swing, we use two HMMs, respectively. The calculation of the observations under each model and their conditional probability from the given observation sequence suggests the walking phase is the maximum probable model. For each HMM, the hidden state is assumed binary s = [0, 1]. The output probability distribution d, which is B = b j (k) and state transition probability distribution A = a ij are the two elements.
and HMM is defined as = (A, B), and the parameters A and B are determined by using [57]. Partial observation sequence obs 1 , obs 2 , . . . , obs t , being in state i at time t, and the forward probability is the probability of the HMM and it is shown in (43) as below, µ t (i) = P(obs 1 , obs 2 , . . . , obs T , |s t = i, ) From t + 1 to the end, backward probability is the partial observation sequence probability, obs t+1 , obs t+2 , . . . , obs T , given the state s t = i and the model threshold.
Given an observation history Obs and HMM n to find new values of n+1 , such that probability P Obs n+1 ≥ P(Obs| n ). From the state i we estimate the expected number of transitions based on the changing values of accelerometer sensor values as ∑ T t=1 λ t (i) and ∑ T−1 t=1 κ (i, j) from state i to j. The complete derivation procedure to estimate the new model parameters in the last step can be found in [77]. The algorithm for the observation sequence-the maximum probable model as the walking phase having estimated parameters of HMM. arg max k P( k |Obs) where k = 0or1. Here, 1 represents the stance model, and 0 represents the swing model. By using the following equation during the swing phase, the velocity v n and the position p n are estimated by using the HMM-based ZVU algorithm.
velocity n k = velocity n k−1 + acc n k ∆t (46) position n k = position n k−1 + velocity n k−1 ∆t + 1 2 acc n k ∆t 2 (47) The sampling interval of the inertial sensors is t and g n and the gravity vector in inertial navigational frame {in f } is g n .

Compensation Mechanism Based on AWCLA
In the case for the compensation mechanism based on AWCLA, we used iBeacon Estimote version Bluetooth 4.0 smart as a fixed device, and its detail is mentioned in Table 4. A 32-bit ARM® Cortex M0 is a small computer accompanied by a temperature sensor and accelerometer. Bluetooth low energy beacon uses ultra-high 2.4 GHz radio frequency. The CR2477 battery power source is used to power the BLE estimate for three years if used in the default condition. The range of the ideal Beacon is around 70 m, and in an indoor environment where signals can interfere, diffracted, or be absorbed by the walls and human body, the range is reduced to 30-40 m. The iBeacon sent information in an advertisement packet containing RSSI values, advertising intervals, measured power, and broadcasting power.  Figure 5 shows the distance computation between the object and Bluetooth low-energy beacons, which is used for calculating the position of an indoor object. Received signals from the beacons are used for the calculation of distance. To smooth RSSI signals, we used the proposed KF process and measurement model. The distance computing model and approach for RSSI estimation are presented. The distance output from iBeacons and the received RSSI measurements have suffered from high distance errors and high noise levels in the indoor environment. Various localization algorithms have been proposed to decrease the position error and enhance the accuracy when using the distance values based on the beacon output signals. However, still, the error is too high, and the localization accuracy is low. In this paper, indoor positioning accuracy and the distance error were improved using the proposed enhanced PDR-BLE compensation mechanism based on HMM and AWCLA for improving indoor localization.

Path-Loss Model-Based Measuring Distance
The nature of the medium and the distance are factors that cause an attenuation when wireless signals are transmitted. The signal is reflected, diffracted, refracted, and scattered when experiencing objects during transmission. In the case of LOS or NLOS, direct attenuated signal is due to other physical effects and indirect attenuated signals such as refraction, reflection, scattering, and diffraction [93]. In the simplest path loss model, there is no multi-path components and signal strength decreases by 1 d1 .The amount of power transmitted compared to the power received is calculated using Friis free space equation [94].
The path loss is expressed in dB and it takes place exponentially with distance as shown in Equation (49) The relation between distance and RSSI in [80] can be described by the log-distance path loss model.
The above equation can be rewritten as: where, the strength of the transmitted signal is Tx s . The process model for smoothing RSSI using the Kalman Filter is shown below in Equation (52): The relationship is modeled through matrices A and B, and it is among the control unit, current state, and previous state. At time step t, the state of interest is x t+1 , whereas the previous state is x t−1 , w t is the process noise, and the control input is u t . The KF based observation model is expressed as: where, at time step t m t is the measurement , the transformation matrix is represented as T, and noise measurement is v t . Likewise, the steps update and prediction based on the Kalman filter are as followŝ We define RSSI signals as the state of interest x t . For certain time frames, the mobile and position are set as static; hence, the RSSI measurements in that time frame remain constant, and the rest of the parameters are taken as process noise. The model can be constructed by setting A to an identity matrix and ignoring control input u t .
The RSSI estimation is computed in three steps.
Step 3: rssi m = Tx t + V t , observation are designed by using the received RSSI measurements and the relationship between the state of interest. For the state of interest updates and the KF, we use a time step from t − 1 to t, variance from the time step t − 1 to t, and Kalman Gain (KG).

Position Estimation Using Beacon Weights
To find the mobile position the centroid location algorithm uses, while using the weight of each Beacon, the weighted centroid location WCL estimates the mobile location. In this paper, we explored the Beacon's importance in terms of weight to estimate the mobile position based on CLA by using the deployed beacons. The accuracy of the centroid localization algorithm is poor, so different modifications are proposed to decrease the position error. To improve the object's position, the proximity between the mobile devices and the Beacons are considered in terms of weights for each beacon. The relationship between the weight and distance is directly proportional, while the impacts of propinquity between the mobile devices and the beacons are inversely proportional. Based on (59), the value of Beacon weight is calculated using equation where the estimated distance between the mobile device and beacon is denoted by d ij and the adjustable degree depends on the environments, and it is referred to g. To estimate the unknown mobile position, the weighted centroid localization algorithm uses Equations (60) and (61) based on the known Beacon position.
Herex,ŷ are the estimated x and y coordinate. The weight of each Beacon calculates using the signal power per Equation (62) Calculations of smartphone locations in indoor surroundings based on KF, which integrates the smoothed RSSI measurements based on the beacon weight. In the proposed algorithm based on KF, RSSI measurements are pre-processed and integrated. The proposed beacon-based localization eliminates noise and smooth RSSI values. By using the estimated filtered RSSI values, the distance between the deployed beacons and smartphones is calculated. The strength of the received RSSI signal is directly proportional to the power delivered to the beacon. The calculation of the actual distance between the deployed beacons and smartphones by using centroid points of beacons.
The error in distance is calculated using equation d n = d n − dactual n (n = 1, 2, . . . , m). The position error between the BLE beacon and smartphone is denoted by dn. The estimated smartphone coordinates are calculated using weights of BLE beacons, and the average of the BLE beacons used to calculate the position. The estimated position of the smartphone is calculated as follows.
Figures 6 and 7 shows the activities performed by an object in an indoor environment. In Figure 6, various performed activities are shown, which include working on a computer or idle activity, running activity, walking upstairs, walking on a plain surface, and writing on board. The change in the magnitude of accelerometer sensor values clearly illustrates the activities start and end times. It also shows how the change in the frequency also changes as the change in activity occurs. The high magnitude and high frequency in activity writing onboard show the frequent movement of the test object in an indoor environment.
On the other hand, Figure 7 demonstrates the raw data information obtained from the IMU smartphone-based sensor.

Development Environment
Experiments were conducted on a Windows PC with 12GB RAM. A front end (desktop application) was developed using Java, and the clustering techniques were applied in python. Well-know python libraries, including NumPy, SkLearn, and Scipy, were used for clustering experiments. In addition, NCSS was used for the visualization of data in PC. Furthermore, the simulation time for acquiring data for every instance was one minute (60 s). The required software and hardware components are listed in Table 5.

Results and Discussion
To validate our enhanced PDR-BLE compensation mechanism based on HMM and AW-CLA for improving indoor localization, the person moves in an indoor environment with a Bluetooth enabled smartphone. The mobile was tested in seven different locations. Actual smartphone coordinates were compared with the estimated positions. Seven Bluetooth low energy beacons with known coordinates named C 1 (x 1 , y 1 ), C 2 (x 2 , y 2 ), . . . C n (xn, yn) (n − 1, 2, . . . 6) placed in the entry and exit points of the fourth floor of Jeju National University, South Korea. To validate our approach, at eleven different locations, the position of the smartphone was calculated. The RSSI values of the BLE-beacon, as shown in the figure, were calculated in the android application. The positioning system in this paper is three-dimensional. In this paper, we considered two floors of Jeju National University engineering building 4. We used a 3D navigation approach to localize object movement in an indoor environment.
By using the Kalman filter in the proposed algorithm, the collected RSSI values were then smoothed, and for position estimation of the smartphone, the weight of each BLE-beacon was used. The figure shows various smartphone and deployed BLE beacon positions.

Error Reduction Using Kalman Filter in RSSI Measurement
To validate our KF approach mentioned in Section 4, RSSI measurements passed through KF to reduce errors. The result of smoothed RSSI values obtained after passing raw RSSI measurements through the Kalman filter from different smartphone locations is mentioned in Table 6. On separate entry and exit points of the floor, the estimated BLE-beacon RSSI values and raw BLE-beacon RSSI values are shown in Figure 8. The smoothed BLE-beacon RSSI values are further used to calculate the distance.  The estimated mobile positions using EPBCM algorithm, the BLE-beacon and PDR is given in Table 7. The combined plotting of EPBCM, PDR, and BLE-beacon-based localization at all tested mobile positions is shown in Figure 9. The EPBCM algorithm shows promising results when compared with other IPS, such as PDR and BLE-beacon-based systems.

EPBCM Algorithm Based Positioning
To validate the EPBCM localization algorithm, six mobile positions were chosen and compared with other estimated positions using different approaches. Figure 10 shows the actual position at six random mobile positions compared to their estimated location using EPBCM, PDR, and the BLE-beacon algorithm. The deviation of position obtained from the proposed EPBCM approach from the actual position is shown in Table 6, along with the coordinates of these locations and their errors.
The measurements of accelerometer, magnetometer, and gyroscope were used to track the position and orientation of an object moving in an indoor environment. Walking down two flights of stairs, trajectory is shown in Figure 11, whereas the count of steps in each flight is 13 steps.
The purpose of showing this result is to evaluate the performance of UKF-based orientation tracking and data collection from smartphone-based IMU sensors. The starting point is the mobile computing lab (MCL) situated on the fourth floor of the JNU, and the ending point is the end of two flights of stairs. However, the exact ground truth cannot be given, but the person's orientation and activity can be determined. Compared to the flat ground, the error in stair walking is more significant. This is due to the fact that the calculations of vertical acceleration in stair walking has to be calculated for this scenario and it must include gravitational acceleration.   In this experiment, several pedestrian walking experiments were conducted in the engineering building of JNU, and the final results are shown in Figure 12. In addition, walking experiments were conducted to assess the performance further, and the smartphone's position was compared with the various reference points at the path of the test subject. Figure 12a shows pedestrian walking experiment conducted on the fourth floor of Jeju National University. It is clearly seen that the localization trajectory based on the proposed EPBCM algorithm follows the ground truth values. Figure 12b shows the complete round trip foot trajectory of walking along a corridor, walking down two flights of stairs, containing multiple turns, and the total distance covered is around 220.35 m. The trajectory computed with the proposed algorithm is compared with the PDR localization algorithm and actual trajectory. The proposed localization algorithm shows a clear decrease in the drift from the actual path as compared to the PDR. To quantify the positioning accuracy, we adopted the maximum error and end-to-end error. For the evaluation of the proposed algorithm, we implemented three algorithms EPBCM, PDR, and BLE. EPBCM incorporates accelerometer magnitude HMM-based detection, and the other two are PDR and BLE-beacon-based localization algorithms.

Conclusions
In this study, an EPBCM based localization algorithm was developed to estimate the position of an object in an indoor environment. The proposed system is a combination of two localization algorithms-PDR and BLE-beacons. In the proposed position estimation module, orientation is estimated using the unscented Kalman filter and HMM-based activity detection by considering the varying measurements of the accelerometer sensor. In this paper, the BLE-beacon-based localization algorithm is used as a compensation algorithm. In this compensation model, the path-loss model is used for distance measurement. The Kalman filter is used for noise elimination, smoothing RSSI measurements, and integrates raw BLE-beacons measurements to reduce the positioning error. The position estimation combinator is designed to combine the position coordinates of the two localization algorithms and get the enhanced position, containing less error. For comparative analysis, we compare the HMM-based activity detection approach results with the K-mean clustering technique. We also compare the three localization algorithm results, showing the proposed indoor positioning system containing the least error. It also shows that the proposed algorithm deviation from the actual location is the minimum. The walking scenario experimental results show that the proposed EPBCM based on HMM and AWCLA is feasible for the indoor positioning system. At some points, the positioning error is tiny, although to maintain a high accuracy level, more beacon deployment must be required to get more compensation in error at different mobile locations.