A Robust High-Accuracy Ultrasound Indoor Positioning System Based on a Wireless Sensor Network

This paper describes the development and implementation of a robust high-accuracy ultrasonic indoor positioning system (UIPS). The UIPS consists of several wireless ultrasonic beacons in the indoor environment. Each of them has a fixed and known position coordinate and can collect all the transmissions from the target node or emit ultrasonic signals. Every wireless sensor network (WSN) node has two communication modules: one is WiFi, that transmits the data to the server, and the other is the radio frequency (RF) module, which is only used for time synchronization between different nodes, with accuracy up to 1 μs. The distance between the beacon and the target node is calculated by measuring the time-of-flight (TOF) for the ultrasonic signal, and then the position of the target is computed by some distances and the coordinate of the beacons. TOF estimation is the most important technique in the UIPS. A new time domain method to extract the envelope of the ultrasonic signals is presented in order to estimate the TOF. This method, with the envelope detection filter, estimates the value with the sampled values on both sides based on the least squares method (LSM). The simulation results show that the method can achieve envelope detection with a good filtering effect by means of the LSM. The highest precision and variance can reach 0.61 mm and 0.23 mm, respectively, in pseudo-range measurements with UIPS. A maximum location error of 10.2 mm is achieved in the positioning experiments for a moving robot, when UIPS works on the line-of-sight (LOS) signal.


Introduction
Satellite signaling systems are universally well known. One example is the global positioning system (GPS), which has a high positioning accuracy at 0.15 m [1]. It is very convenient to use satellites to obtain locations. Unfortunately, satellite positioning signals normally cannot be received indoors due to obstructions from buildings, and people have to do most of their work (an estimated 87 percent overall) indoors [2].
Because of the reasons outlined above, indoor positioning systems (IPSs) have gained increasing attention from researchers across the globe in the last few decades, as IPSs are widely used in health-care as well as in home and building automation [3][4][5][6]. There are already many local positioning systems based on different technologies, and they each have their own advantages and weaknesses. Systems based on infrared beams make use of the scanning sweep method and are very inexpensive for users, but only have accuracy up to 57 cm [7]. Xiaohan Liu et al. [8] developed an IPS using a visible light communication platform, which has an accuracy of 10 cm, but it requires expensive infrastructure. when all distance measurements are finished. The coordinates for the mobile robot can be calculated by the server when the distance values to all anchors in the same moment are received. The server can forward these coordinates on to users (robots here). There can be two work modes to transmit the ultrasonic signal: the first one is from the anchor nodes to the robot, shown in Figure 2a, and the second is vice versa, as shown in Figure 2b. We assume that the number of the anchors is N 1 (N 1 > 3), and the number of robots is N 2 (N 2 > 0) in a coverage area. Every anchor will send the ultrasonic signal separately at a different time, presented as t 1 , t 2 , · · · in Figure 2a. Thus, the signal interference between different anchor nodes is avoided when the time synchronization signal (TSS) arrives in the first work mode. There is some time drift between different anchors, for which there must be a compensation algorithm, but it is very complex, and the accuracy is not high. The advantage with this mode is that it needs only one TSS for positions of all robots, and saves power. If just one anchor transmits the signal in a TSS in order to void the compensation for time drift, there needs to be N 1 TSSs for all robots, but the position will have large errors in both methods above when robots are moving. Because the measurements for the distances to all anchors are finished at different times, the position coordinates can only be calculated roughly through these distance values.
In the second work mode, the target nodes transmit the ultrasonic signal to the anchors, selected by the UIPS in this paper. Only one robot sends the signal that will be received by all anchors at the same time when the TSS for it arrives, and then the distances to all anchors are measured. The ultrasonic signal pulse is just 1 ms, which will be described later in this article. There is a reasonable assumption that the position for the moving robot will not change in so short a time, so this mode can be appropriate for mobile robot localization, although it needs more TSSs (N r ) for all robots. The information from the time synchronization node contains a robot address. The robot with this address will send the ultrasonic signal, and the remaining ones will not. The anchors distinguish the ultrasonic signals from each other with the address. The time synchronization node will cyclically transmit TSS to every robot in turn, so the resolution for UIPS will reduce when N r grows larger.

Ultrasonic Envelope Detection
Ultrasound is a vibration wave, for which the amplitude will increase when it arrives at the peak. There will be a reducing process while the signal drops to the minimum amplitude value from the peak value. If the driving signal for the ultrasound is cut off immediately when the peak arrives, the signal will have a unique wave peak. The signal for this means can be described by Equation (1) [28].
where the parameters A(t), f c , and θ(t) are the signal amplitude, frequency, and phase, respectively. A(t) is also the envelope signal and is given by: where β is the amplitude parameter, and α is the bandwidth factor. We can see that A(t) will obtain its maximum value when t = τ from the equation. The original ultrasonic signal x(t) from the received transducer is shown in Figure 3a, and the envelope A(t) is presented in Figure 3b. The ultrasonic envelope detection aims to extract A(t) from x(t). We consider that the time when the ultrasonic envelope arrives at its peak is the arrival time of the ultrasonic signal. That means the TOF for the ultrasonic envelope is τ in Equation (2), if t = 0 is the start time for transmission of the signal. A rectangular window function w(t) with a length of N is defined as Equation (3). It will become w(t − T), w(t − 2T), and w(t − 3T), · · · , when the function is moving with a step of T, as shown in Figure 3c. T is the sampling period for the ultrasound signal.
x(t) of the length of N · T is selected in every window, when x(t) multiplies the window function.
The maximum value The digitalized values x(n) are provided by the analog to digital converter (ADC) from x(t) with a sampling rate of f s (1/T), given by: x(n) = A(n) · sin(w c nT + θ(n)) (4) = A(n) · sin(w c nT)cos(θ(n)) + A(n) · cos(w c nT)sin(θ(n)) = sin(w c nT)cos(w c nT) A(n)cos(θ(n)) A(n)sin(θ(n)) where A(n) and θ(n) stand for the amplitude sampling value of the envelope and the phase angle at nT time, respectively, and w c = 2π f c . If the window function w(t) is discretized into w(n) with the same frequency f s , and we can get Equation (5) in the window i, where j = 1, 2, · · · , N and i = 0, 1, 2, · · · . Because the value of N · T is small, at just 0.05 ms in this paper (where N = 50 and T = 1 µs), ultrasonic signal is a mechanical vibration, with the characteristic of inertia. Its amplitude and phase have little change in such a short period of time. We can assume that the envelope value A(i + j) and the phase θ(i + j) are constant for all j values in every window i, presented as A(i) and θ(i), respectively, and then we can obtain Equation (6) from Equations (4) and (5), where x(i + 1), x(i + 2), · · · , x(i + N) can be obtained from ADC sampling.
· · · = · · · + · · · x(i + N) = sin(w c (i + N)T) · A(i)cos( θ(i)) + cos(w c (i + N)T) · A(i)sin( θ(i)) Equation (6) is written in the form of a matrix: where the transposes of X i , C i and Ψ i are given by: Now, the problem is transformed into a method to estimate C i of Equation (7). The estimation of C i isĈ i (assumedĈ i = ĉ i1ĉi2 ), and it can be determined using the least squares method for minimizing the following error function between X i and X i ( X i = Ψ iĈi ): We can obtain Equation (12) in order to minimize J(Ĉ i ): and then,Ĉ i is given by: we can getÂ(i) andθ(i), which are the estimations of A(i) and θ(i), respectively, from Equations (9) and (13):

Implementation of Positioning
The received nodes must know the time at which the transmitter node starts to generate the ultrasonic signal. Hence, there must be a time synchronization in these nodes, which is presented in the first part of this section, followed by TOF estimation and positioning.

Time Synchronization
The time protocol of the UIPS is based on reference broadcast synchronization (RBS) [29], which works in the data link layer. The architecture of synchronization for the UIPS is shown in Figure 4.

WSN Nodes WSN Nodes
Reference Node

WSN Nodes WSN Nodes
Reference Node Reference Node Reference Node The whole space is divided into several subspaces, and there is a reference node in every subspace. All anchor nodes of the subspace have a common ultrasonic signal coverage region, and the RBS node will be asked to broadcast the synchronization signal periodically to the anchor nodes and the target nodes by the server, when there are some positioning nodes that walk into the region. The transmitters will start to work, and the received nodes will begin sampling the signal as the synchronization broadcast is arriving.
The process of the transmission for TSS is shown in Figure 5. The central processing unit (CPU) of the reference node will start a timer count when it receives instructions from the server. The timer will generate an interrupt signal and count from zero again while the counter arrives at the TSS period, and then the CPU program will access the interrupt handing, where the synchronization frames are transmitted to the RF module. The frames will be encoded in the RF module and then transmitted to the receivers by the antenna. Receiving and decoding will be completed by the receivers with a reversed order of the sender when the TSS arrives at the receiving systems. Furthermore, the alignment for the received frames is finished and then an interrupt signal is generated for the CPU.  The velocity of the electromagnetic wave is the approximate speed of light in a vacuum, so the propagation time differences from different nodes are quite minor and can be ignored in a subspace. The synchronization protocol based on RBS suffers from the uncertainties of the transmission and reception times, as well as the yield synchronization error, which is about 13 µs [30], and cannot meet the requirements of the UIPS. Several modifications are performed to reduce the error. First of all, the synchronization and other data transmissions have the same communication module as in the other system, but there are two different modules in the UIPS, and the modules will not be occupied by the data transmission process. The interrupt for transmitting and receiving have the highest priority, and will not be terminated by the other interrupt.
As described above, the rest factors for synchronization accuracy are in the RF module. CC2500 is selected as a synchronization module in UIPS, which can provide extensive hardware support for packet handling, data buffering, and burst transmissions [31]. Encoding/decoding, transmitting/receiving, and alignment are affected by the traffic rate of the synchronization module. A testing experiment is designed in order to verify this and calculate accuracy. The reference node transmits eight bytes of synchronization data to the other node. The structure for the data frame is shown in Figure 6.

Address Command
Data Bytes CRC Data Figure 6. The structure for the data frame, CRC: cyclic redundancy check.
The length of the address is two bytes in the figure, and a command is used to distinguish data frames into time synchronization or data transmission. This takes up one byte. The next three bytes are data bits. Because data transmission is completed by WiFi module, the data bits are reserved for future research. The last two bytes are cyclic redundancy check (CRC) bits, which indicates whether the received data has some errors. There are two nodes in the experiment, the data frames are sent once every 200 ms, the receiver will return the data to the reference immediately when the receiving is finished. The time from the beginning of transmission to the end of receiving for the reference node is recorded as t s in the sender. The statistics of 500 measurements for every rate are shown in Table 1. The difference between the maximum and minimum value of t s can indicate the precision of the time synchronization. This brings us to the conclusion that the higher the data communication rate is, the lower the differences are. The difference will be 1 µs when the rate is above 100 kb/s, so the precision of the time synchronization should be less than 1 µs because of one-sided communications in UIPS. The ranging measurement error, resulting from this, is less than 0.34 mm, assuming the ultrasonic velocity is 340 m/s.

Ultrasonic TOF Estimation
The analog-to-digital converter (ADC) of the received nodes starts to sample the ultrasound signal using a sampling frequency f s ( f s = 1 T ) when the synchronization data are arriving. The range of ultrasonic propagation is limited to 5 m in UIPS, so the time it takes to sample the signal is less than 15 ms, assuming the velocity is 340 m/s. The uncertain drift of the crystal oscillator of the received nodes can be ignored in this period. Therefore, the time instant at which the envelope reaches its maximum values (n max ) can be calculated with n max f s . The parabolic interpolation method in which the adjacent samples aroundÂ(n max ) can reduce the TOF estimation (t to f ) error [32], is given by: where n x is the fractional correction term obtained from parabolic interpolation with three samples [27], given by: The phase information at n x can be obtained from Equation (15), and it can improve a greater resolution of t to f . The TOF calculated value by phase is shown in Equation (19) [20], where Int[ ] is the integer operation.

Estimation of Distances and Positioning
The speed of ultrasound v in air depends on many factors. The influence of temperature is only considered in the special indoor condition, and it can be estimated with Equation (19) [33], where φ is the temperature in degrees Celsius, v = (331.3 + 0.6φ) m/s Then, the distance d i between the target node and the anchor node i can be estimated with t to f and v as: The coordinate of the anchor node i is (x i , y i , z i ), and it is assumed that the number of the anchor nodes is k. The coordinate of the target node is (x, y, z). Then, these equations are obtained as: where the left and right equations are subtracted from the first and second equations, respectively, and the equation is expressed in matrix form as: where A, x and b are referred to as: . .
The close solution of Equation (22) for x can be obtained by using the least squares method from Equation (26) [27].

Implementation of the UIPS
The implementation of UIPS is based on embedded system design. A 32-bit ARM Cortex TM -M7 microprocessor is selected as the hardware, which features a single floating point unit (SFPU) and supports single precision data processing instructions and data types. The software is programmed in a bare metal machine in which the registers of hardware can be read or written directly. The real-time performance of the system is strengthened significantly.

Hardware
The node hardware of UIPS is designed for the core board with a size of 90 mm × 58 mm, shown in Figure 7. The core board is powered by a lithium battery (LB), which can be charged for reuse. It can be configured as a receiver anchor node and arranged in the interior ceiling. The specified extended board for the core board that is configured as the transmitter node can be used to control the mobile robot. The microcontroller unit (MCU), the transmitter and receiver for ultrasound, the CC3200 and CC2500 modules, and the power system comprise the hardware system of UIPS, which is shown in Figure 8. UIPS has two STM32F722RCT6 32-bit MCUs, which have a running frequency up to 216 MHz and come from STMicroelectronics (http://www.st.com); one is the master, and the other is the slave with alternate sampling and calculation. This MCU integrates 512 Kbytes Flash memory with protection mechanisms and 256 Kbytes of static random access memory (SRAM) on chip. It has an abundance of peripheral resources and interfaces, such as a 12-bit ADC, a digital to analog converter (DAC), a timer that can produce the pulse width modulation (PWM) signal, universal synchronous or asynchronous receiver transmitters (USARTs) and a direct memory access (DMA) channel [34]. The signal strength of the ultrasonic transmitted transducer with a frequency of 40 kHz is too low to be sampled by the ADC directly, so it must be amplified firstly, and then processed by a band-pass filter to reduce the out-of-band noise. The ultrasonic received sensor can be driven by the PWM orsinusoidal signal, which can be generated by DAC. The former is adopted in UIPS. It can be obtained from the timer with high precision.
The CC3200 [35] module communicates with the master MCU by USART, which can realize the transparent data transmission between the master and the server via the WiFi wireless network. The CC2500 module is used for time synchronization and communicates with the master MCU through the SPI interface. Besides, the module is linked to the master MCU via an input/output (IO) port in hardware.

Software
The implementation of the algorithm for envelope detection in Section 2.2 requires a large number of matrix calculations using Equation (13), but some regularity can be found if Equation (10) is plugged into Equation (13). The elements of Ψ i will be periodic and constant if the length N and sampling period T are constant, so all (Ψ T i Ψ i ) −1 Ψ T i will also form a series of periodic coefficients. The coefficients in only one period are enough for the implementation of the algorithm, and are computed in advance using MATLAB and are written into the read-only memory (ROM) of the MCU in a table form. The computational complexity of the algorithm can be reduced significantly.
There are rich DMA channels and interrupt vectors on the MCU chip, with which the real-time and reliability performance of the software system can be enhanced. There is a joined IO port between the CC2500 module and the master MCU as described above. The module will produce a rising edge pulse signal when the time synchronization data come, which makes the software of the master go into an external interrupt vector with the highest priority of all. The system will have an alternating sampling and detection between the master MCU itself and the slave MCU, shown in Figure 6. The master will turn on the DMA channel and enable the timer to trigger the ADC for ultrasound signal acquisition with rate f s if it is time for the master itself. The software will run into the DMA interrupt service program when all M pieces of data are collected.
The envelope detection method presented in Section 2.2 is implemented in the DMA interrupt service program and then calculates the distance value from the target node to the anchor node; The value will be transferred to the server through the WiFi network. The slave MCU will obtain the distance value like the master in the external interrupt program if it is its time, shown in the red dashed rectangle of the figure, and then transfer the value to the master through USART; finally, the master transfers it to the server. The whole software flow diagram is shown in Figure 9.  Figure 9. The software architecture and flow diagram of the UIPS receive node. DMA: direct memory access. IO: input/output.

Experiments
A simulation experiment using MATLAB is described to prove the validity of the envelope detection method in this section, meanwhile, the point-to-point ranging and the position for the mobile robot are presented to validate the UIPS's performance.

Simulation
The analog ultrasonic signal and its envelope are generated from Equations (1) and (2) in Section 2.2, which only has a peak, as mentioned earlier. Noise is inevitable in any practicable system, so the white Gaussian series are added to the signals with a different signal-to-noise ratio (SNR) in order to test the filtering effect of the algorithm in Section 2.2. The Hilbert transform (HT) is widely used for envelope detection in engineering [36], by which the ultrasonic envelope is also extracted for comparison with the method in this paper. The results are shown in Figure 10. The envelope detection method based on LSM can detect the envelope of ultrasound with a high precision, comparing (a2) and (a4) in the figure, and there is no time delay for the peak between them. Filter effect analysis proves that the proposed algorithm can obtain a good filtering result, even if the SNR is very low (as shown from (b) to (d) of Figure 10). The method based on HT can detect the envelope too, but it has no filter effect from the third column on. This can only be achieved by means of some special digit filter. Besides, the HT is more complex.

Applications
The distance measurement experiment is completed to evaluate the accuracy of UIPS. A pair of nodes are at the same level as each other, which can guarantee that the nodes work on the LOS condition, avoiding interference for ultrasonic multi-path propagation. One is configured as the transmitter, and the other node as a receiver. The transmitter sent a PWM of 1 ms under the control of the time synchronization signal with a period of 200 ms. The ultrasonic signal completely disappears in such time, so that the influence of the last cycle will be avoided.
A commercial vision-based localization system (vicon) from Oxford Metrics Limited (www.vicon.com) is used to measure the separation between nodes, which has a precision of 1 mm. Firstly, some optics markers are planted around the ultrasound transducer symmetrically, shown in Figure 11, so that the position coordinates of two nodes can be obtained from the vicon system. They are (x 1 , y 1 , z 1 ) and (x 2 , y 2 , z 2 ), and the distance is: Transmitter node Received node Figure 11. An illustration of the distance measurement between two nodes.
Eight group distances are measured, which have some random bits. The quadrature sampling (QS) [27] is achieved by UIPS to compare the method based on LSM in this paper. The statistics are shown in Table 2, whereX is an average of 500 times of measurement for each distance, var is their variance, and |E| max is defined as: where v max and v min represent respectively the maximum and minimum in all 500 measurements. |E| max can reflect a certain accuracy of UIPS. We can see thatX error is less than 1.5 mm with the reference distance for two methods. The highest |E| max and var can obtain values of 0.61 and 0.23, but they will increase with distance. This is because of the influence of noise when the ultrasonic signal becomes weakened, and the SNR is smaller. |E| max and var in LSM are smaller than those in QS in all groups, so the method based on LSM has a higher accuracy and robustness.
The localization experiment for the mobile robot is performed in order to test the system function. Four anchor nodes are placed at a fixed position, which are configured as the receiving end, shown in Figure 12. Here, the coordinates of the anchor node are obtained from vicon as above. They are, respectively: (−115.79, 1004.64, 1501.64 Anchor node 2 Anchor node 1 Anchor node 4 Anchor node 3 Robot Figure 12. An illustration of the positioning experiment for the mobile robot.
The motion with open-loop trajectory for the robot is a standard circle, which starts from different positions with various radii. There are also some optics markers around the ultrasound transducer of the node on the robot, so the trajectory can be obtained from vicon. The mobile robot will transmit the ultrasonic signal in each 200 ms cycle as with the distance measurement. The signal is transmitted with LOS in order to overcome the multi-path case, additionally, a short ultrasonic signal pulse, just 1 ms in this paper, can reduce interference for ultrasonic multi-path effect [37], so it is ignored here. The robot moves with a very low speed in the common coverage areas, so the Doppler effect of ultrasound is ignored in this experiment.
Four experiments are conducted with different radii in total, and the trajectory tracking results are shown in Figure 13. The position data sampling rate from vicon is much greater than that of UIPS.
We can see that the UIPS can follow the tracks of the robot with a maximum error of 10.24 mm. The error is 12 mm when the same experiments are completed though quadrature demodulation [38] with the same sampling frequency f s . |E| m is used to represent the maximum error in this paper, and is defined as: |E| m = (x m − x r ) 2 + (y m − y r ) 2 + (z m − z r ) 2 (31) where (x m , y m , z m ) is a position from UIPS, which deviates furthest from the vicon reference. (x r , y r , z r ) is from vicon, because vicon is not in time synchronization with UIPS and has a much higher sampling frequency for positioning data than that of UIPS. (x r , y r , z r ) is the nearest point to (x m , y m , z m ) in all cases.

Conclusions
In this work, we present a new envelope detection method for the ultrasonic signal and develop an indoor position system based on this method, which can be also applied to other fields. Filter effect analysis from simulation proves that the method is effective. The system can fix a continuous position on the mobile robot with high and robust stability. We also present an improved time synchronization method based on RBS in the UIPS, which has an accuracy up to 1 µs. Network nodes have individual communication modules using the WiFi protocol, which is used widely in day-to-day life. Therefore, we will integrate the ultrasonic transducer with a mobile phone in the future and realize the precise positioning for personnel using the phone and the UIPS.

Conflicts of Interest:
The authors declare no conflict of interest.