Design of a TDOA location engine and development of a location system based on chirp spread spectrum

Location based services (LBS) provided by wireless sensor networks have garnered a great deal of attention from researchers and developers in recent years. Chirp spread spectrum (CSS) signaling formatting with time difference of arrival (TDOA) ranging technology is an effective LBS technique in regards to positioning accuracy, cost, and power consumption. The design and implementation of the location engine and location management based on TDOA location algorithms were the focus of this study; as the core of the system, the location engine was designed as a series of location algorithms and smoothing algorithms. To enhance the location accuracy, a Kalman filter algorithm and moving weighted average technique were respectively applied to smooth the TDOA range measurements and location results, which are calculated by the cooperation of a Kalman TDOA algorithm and a Taylor TDOA algorithm. The location management server, the information center of the system, was designed with Data Server and Mclient. To evaluate the performance of the location algorithms and the stability of the system software, we used a Nanotron nanoLOC Development Kit 3.0 to conduct indoor and outdoor location experiments. The results indicated that the location system runs stably with high accuracy at absolute error below 0.6 m. Electronic supplementary material The online version of this article (doi:10.1186/s40064-016-3632-0) contains supplementary material, which is available to authorized users.

to the location engine. The server must effectively manage the configurations of Tags, Anchors, and location engines, such as by specifying the parameters of the location algorithms, initializing the coordinate values of the Anchors, and selecting the necessary algorithm. To simplify the system, our location server was divided into two parts: MClient (interface management client) and Data Server. The Data Server was designed as an information processing center, while the MClient was designed as an information management center able to access the database directly.
The location engine receives the measurements and generates the ultimate location results, as well as the coordinate values of the Tags with the location algorithms in realtime. Detailed TDOA location algorithms provided by Chan et al. (2006), Foy (1976) and Li and Liu (2005), and data smoothing methods were coded into the location engine using programming language C++. The location results are sent to the server again and stored in a database, then location results are displayed in real-time on the Mclient in graphic form. The main software framework is shown in Fig. 1.

Design and implement of location engine
The communication network protocol between the location engine and the data server is TCP. The necessary algorithms were derived according to the Anchor coordinates and algorithm parameters, then TDOA measurements were input into the formulas to produce location result outcomes. The Location Engine is tasked with sending these results to the server. To improve the computational efficiency, the Location Engine caches additional data (Anchor coordinates and algorithm parameters). A specific calculation process including a TDOA measurement smoothing method based on Kalman Filtering, a cooperative localization method based on Kalman algorithm and Taylor algorithm was built to ensure precise and real-time results.

TDOA positioning principle
Again, the TDOA model measures the differences in times at which signals from the Tag directly or indirectly arrive at multiple Anchors; the TOA model only measures the time at which the signal arrives at one Anchor from the Tag. Anchors are devices placed at fixed sites with known coordinate values, while the coordinates of Tag devices must be estimated according to the anchor values and measurements. The measurement accuracy of TDOA depends on two factors: Accurate recording of the arriving time, and clock synchronization accuracy between the various Anchors. Measurements are then used to establish a hyperbolic model and to estimate the Tag coordinates. The hyperbolic model of TDOA is more complex than the circle model of TOA, accordingly, as depicted in Figs. 2 and 3. TOA Fig. 1 Software framework of proposed location system obtains measurements as the signal propagation time between Tag and the ith Anchor, then the distance rth between the Tag and the ith Anchor can be calculated as follows: where v represents the speed of light. TDOA returns the measurement t ij , i.e., the time difference of the signals arrival at the ith Anchor and jth Anchor from the Tag. The distance difference r ij can be obtained as follows: Figures 2 and 3 show where the TOA model obtains the Tags location by finding n(n ≥ 3) circles intersections, then the TDOA model obtains the n(n ≥ 4) hyperbolas intersection. There is no sizable difference between TOA and TDOA, but TOA requires clock synchronization between each Anchor and Tag while the TDOA model only requires clock synchronization between the Anchors. TDOA hardware can be more simply and easily implemented, to this effect, than TOA hardware. According to the hyperbolic characteristics, Eq. (3) can be obtained: (1) The Anchors coordinates are known, (x i , y i ) represents the ith Anchors location, and (x 0 , y 0 ) represents the Tags coordinate which which can be calculated via Eq. (3).

Smoothing method based on Kalman filter for TDOA measurements
The Kalman smoothing algorithm is applicable to TOA and TDOA distance measurements. The measurements should meet two conditions: (1) A previous estimated value P k−1 and (2) The time interval T between current point and last point less than the threshold . When these conditions are met, P k−1 can be used as Kalman filter parameters to obtain the estimated value P k . Otherwise, measurements are the necessary parameters to determine P k directly. As discussed in detail below, some results are disturbed severely by NLOS. When this occurs, the state estimated values of P k (assuming at time t k ) will be given up and previous estimated values of P k−1 will be reused in the subsequent iteration. Because the Kalman filter as a linear optimal filtering algorithm can effectively utilize historical data, it also smooths the measurements and effectively reduces error. The following pseudo-code describes the Kalman-based smoothing process:

Cooperative localization based on Chan, Kalman, and Taylor
Chan TDOA algorithms can be utilized to linearize TDOA hyperbolic equations and conduct dual weighted least squares (WLS) to obtain useful results; this yields relatively high accuracy if the noise error is in Gaussian distribution. Taylor TDOA algorithms are recursive, and require an initial estimated value to expand the Taylor series and linearize nonlinear equations, so the calculation load is high (and the results divergent) when there are large initial errors. The EKF lends the Kalman-based TDOA algorithm better dynamic performance. Based on the features of the three different algorithms, we developed a cooperative localization method based on Chan, Taylor and Kalman; three algorithms are used to calculate the location results while setting thresholds for the residual sum of the squares to identify the NLOS error. Per the proposed method, the measured data (smoothed by a Kalman filter) is read first and initial results (x 1 , y 1 ) are obtained via Chan algorithm. The residual sum of squares of the Chan algorithm (Res chan ) are then compared with the first threshold δ 1 . The residual square sum of estimation result (x, y) is defined as follows: where n is the number of Anchors, (x i , y i ) is the coordinate of the ith Anchor, r i1 is the difference in distance between the ith Anchor and the first Anchor (i.e., reference Anchor).
If the first result of the Chan algorithm is less than the first threshold, it serves as the initial value of the Taylor algorithm to obtain a second result (x 2 , y 2 ). Then, the second threshold δ 2 is set for judging the Res taylor (residual sum of squares) of (x 2 , y 2 ), as mentioned above.
Third, there are two necessary conditions remaining for the Res taylor : Whether the Kalman algorithm has been initialized, and whether the interval time is below threshold δ 5 . If both are satisfied, (x 2 , y 2 ) will be the input parameter of the Kalman algorithm to obtain another result (x 3 , y 3 ), or the estimated results (x 2 , y 2 ) will be the initial value of the Kalman algorithm and become the final result. Then, provided there is sufficiently small measurement error, the location results of Taylor and Kalman are close to each other based on these characteristics. (The larger the error, the larger the deviation). Another two thresholds, δ 3 and δ 4 , are adopted to judge two types of inequality and further determine whether the measurement error is too large (Eq. 5). If both threshold conditions are not met, the process returns to the first step to read the measurement and gives up the current step.
where (x k−2 , y k−1 ) is the ultimate estimated result at the time t k−1 . Again, when the estimated results (x 2 , y 2 ) and (x 3 , y 3 ) do not meet the condition of Eq. (5), the next step is given up and the measured value must be re-read. Otherwise, the residual square sum Res kalman of the Kalman algorithm is calculated and the residual weighted method is applied to obtain location result (x 4 , y 4 ) Eq. (6).
In summary, the Chan, Taylor, and Kalman algorithms are used in sequence across the whole positioning computational procedure as illustrated in the following pseudo-code.
The values of the thresholds δ 1 , δ 2 , δ 3 and δ 4 are highly influenced by the accuracy of the historical data and the precision of the location device; when they are appropriate, they reduce the interference of NLOS and improve the location accuracy overall. We conducted several experiments yielding a large amount of measured data which were used to get location results by the three algorithms (Chan, Taylor, and Kalman). δ 1 and δ 2 first determined by the residual sum of squares of the location results of Chan and Taylor separately. δ 3 and δ 4 first determined by the difference value between the mean value of the residual sum of squares of the location results of Taylor and Kalman. Then adjusted the threshold values according to the actual effect. Finally, the thresholds were set by the following principles iteratively and verified according to the accuracy of the (6) x 4 = Res kalman * x 3 + Res taylor * x 2 Res kalman + Res taylor y 4 = Res kalman * y 3 + Res taylor * y 2 Res kalman + Res taylor location results.
(1) δ 1 is set as large as possible to filter the measurements with large error and reduce the calculation amount of the Taylor algorithm.
(2) δ 2 is set carefully to discard the measurements which suffer from excessive NLOS. Otherwise, the accuracy of the whole method would be severely affected.
(3) δ 3 and δ 4 validate whether the measurements meet the necessary criteria, then measurements suffering excessive NLOS are further discarded.

Smoothing method based on moving weighted average for location results
The moving weighted average method can be used to smooth the location result (x 4 , y 4 ) obtained in the previous step at time t k . An abundance of historical data is necessary to smooth the result; the thresholds δ 6 , δ 7 restrict the time and space of said data, respectively, as expressed in Eqs. (7) and (8). The history data (x i , y i ) at time t i must satisfy both.
After securing qualified data, each weighting coefficient is given and the last estimated results (x,ŷ) are obtained via Eq. (9): where (x i , y i ) is the selected historical location result, q i is the corresponding weighting coefficient, (x 4 , y 4 ) is the current estimation result,and q is the corresponding weighting coefficient. The smaller the i value, the closer the historical result (x i , y i ) is to the current estimated result (x 4 , y 4 ) in time and space. This result is then referenced to assign the value of weighting coefficients, which we set to q = 0.5, q 1 = 0.25, q 2 = 0.125, q 3 = 0.0625, q i = 2 −(i+1) .

Design and implement of location management server
The location management server is responsible for storing data and managing communications with the Location Engine and Anchor devices. To facilitate server management operations, the location server was divided into two parts according to the pre-established software framework design: Data Server and MClient. Data Server is an information processing center and Mclient is an information management center.

Data server implementation
The Data Server integrates both TCP and UDP network protocol and has two serversides plus a data processing module. The server programs use C++ SOCKET network programming and an event selection (WSAEventSelect) asynchronous I/O model. An information processing module phases the received request data, and a server sends the corresponding response data. The structure of this framework is illustrated in Fig. 4.
As shown in Fig. 4, the data server is defined by two-layers to facilitate management. The bottom layer or so-called Data Communication Layer is mainly tasked with data communication. The top layer, the Data Application Layer, generates response data through a data analysis process which is later transmitted to the Data Communication Layer and sent to the appropriate client according to the response rule. Consequently, the connected objects and appropriate clients can be divided into three categories: (1) MClient (Interface Management Client), (2) LEClient (Location Engine Client), and (3) RawDataClient (Providing Measurement Client). Among them, RawDataClient uses UDP as a communication protocol, LEClient uses TCP, and MClient uses both.
All previously referred data are received by the Communication Layer and processed by the Application Layer. The response data must contain a TCP address and be cached in the Communication Layer. Finally, the location results are received and displayed by MClient; the received data are stored in the database. A flow chart of this process is shown in Fig. 5.

MClient implementation
Mclient is the management center for resource information in the proposed system; it performs data synchronization with the Data Server. MClient interacts with the database and can display location results graphically in real-time. With the interface, administrators can set configuration parameters for each module and manage the system resources efficiently and intuitively. MClient is divided into the following function modules dependent on the type of data: (1) The location information display module, which displays location results in real-time in graphic form. (2) The network address information module, which sets the IP and port of MClient.
(3) The anchor information module, which sets Anchor information (such as Anchor additions, coordinate information, and measurement error). (4) The Tag information module, which operates and monitors Tag information. (5) The location zone information module, which manages zone information (such as map information and work state). (6) The algorithm parameter information module, which sets the algorithm parameters.
Initiating a positioning area to a start position requires two factors: First, that all Anchors in the zone have run and been registered in Data Server; and second, that at least one Location Engine has run. When these requirements are met, one Location Engine is selected as the computing center. A command message containing relevant Anchor information and selected Location Engine information is then sent to the Data server. The Data server detects whether the Anchors and Location Engine are ready; once ready, the Data server runs the corresponding program and readies for location. Location results can be obtained from the Location Engine and sent to the Data Server at the same time. Figures 6 and 7 show images of the MClient interface.

Wireless location test design
The Nanotron nanoLOC Development Kit 3.0 suite (Nanotron Technology) was used to simulate a small zone based on its Location Demo. We built a simulated location system and ran a location test with the Nanotron Location Server and four other parts (the RawDataClient, Data Server, Mclient, and LEClient). We first set up the Location Server and placed the Tag in a fixed position, then ran all programs and set all system configuration parameters according to the physical parameters. After powering on the Anchors and Tag and clicking the start button, MClient sent the ranging command to force the Anchors and Tag to start ranging. Next, each program module of the location system ran concurrently while location results were calculated and displayed in real-time as shown in Fig. 7. We designed both indoor and outdoor location experiments to evaluate the performance of this location system. We compared the location accuracy of five algorithms altogether including Chan, Taylor (where Chan provides the initial estimated value), Kalman, Compared Taylor Method (where a threshold is set for residual square summation to select the result), and cooperative localization method based on Kalman and Taylor (where location results were smoothed). We also evaluated the smoothing algorithm based on Kalman for ranging data in regards to location accuracy. Positioning accuracy, i.e., the error between the estimated position and real position, is the most import criterion for a positioning algorithm. We adopted the root mean squared error (RMSE) and absolute error to evaluate the various positioning methods.

Indoor location test
Four Anchors, Anchor 1 (0.00, 0.00), Anchor 2 (5.65, 0.00), Anchor 3 (5.65, 5.40), Anchor 4 (0.00, 5.40), were placed in a laboratory at Hangzhou Dianzi University 8.3 m × 8.5 m as a small zone within which a Tag was placed in a certain position. This area represents a complex environment through which people move frequently in and out among work tables, computers, and other equipment.
Through statistical analysis of experimental data, the following parameters were set: = 5000 ms, δ 1 = 4, δ 2 = 0.36, δ 3 = 0.14, δ 4 = 0.5, δ 5 = 5000 ms, δ 6 = 2000 ms, δ 7 = 1.5 m; each was based on the measured data and the actual effects of the experiment. was used to smooth the measurements based on the Kalman algorithm to limit the time interval; δ 1 , δ 2 , δ 3 , δ 4 and δ 5 were applied to complete the cooperative localization method based on Chan, Kalman, and Taylor; δ 6 and δ 7 were applied to smooth the results. These parameters were repeatedly set during the experiment until finally being established as discussed above to secure the optimal results. In practice, only TOA ranging data were collected, so an Anchor was set as the reference and TDOA data was obtained via algorithm measurements (Additional file 1).
Tag was placed in six different positions and six sets of ranging data were gathered. Chan, Taylor, Kalman, Compared Taylor Method, and method in this paper were respectively used. Then, location results and corresponding RMSE were given as Tables 1 and 2.
The Tag was placed in three different positions to gather three sets of ranging data, then Chan, Taylor, Kalman, Compared Taylor Method, and Cooperative localization Method Based on Kalman and Taylor were respectively used for comparison. The location results and corresponding RMSE values are provided in Tables 3 and 4.

Comparative experiments
At first, the partial ranging data of the indoor position (3.39, 5.40) and outdoor position (3.00, 4.00) were respectively used to compare the location errors of Taylor and Kalman     To verify whether the Kalman-based smoothing algorithm for ranging data improved the location accuracy and enhanced robustness, partial ranging data of the indoor position (3.39, 5.40) and outdoor position (3.00, 4.00) were investigated: The ranging data were divided into two test groups (those smoothed via Kalman method before being calculated by cooperative localization, and those obtained directly via cooperative localization) while two other groups of location results were smoothed by moving weighted average method. The absolute location error among the groups was compared as shown in Figs. 12 and 13.

Discussion
Tables 1, 2, 3, and 4 clearly show that Chan was less accurate than Taylor/Kalman or the proposed method. Taylor, Kalman, and Compared Taylor had almost the same RMSE, while Taylor/Kalman had smaller RMSE. The RMSE value reflects the bias between estimated and real results; the smaller the RMSE, the greater the accuracy. The experimental cooperative localization results of the cooperative Kalman and Taylor method was highly accurate. The indoor results were worse than the outdoor results due to NLOS. The RMSE of the proposed method was the lowest out of all the location methods, at below 0.6. Figures 8 and 9 show where the cooperative method resulted in absolute error lower than 0.7 m and average error of about 0.5 m, while the absolute errors of Taylor, Kalman, and compared Taylor were close to 1 m in the indoor test. Figures 10 and 11 show where the cooperative method performed better than the other three methods in the outdoor location test as well, with absolute errors smaller than those of the indoor test (slightly below 0.6 m).
As shown Figs. 12 and 13, the Kalman-based smoothing method indeed yielded more stable location results, especially in the outdoor experiment. Furthermore, measured values were smoother and ranging error was smaller after applying the smoothing method. The cooperative localization method not only improved the efficiency, but also further restrained NLOS, yielding higher accuracy overall.

Conclusions
A location system based on the CSS signal and TDOA method was developed in this study. The proposed system is comprised of a Location Engine and a Location Server. To verify its feasibility and effectiveness, we conducted indoor and outdoor experiments in real-time using a NanoLOC Development Kit 3.0. The proposed localization method does not have favorable adaptability, as the parameters δ 1 , δ 2 , δ 3 , δ 4 and δ 5 are not selfadaptive; when the environment changes, these parameters should change as well. However, when these parameters are appropriate for the environment (such as in the test we conducted), the proposed cooperative localization method based on Kalman and Taylor did restrain NLOS effectively while the Kalman-based smoothing algorithm reduced the measurement error and enhanced the robustness of the system on the whole. The next step in developing the proposed method is to improve the parameter selection process to make it better adaptable to different situations. The system program was