Mean square difference of position, velocity, and orientation estimation between the proposed GPS‐aided SINU system's output with Piccolo II's output.

## Abstract

Kalman filter was pioneered by Rudolf Emil Kalman in 1960, originally designed and developed to solve the navigation problem in Apollo Project. Since then, numerous applications were developed with the implementation of Kalman filter, such as applications in the fields of navigation and computer vision's object tracking. Kalman filter consists of two separate processes, namely the prediction process and the measurement process, which work in a recursive manner. Both processes are modeled by groups of equations in the state space model to achieve optimal estimation outputs. Prior knowledge on the state space model is needed, and it differs between different systems. In this chapter, the authors outlined and explained the fundamental Kalman filtering model in real‐time discrete form and devised two real‐time applications that implemented Kalman filter. The first application involved using vision camera to perform real‐time image processing for vehicle tracking, whereas the second application discussed the real‐time Global Positioning System (GPS)‐aided Strapdown Inertial Navigation Unit (SINU) system implementation using Kalman filter. Detail descriptions, model derivations, and results are outlined in both applications.

### Keywords

- Kalman filter
- real‐time
- navigation
- vehicle tracking
- GPS‐aided‐INS

## 1. Introduction

Kalman filter exists for the past 50 years. It was first introduced by Rudolf Emil Kalman in 1960 [1] and was implemented on the Apollo Project in 1961 to solve the space navigation problem [2]. Kalman filter is claimed to be an optimal estimator [1] due to its ability to optimally estimate the system's error covariance and use the prediction in a recursive manner to improve the system measurements from time to time. As such, Kalman filter was implemented as the estimator in various applications, such as in navigations [3, 4], image processing [5, 6], and finance [7].

One of the uniqueness in Kalman filter is that it consists of two distinct processes, namely, the prediction process and the measurement process. Both processes are combined and operated in a recursive manner to achieve optimal Kalman filtering process [8]. Another uniqueness of Kalman filter is the incorporation of prediction errors and measurement errors into the overall Kalman filtering process. It is common that each prediction and measurement process consists of errors in random nature. These errors or “noise” are normally being described using the stochastic process. On the other hand, a real‐time application can be defined as an application or program that reacts or responses within a predefined time frame, where such predefined time frame is a quantified time using a physical clock [9]. From a real‐time application's point of view, the real world's continuous time is turned into discrete time frame Δ. Different real‐time applications have different Δ, which in turn defined the response time of the applications. The real‐time application must react within the predefined time frame to provide an up‐to‐date response. Such real‐time constraint forced the application to complete its routine within the time frame, else the output may not be accurately reflecting the current state of input [10].

Note that the realization of Kalman filter, in its recursive nature, can be described as a real‐time implementation. In this book chapter, the authors will demonstrate two real‐time Kalman filtering examples. The first example demonstrated the real‐time Kalman filter implementation on vehicle tracking application using vision camera's image processing. A Kalman filtering model is established to estimate the positions and velocities of the moving vehicles and to provide tracking on the vehicles at a normally visible condition [11]. The second example demonstrated the Kalman filter implementation on the real‐time Global Positioning System (GPS)‐aided Strapdown Inertial Navigation Unit (SINU) System or GPS‐aided INU system for Unmanned Aerial Vehicle (UAV) motion sensing. The results obtained from both experiments will be illustrated and discussed in this book chapter.

The outline of this chapter is as follows. Section 2 illustrates the generalized Kalman filter model from real‐time system's point of view. Section 3 outlines the real‐time vehicle tracking system using vision camera. The contents include the elaboration of image processing algorithms, illustration of the Kalman filtering model on the tracking system, result in acquisition, and discussions. Section 4 depicts the real‐time GPS‐aided SINU system for UAV motion sensing using Kalman filter. The contents included the derivation of Kalman filter for the GPS‐aided SINU system, the offline and real‐time implementation of the Kalman filter on the GPS‐aided SINU system, results and discussions, and conclusion. Lastly, Section 5 concludes the chapter.

## 2. Kalman filter

Kalman filtering is a popular technique used to solve observer problems [12] in control engineering [13]. Numerous derivations of the Kalman filter model can be obtained from various researchers’ works [3, 8, 12, 14, 15], where detailed elaborations and explanations of the Kalman filter, which included the derivation of the prerequisites such as the state space model and random variables, are outlined. Hence, in this chapter, the authors derived and explained the discrete real‐time Kalman filter model from the implementation point of view to ensure readers can understand the idea of Kalman filter from the real‐time implementation angle.

### 2.1. Discrete Kalman filter model

A typical Kalman filtering process is separated into two distinct processes, namely, the prediction process and the measurement process [14]. In general, the Kalman filter prediction model and the measurement model of a real‐time system, expressed in discrete form, are as follows:

where

### 2.2. Kalman filter algorithm

The Kalman filtering algorithm starts from the prediction process by estimating the prediction state based on the derived state space equation. The state space equation, or state transition equation, may differ in different systems. From the implementation point of view, the expression of the prediction state, similar to Equation (1), is outlined as follows:

where *a priori* state estimated at the discrete instant *k*, and *a posteriori* state illustrated at the discrete instant *k* given the measurement *a priori* state *a posteriori* state *a priori* prediction error *a posteriori* estimation error

From Equation (4), the *a priori* prediction error covariance can be expressed as:

From Equation (6), substituting *xk*. Equation (1) and

Because the state estimation error and the process noise error are uncorrelated,

Therefore, Equation (7) can be simplified into:

Equation (9) yielded an important step in the prediction process of the Kalman filtering algorithm in obtaining the *a priori* prediction error covariance using the system's state transition matrix *a posteriori* measurement error covariance from previous estimation

The next stage of the Kalman filtering algorithm is the measurement process. Equation (2) depicts the observation equation, or the actual measurement equation, of the system. The measurement output *a posteriori* measurement

where **K**_{k} is the Kalman gain, and the term

Given the *a posteriori* measurement error covariance, with reference to Equation (5):

Substituting Equation (11) into Equation (12) yielded:

Because the state estimation error and measurement noise error are uncorrelated,

Therefore, Equation (13) can be simplified into:

Equation (15) depicts the error covariance update equation in the measurement process of the Kalman filtering algorithm. From Equation (15), one could obtain the optimal Kalman gain *trace* of *trace* is defined as the sum of the diagonal elements in the matrix. To do so, the error covariance update equation from Equation (15) can be rewritten as:

The mean squared error reflected by the *trace* of the error covariance

where *trace* of matrix and

where

Lastly, substituting Equation (19) into Equation (16) yielded:

where Equation (20) is the simplified version of error covariance update equation expressed in terms of optimal Kalman gain obtained from Equation (19) and the *a priori* prediction error covariance obtained from Equation (9).

In summary, the Kalman filtering algorithm can be summarized and is shown in Figure 1. The prediction process, as shown in Figure 1, covers the prediction of *a priori* state and *a priori* error covariance. The measurement process, on the contrary, covers the calculation of optimal Kalman gain, updating the *a posteriori* estimation state and the *a posteriori* error covariance. Both processes run in a recursive manner, forming the well‐known Kalman filtering algorithm.

### 2.3. Real‐time consideration of Kalman filter

Figure 1 depicts a typical Kalman filtering process algorithm in its recursive form. Notice from the block diagram that the algorithm processed each stage one by one and rewind back to the initial block for the next cycle of processing. From the real‐time perspective, there are certain time critical events that need to be handled within a specific time frame. In this subsection, the time critical events are analyzed and discussed as part of the consideration of real‐time Kalman filtering algorithm.

The pseudo code of the Kalman filtering algorithm is outlined in Figure 2. It is divided into three sections. The first section denotes the system initialization, and it is covered from steps 100 and 101. The second section is the prediction process section, covered from steps 200 to 202. The third and final section is the measurement process section, covered from steps 300 to 310. Note that the second and third sections run recursively.

Figure 3 depicts the timing diagram of the real‐time Kalman filtering algorithm based on the pseudo code illustrated in Figure 2. The following observations are obtained by examining Figure 3:

Δ

*T*_{21}can be defined as the time required for Kalman filter prediction process from steps 200 to 202.Δ

*T*_{32}is defined as the time required for the measurement sensor's data preparation from steps 300 to 305. The time consists of reading the measurement data from the sensors and performs the preprocessing on the data as part of the measurement process preparation. Note that Δ*T*_{32}may be the most time‐consuming factor in Kalman filtering process due to the preprocessing step 302. Depending on the application, the preprocessing of measurement data may require a substantial amount of processing power to complete.Δ

*T*_{43}depicts the time required for the measurement data computation process from steps 306 to 310. Three important parameters were computed within this time frame, namely, the optimal Kalman gain, the measurement states, and the error covariance measurements.The total duration for a single iteration is Δ

*T*_{41}, which is equal to Δ*T*_{21}+Δ*T*_{32}+Δ*T*_{43}. Note that Δ*T*_{41}shall not exceed Δ, where Δ*T*is defined as the fixed time‐step of iteration. In most Kalman filter applications, Δ*T*is normally adopted as the sampling duration of incoming data. If the processing time for a single iteration exceeded Δ, then the next prediction will not be accurate.

## 3. Vision‐based real‐time vehicle tracking system

A vision‐based real‐time vehicle tracking system used vision camera to achieve target tracking [17]. The number of tracked vehicle can be single or multiple. The detection and tracking of vehicles are done through the image processing of consecutive frames of video. Before tracking the vehicles across frames, target detection algorithm such as background subtraction is responsible for isolating the position of the moving vehicles in every frame. The tracking algorithm used the measurements from the detection stage to relate the moving vehicles from frame to frame. However, due to the limitation of performance in the target detection algorithm, it is not reliable to solely depending on the measurements computed from the detection stage. As such, Kalman filtering algorithm can be adopted to compensate the fluctuation and missing measurements whenever the detection stage fails. The missing measurements are predicted based on the center position and velocity of the detected vehicle. An experimental study was conducted on the real‐time vehicle tracking at a road junction. The results showed that the Kalman filtering algorithm is capable of tracking the vehicles even with loss measurements appeared on the scene.

### 3.1. Preprocessing of vision‐based vehicle tracking system

Traditionally, the road traffic monitoring is analyzed based on the data collected from the electronic sensor (i.e., loop detector) and manual observation by the human operator. The integration of multiple targets tracking algorithms in the vision‐based vehicle tracking system offers an attractive alternative with additional potential to collect a variety of traffic parameters [18]. As illustrated in Figure 4, that the vehicle tracking process is the second processing stage in the existing vision‐based traffic monitoring system. The performance of this stage greatly depends on the output from the first stage (i.e., the vehicle detection stage). The frames from the video input are recognized as image sequences and fed into the first stage of traffic monitoring system. Moving vehicles are segmented from the stationary background. Because a moving vehicle is formed by a sequence of images from the consecutive frames, the foreground images are matched and combined into its respective tracked objects.

Background subtraction technique is the most widely used image processing algorithm for moving vehicle segmentation [19]. The basic idea of background subtraction algorithm is to subtract (in pixel‐wise) all consecutive frames from an occupied background frame. As a result, this algorithm can be easily affected by sudden changes in background and illumination. Since then, numerous researches on updating the background image have been carried out to create a more adaptive background model. However, the contribution effort is still not able to perform vehicle segmentation perfectly, which indirectly affects the performance of vehicle tracking. This is where the Kalman filtering algorithm comes into the picture to improve the tracking performance.

### 3.2. Kalman filter model for vehicle tracking system

From the vehicle tracking system's point of view, the Kalman filter is to be designed to have the ability to predict the movement of vehicles in the future video frames. The prediction provides a suitable area for searching vehicles in the future frames. Consequently, it shortens the processing time by excluding the foreground images that is not located in the search area [14]. Besides, it also assists the tracking process in the situations where vehicles are temporarily lost due to failed detection.

In the common road traffic flow, vehicle movements can be sufficiently recorded with an optical sensor (i.e., camera) of 25 frames per second. This is because the changes in displacement of moving vehicles in *x*‐ and *y*‐positions have been monitored to be small and do not show drastic changes, even at the road junction [20]. Kalman filter can be adopted for predicting the position of the vehicle, particularly during the loss of measurement detections. As discussed previously in Section 2.2, the Kalman filter is a recursive model between the prediction process and the measurement process. The prediction model of the vision‐based vehicle tracking system, expressed in real‐time discrete form, is outlined as follows:

with

where *T* and *n* are the sampling instant between image frames and the detected vehicle number, respectively. The predicted error covariance can be calculated as:

where

On the contrary, the measurement model of the vision‐based vehicle tracking system, expressed in terms of real‐time algorithm, is outlined as follows:

where

With Equations (24) to (26), the optimal Kalman gain can thus be derived using Equation (19) followed by the updates of the estimation state variables

### 3.3. Experiments and results

An experimental study was carried out using the Kalman filtering model derived in Section 3.2 for real‐time vehicle tracking. The experiment used the video stream captured from a static camera installed on a pedestrian bridge above the road, somewhere near the Multimedia University, Melaka, Malaysia. The Kalman filtering model is implemented with C++ programming language. The Open source Computer Vision (OpenCV) library [21] is used for the vehicle detection stage using the background subtraction method based on adaptive Gaussian mixture model in OpenCV. The tracking stage is demonstrated with the Kalman filtering algorithm for associating the foreground images with tracked vehicles from the previous frame.

Figure 5 depicts one of the image frames of the experiment. During the experiment, the tracking of vehicle number 8 (Figure 5, left) suffered lost detections due to the imperfection of background subtraction technique. Figure 6 illustrates the tracking results comparison in terms of *x*‐ and *y*‐positions in the image frames for the experiment. Note that there were lost detections in position of vehicle number 8 from frames 190 to 197, as shown in Figure 6. Notice that, despite the loss measurements of vehicle number 8, the Kalman filter algorithm can still provide adequate estimations to the vehicle's positions. Note that, although vehicle number 8 was not moving in a straight line, the tracking process was able to update the prediction according to the computed velocity and acceleration from the measurement model. This result shows that the Kalman filtering algorithm assures the continuous tracking of vehicles, although there are several lost measurements during the process.

### 3.4. Conclusion

This section demonstrated the experimental study of the Kalman filter model for multiple vehicle tracking. The model has incorporated the measurements of center positions of moving vehicles together with the computed velocity and acceleration from the displacement changes in the prediction phase. The tracking results show that the derived Kalman filter model is suitable for tracking multiple vehicles, although measurements are lost in a short period of time.

## 4. Real‐time GPS‐aided INU system

Inertial navigation system, which relied on inertial sensors [22] to operate, existed for the past few decades for navigation applications. The SINU is a low‐cost inertial sensor developed to substitute the high‐cost, high‐performance inertial sensors. High‐performance inertial sensors are commonly being controlled by government regulations, resulting in unattainable of the sensors in civilian applications. On the contrary, the low‐cost, low‐performance SINU sensors can be easily acquired, but its measurement data suffered from various errors [23] that jeopardized its accuracy. Due to this issue, the GPS data are adopted as an external reference source to minimize the SINU's errors through the implementation of the Kalman filter.

A typical SINU consists of three orthogonally aligned accelerometers and three orthogonally aligned gyroscopes that provide direct measurement on 3 degrees‐of‐freedom (DOF) accelerations and 3‐DOF angular velocities. Some SINU consists of extra three orthogonally aligned magnetometers for true north measurement. These measurements, as discussed previously, are not accurate. To increase the SINU's accuracy, the GPS's position data obtained from dead reckoning technique is fused with the SINU data through the Kalman filtering algorithm. The system that used such fusion technique is commonly known as the GPS‐aided SINU system, in which this fusion is known to retain the advantages of both SINU and GPS while discarding the disadvantages [4].

### 4.1. Inertial navigation equations

The GPS‐aided SINU system is supposed to provide outputs in terms of position, velocity, and orientation. However, the direct outputs provided by the SINU are in terms of accelerations and angular velocities. Hence, the inertial navigation equations, or navigation equations, are formulated to describe the relationship between the GPS‐aided SINU system's outputs in terms of the accelerations and angular velocities.

The general form of navigation equations can be derived as follows:

where *navigation frame* (or *n‐frame*), *body frame* (or *b‐frame*) to *n‐frame*, *b‐frame* and the gravitational force in *n‐frame*, *earth frame* [or *e‐frame* with respect to *inertia‐frame* (or *i‐frame*)] projected to *n‐frame*, *b‐frame* with respect to *i‐frame* projected to *b‐frame*, and *n‐frame* with respect to *i‐frame* projected to *b‐frame*. Note that the definition of different *frames* can be found in [4].

### 4.2. Dynamic error model of inertial navigation equations

The navigation equations outlined in Equation (27) served as the ideal equations to calculate the position, velocity, and orientation based on the data measured from the SINU. However, as discussed earlier, the measurement data from the low‐cost SINU contained various dynamic errors that were not reflected in Equation (27). Hence, perturbation process is applied on the navigation equations to acquire the dynamic error equations.

The dynamic error equations, expressed in continuous time, can be elaborated as:

where *p*, *v*, and *e* representing the position, velocity, and orientation, respectively. A full description and elaboration of the Jacobians can be found in [24]. *n‐frame* and three‐dimensional angular velocity measurement in *n‐frame* with respect to *i‐frame* projected in *n‐frame*, *b‐frame* and three‐dimensional angular velocity measurement error in *b‐frame* with respect to *i‐frame* projected in *b‐frame*. Note that both

Equation (28) can be expressed in the state space model as follows:

with

where

### 4.3. Kalman filtering model of GPS‐aided SINU

The Kalman filter prediction stage of GPS‐aided SINU system used the state space model of the dynamic error equations of the SINU to predict the errors. For real‐time implementation, the dynamic error equations stated in Equation (29) are to be transformed into its discrete form as follows:

where

and

where

The observation equations of the dynamic errors, on the contrary, can be modeled as follows:

with

where *n‐frame*. On the contrary,

with

where Equations (36) and (37) represent the orientation measurement vectors. Note that the vector *n‐frame* obtained from the magnetometers, and the operator atan2 represents the four‐quadrant inverse tangent function.

Notice from Equation (35) that there are two different discrete instants described by subscripts *j* and *k*. These two different subscripts described two different discrete instants, with subscript *k* depicts the SINU's discrete instant, whereas subscript *j* depicts the GPS's discrete instant. In most cases, the SINU's sampling rate is much faster than the GPS's sampling rate. This creates phenomena in GPS‐aided SINU system's Kalman filtering process that the filter will need to predict a multiple number of predictions before obtaining a measurement from GPS to correct the errors. Figure 7 illustrates the time operation diagram of the matching of 5 Hz GPS data with the 40 Hz SINU data.

### 4.4. GPS‐aided SINU system design and its real‐time implementation

Figure 8 delineates the operational block diagram of the design of GPS‐aided SINU system. As shown in Figure 8, that the SINU consists of three‐dimensional accelerometers, gyroscopes, and magnetometers that output three‐dimensional accelerations, angular velocities, and magnetic field strengths, respectively. The sampling rate of the SINU is 40 Hz. By combining these data with the GPS data (5 Hz) through the Kalman filtering model, the system is able to compute the estimated position, velocity, and orientation errors, which could be used to improve the overall estimations.

Offline field experiment using a moving car was carried out to verify the performance of the GPS‐aided SINU system before real‐time implementation. The Kalman filtering process is carried out in offline mode to verify the performance of the developed system. Note that, in the experiment, the SINU and GPS data rate are 40 and 5 Hz, respectively. The data obtained from the offline experiment was fed into the Kalman filtering model to obtain the offline measurements. To test the performance of the proposed GPS‐aided SINU system, the same set of offline data was also fed into a conventional GPS‐aided SINU system with no magnetometers. The result obtained from the conventional GPS‐aided SINU system without magnetometers is compared to the result obtained from the proposed GPS‐aided SINU system with magnetometers to verify the performance of the proposed system. From the results of the offline experiment, there is an average difference computed to be 2.84 m between the navigation paths of GPS‐aided SINU system with and without magnetometers. The mean difference between the navigation paths of GPS measurements and the GPS‐aided SINU system with magnetometers is computed to be ′0.173 m. On the contrary, the mean difference between the navigation paths of GPS measurements and the GPS‐aided SINU system without magnetometers is calculated to be ′2.67 m, much higher than the mean difference from the previous calculation. Such results indicate that the proposed system work well in offline mode.

With the success offline implementation on the moving car, the system is now ready for real‐time implementation. Both the GPS module and the SINU are connected to an embedded high‐performance computer (HPC) through RS‐232 for data acquisition and real‐time processing. The embedded HPC used in the system come with an Intel Core™ 2 Duo Processor E7500, 4 GB DDR2 RAM, 40 GB hard drive integrated into Zotac Nforce 9300‐ITX motherboard. Similar to the previous setting, the SINU's data rate is 40 Hz, which is relatively faster than the GPS data rate of 5 Hz. During the data acquisition stage, the embedded HPC acquired one set of SINU data every 25 ms (equivalent to 40 Hz). On the contrary, the embedded computer acquired one full GPS data every 0.2 s (equivalent to 5 Hz). Hence, it is obvious that there is a mismatch of GPS data to SINU data. As shown in Figure 7, when both GPS and SINU data are updated with the newest measurements, the real‐time processing system will proceed with the Kalman filtering process to provide a new update on the error prediction. At the instances where newest GPS data were not available, the real‐time system will compute the error prediction solely depending on the previous error prediction obtained from the Kalman filtering process and the newest SINU measurements.

A graphical user interface (GUI) is developed using Visual Basic software (from Microsoft Corporation) for the real‐time implementation. A total of 31 variables will be saved into the solid‐state hard disk continuously in binary file format. The first nine variables represent the raw data from the SINU, which serves the inputs of the GPS‐aided SINU system. The subsequent 15 variables represent the computed three‐dimensional position, velocity, orientation, acceleration errors, and orientation errors, which serve as the outputs of the GPS‐aided SINU system. The last seven variables are the GPS data. Figure 9 shows the GUI layout and the real‐time experimental results of the developed real‐time GPS SINU system. Figure 9 (top left) indicates the serial ports setting for the SINU and the GPS. An”Operation Start“button is located beneath the serial ports frame. An *X*‐*Y* graph is used to display both the real‐time GPS path in green color line and the real‐time SINU's navigation path in red color line. A group of real‐time parameters could be found below the *X*‐*Y* graph. These parameters included the real‐time updated position, velocity, orientation, and GPS information. The incoming raw SINU data are displayed at the bottom of the GUI. Note that the position plots shown in Figure 9 *X*‐*Y* graph are the results from one of the field experiments conducted in Kampung Seri Pantai, Mersing, Malaysia. In this experiment, the GPS‐aided SINU system is installed inside an UAV for motion sensing. The navigation path of the UAV, in GPS data, is shown using the Google Earth in Figure 10. The duration of the experiments was approximately 50 min. The recorded average flight speed was 145 km/h.

Figures 11 and 12 illustrate the results obtained from the real‐time experiment, with Figure 11 depicting the real‐time velocity plot and Figure 12 depicting the real‐time orientation plot. The motion sensing results are compared to the UAV's onboard Piccolo II Autopilot Navigation System [26] outputs. Note that the Piccolo II Autopilot Navigation System is a high‐performance, commercial‐grade navigation system for UAV autopilot. The mean square differences of position, velocity, and orientation were computed between the developed system and the Piccolo II system and the comparison results are outlined in Table 1. Such results indicate that the low‐cost GPS‐aided SINU system achieved a comparable, adequate performance when compared to a high‐performance, high‐cost system.

Mean square difference | |
---|---|

Position (m) | 0.3081 |

Velocity (m/s) | 0.0077 |

Orientation (°) | 2.5930 |

## 5. Conclusion

This chapter illustrated the real‐time implementation of Kalman filter in two applications, namely, the vision‐based vehicle tracking system and the GPS‐aided SINU system. The Kalman filtering algorithm was derived with the consideration of real‐time element. Detail illustrations on deriving the Kalman filtering models for the vision‐based vehicle tracking system and the GPS‐aided SINU system were outlined and discussed. Both implementations were put on real‐time experiments, and the results from both implementations were recorded and analyzed. The results show that the real‐time Kalman filtering algorithms work well in the applications.