You are on page 1of 8

1

Reproduction of Unscented Kalman Filtering of a


Simulated PH System
Optimal Control Exam 2

Arief Barkah Koesdwiady g201001980


Muhammad Fuady Emzir g200903910
Salman Baig g200903690

Abstract—This report presents a reproduction of Unscented random variable (GRV), but is now specified using a minimal
Kalman Filter (UKF) and Extended Kalman Filter (EKF) sim- set of carefully chosen sample points. These sample points
ulation of PH system. To make a comparison two simulation completely capture the true mean and covariance of the GRV,
is carried, one using perfect model, and another using model
with miss match parameter. Contrary with the original work of and when propagated through the true non-linear system,
this paper [2], the superiority of UKF is not clearly seen here captures the posterior mean and covariance accurately to
compared to EKF. the 3rd order (Taylor series expansion) for any nonlinearity.
Index Terms—EKF, UKF, PH system Consider a dynamic system approximated in discrete time as

I. I NTRODUCTION xk = f (xk−1 , uk−1 , vk−1 , k − 1) (2)


State and parameter estimation has been used widely for with a measurement vector
the purpose of control and monitoring. One of the most-
utilized linear estimation methods is the Kalman filter, whereas yk = h(xk , uk , ωk , k) (3)
nonlinear problems may be tackled with the extended Kalman
filter (EKF). The EKF contains several flaws that may se- In the equations above, x is the state vector, u the control input
riously affect its performance. For instance, although the a vector, v the system noise vector, ω the measurement noise
priori state mean may be estimated propagating the nonlinear vector, f (. . .) the process model and h(. . .) the measurement
system directly, the corresponding covariance estimate calls model. A Kalman-type filter consists of two major steps:
for the calculation of the state transition matrix, which, in prediction, in which a new a priori estimate of the state
turn, requires linearization of the system model. This may vector is computed using the system model; and correction,
introduce significant errors if the error in the state estimate in which this predicted estimated is improved using available
is not sufficiently small. Indeed, measurements. This structure also is maintained in the UKF.
However, instead of system and measurement model trunca-
Pk|k+1 = ΦPk|k ΦT + DQk DT (1) tion, the probability densities are truncated.
where Φ is the state transition matrix. The unscented transformation makes use of deterministi-
There are continuous time versions of the Kalman filter where cally chosen sigma points that are propagated through the
the state and its covariance matrix are integrated directly. original nonlinear system equations. Using an appropriate
However, this results in a large system of ordinary differen- weighing scheme, it is then possible to calculate the statis-
tial equations(ODEs) to be integrated. Besides, discrete time tical properties of the propagated point set with the same
formulation is a natural form for implementation in modern performance as the truncated second-order Gaussian filter
digital control and measurement systems. Moreover, the matrix but without the need to calculate the system?s Jacobians or
exponential evaluation is a potentially ill-conditioned opera- Hessians. In the UKF formulation, the system state vector is
tion. augmented,
An enhanced filtering technique that effectively addresses the
aforementioned issues was proposed in the literature; this xak−1|k−1 (xk−1|k−1 vk−1 ωk−1 ) (4)
technique is called the unscented Kalman filter (UKF) method.
and the covariance of the augmented state vector is given by
The ability of the UKF to address discontinuous systems
resulted in a successful application of the UKF to models with Pk−1|k−1 0n×q 0n×r
 
freeplay and hysteresis. Superior performance of the UKF, as Pak−1|k−1 =  0q×n Qk−1 Pvω k−1
 (5)
compared to the EKF, has been observed in communication 0r×n
Pωv R k−1
k−1
systems.
where n is the dimension of the original state vector, and q
II. U NSCENTED K ALMAN F ILTER (UKF) and r are the sizes of the covariance matrices of the system
The UKF addresses the approximation issues of the EKF. and measurement noise, respectively. Pvω ωv
k−1 and Pk−1 are
The state distribution is again represented by a gaussian the correlation matrices between the system and measurement
2

noises. The dimension of the resulting augmented state vector The following equations are typical Kalman filter expressions
is for the measurement update. The Kalman gain is
na = n + q + r (6)
Kk = Pxy P−1
y (16)
Consequently, a set of 2na + 1 symmetric sigma points is
computed: the updated mean of the state vector is
x̂k|k = x̂k|k−1 + Kk (yk − ŷk ) (17)
q

Xk−1|k−1 =[0, (na + K)Pak−1|k−1 ,
q and the corresponding covariance matrix is given by
− (na + K)Pak−1|k−1 ] (7)
Pk|k = Pk|k−1 − Kk Py KTk (18)
where K is a parameter for “fine-tuning” the higher-order
moments of the approximation. For any symmetric prior The aforementioned algorithm describes the ?standard? un-
distribution with kurtosis k, if K is chosen such that scented Kalman filter.
0 < na + K ≤ k , then the predictions of means and
covariances are more accurate than those of the EKF. III. S YSTEM D ESCRIPTION
However, for numerical robustness and computational
The performance of each of the filters was compared by
efficiency reasons, the Cholesky decomposition should be
implementing them on a simulated system that consisted of a
preferred.
continuous stirred tank reactor(CSTR) in which a neutraliza-
tion reaction between a strong acid (HA) and a strong base
As the sigma point set X ⋆ is zero mean, the estimate
(BOH) occurs in the presence of a buffer agent (BX).
x̂ak−1|k−1 ⋆
is added to each sigma point in vector Xk−1|k−1
and the resulting vector of sigma points is

Xk−1|k−1 =[Xk−1|k−1,1 + x̂ak−1|k−1 . · · · ,
a⋆
Xk−1|k−1,2n+1 + x̂ak−1|k−1 ] (8)
The prediction step consists of (i) the mapping of the sigma
point set through the nonlinear system
Xk|k−1 = f (Xk−1|k−1 , uk−1 , k − 1) (9)
and (ii) the calculation of the predicted mean as
a
2n
X +1
Figure 1. Neutralization Process
x̂k|k−1 = Wi Xi,k|k−1 (10)
i=1

where W is a weight vector of size 2na + 1 with elements The state vector is defined as
(
K
na +K (if i = 1) x1 = [A− ]
Wi = 1
2(na +K (otherwise (if i 6= 1))
x2 = [B + ]
The predicted covariance is computed as
X a
and
Pk|k−1 = i = 12n +1 Wi [Xi,k|k−1 − x̂k|k−1 ] x3 = [X − ] (19)
T
× [Xi,k|k−1 − x̂k|k−1 ] (11) where [A− ] ,[B + ] and [X − ] are the concentrations of the acid,
The statistics of the innovation is determined in a similar base, and the buffer agent, respectively. The process model has
manner. The predicted observation is computed as the following form:
Yk = h(Xi,k|k−1 , uk , k) (12) 1 1
(x1,i − x1 ) − x1 qB
ẋ1 = (20)
a
θ V
2n +1
ŷk =
X
a
Wi Yi,k (13) 1 1
ẋ2 = − x2 + (x2,i − x2 )qB (21)
i=1 θ V
and its covariance is determined as 1 1
ẋ3 = − x3 + (x3,i − x3 )qB (22)
2n
X
a
+1 θ V
Py = Wi Yi,k − ŷk [Yi,k − ŷk ]T (14) Kw x3
i=1
F(x, ξ) ≡ ξ +x2 +x3 −x1 − − =0 (23)
ξ 1 + (Kx ξ/Kw )
The cross-correlation between the state estimate and the mea-
surement sequence is where ξ = 10−pH and θ = qVA . The terms qA and qB
X a
represent the inlet flow rates, x1,i , x2,i and x3,i are the
Pxy = i = 12n +1 Wi [Xi,k|k−1 − x̂k|k−1 ][Yi,k − ŷk ]T inlet concentrations of the species and Kx and Kw are the
(15) dissociation constants of the buffer and water respectively.
3

The above expression was rewritten as a third-order polyno- non-linearities of the system’s dynamics are approximated by
mial a linearized version of the non-linear system model around
Kw Kw K2 the last state estimate. For this approximation to be valid, this
ξ3 + [ + x3 + x2 − x1 ]ξ 2 + (x2 − x1 − Kx ) ξ− w = 0 linearization should be a good approximation of the non-linear
Kx Kx Kx
(24) model in all the uncertainty domain associated with the state
from which the value of the output may be derived by estimate.
introducing the following auxiliary variables:
a = 1
Kw
b = + x3 + x2 − x1
Kx
Kw
c = (x2 − x1 − Kx )
Kx
2
Kw
d = −
Kx
b
p = −
3a
3 bc − 3ad Figure 2. Extended Kalman Filter dynamic concept
q = p +
6a2
c
r =
3a The Extended Kalman filter considers, at each cycle, a
Solving for pH, linearization of the non-linear dynamics around the last con-
p secutive predicted and filtered estimates of the state, and for
pH = − log[q + q 2 + (r − p2 )3 ]1/3
the linearized dynamics, it applies the Kalman Filter. One
p 1/3
+[q − q 2 + (r − p2 )3 ] + p (25) iteration of the EKF is composed by the following consecutive
steps:
The above output equation clearly exhibits a very strong 1. Consider the last filtered state estimate x̂(k|k),
nonlinear behavior. 2. Linearize the system dynamics, xk+1 = f (xk ) + wk
around x̂(k|k),
IV. E XTENDED K ALMAN F ILTER 3. Apply the prediction step of the Kalman filter to the
In this section we address the filtering problem in case the linearized system dynamics just obtained, yielding x̂(k + 1|k)
system dynamics (state and observations) is non-linear. With and P (k + 1|k),
no loss of generality we will consider that the system has no 4. Linearize the observation dynamics, y= h(xk )+vk around
external inputs. Consider the non-linear dynamics x̂(k + 1|k),
5. Apply the filtering or update cycle of the Kalman filter to
xk+1 = fk (xk ) + wk
the linearized observation dynamics, yielding x̂(k + 1|k + 1)
yk = hk (xk ) + vk (26) and P (k + 1|k + 1).
where,
V. S IMULATIONS
xk ∈ Rn , fk (xk ) : Rn , → Rn
yk ∈ Rr , hk (xk ) : Rn , → Rr Contrary to ordinary approach in EKF that use Jacobian
matrix to find differentiation of the state and output equation,
vk ∈ Rr here we use the complex step Jacobian to linearise the non-
wk ∈ Rn (27) linear dynamic system. The linearized matrices are then used
in the Kalman filter calculation. [1]
and vk , wk are white Gaussian, independent random processes
with zero mean and covariance matrix Two cases are considered: in Experiment I, the filters have
access to the perfect model of the process, whereas in Exper-
E[vk vkT ] = Rk iment II, the model underestimates the system parameter θ by
E[wk eTk ] = Qk (28) 1%. Although, in Experiment I, the process model is perfect,
the states are corrupted by the system noise and the filters must
and x0 is the system initial condition considered as a Gaussian address this by decreasing the incurred uncertainty by effective
random vector, incorporation of the measurements into the state estimate. The
x0 ∼ N (x̄0 , Σ0 ). (29) relative weight in the final estimate of the a priori estimate,
obtained from the model prediction, and the measurement is
Let Y1k = y1 , y2 , · · · , yk be a set of system measurements. determined by the Kalman gain that, in turn, is dependent on
The filter’s goal is to obtain an estimate of the system’s state the predicted output covariance and the innovation covariance.
based on these measurements. The Extended Kalman filter Because the output equation is non-linear, even in this perfect
(EKF) gives an approximation of the optimal estimate. The case, the unscented Kalman filter produces better results (see
4

Table I) except on state 1 and 2 , although the difference in [2] A. Romanenko, L. Santos, and P. Afonso, “Unscented Kalman filtering
state estimate error is not significant. of a simulated pH system,” Ind. Eng. Chem. Res, vol. 43, no. 23, pp.
7531–7538, 2004.
Experiment II poses a more challenging task, as the model [3] D. Simon, Optimal state estimation: Kalman, H∞ and nonlinear ap-
predictions have a bias, because of the error in the parameter proaches. John Wiley and Sons, 2006.
θ. A possible way of taking into account unmodeled features
or model-plant mismatch is to increase the system noise
covariance artificially. In this respect, this matrix is treated
as a measure of confidence in the process model and not as
the reflection of a system noise characteristic. Nevertheless,
the focus in this work is to expose the filter to the same
consistent information about the stochastic disturbances, and,
therefore, the system noise covariance matrix is maintained,
as in the previous case. Because model predictions contain an
additional error caused by the mismodeling, the measurement
is of greater importance to reduce the overall estimation error.
Now that the UKF is able to predict better the respective
covariances, the resulting state estimates are visibly better than
those of the EKF.
Table I
O PEM -L OOP M EAN S QUARE E STIMATION E RRORS

Method x1 × 10−11 x2 × 10−11 x3 × 10−11 y × 10−4


EKF - I 1.34 1.55 1.47 6.95
UKF - I 1.35 1.56 1.46 4.9
EKF - II 1.57 1.67 1.72 3.41
UKF - II 1.56 1.69 1.72 2.86

VI. C ONCLUSIONS
From several figures and tables above we conclude that both
EKF and UKF had done a good job to estimate the state. For
the first simulations, generally UKF has better performance
than EKF, except that for first and second state, EKF esti-
mation give less MSE than UKF, 1.34 × 10−11 compared to
1.35 × 10−11 for first state, and 1.55 × 10−11 compared to
1.56×10−11 for second state. For second simulation, UKF also
give slightly better performance compared with EKF, except
that for first and second state, EKF estimation give less MSE
than UKF, 1.56 × 10−11 compared to 1.57 × 10−11 for first
state, and 1.67 × 10−11 compared to 1.69 × 10−11 for second
state. This improvement of EKF performance is coming from
the use of the complex differentiation that bring enhancement
to give more precise value compared with ordinary Jacobian.
The original source of this paper has also confirmed the same
fact that for both simulations, UKF give superior estimation
result compared to EKF.[2]. However, what we have seen from
the simulations reveals that although UKF seems give better
performance, but the computation effort to be done its much
larger, in addition that in system we have ẋ is in linear relation
with state. Although the system have high non linearity in
output equation, but from the comparison result, this non-
linearities is not worsen the estimation result of EKF. At the
end, we want to emphasize that, EKF still considerably give
a good estimation here with less computation effort.

R EFERENCES
[1] A. Hjorungnes and D. Gesbert, “Complex-valued matrix differentiation:
Techniques and key results,” Signal Processing, IEEE Transactions on,
vol. 55, no. 6, pp. 2740–2746, 2007.
5

A PPENDIX

x1 State Estimation UKF Vs EKF x2 State Estimation UKF Vs EKF


0.97 0.56
x1 measurements x2 measurements
x1 UKF x2 UKF
x1 EKF x2 EKF
x1 true x2 true
0.96 0.54

0.95 0.52

0.94 0.5

x2 × 103 /mol/L
x1 × 103 /mol/L

0.93 0.48

0.92 0.46

0.91 0.44

0.9 0.42

0.89 0.4

0.88 0.38
0 200 400 600 800 1000 1200 1400 1600 1800 2000 0 200 400 600 800 1000 1200 1400 1600 1800 2000
Time/min Time/min

(a) x1 State Estimation (b) x2 State Estimation

x3 State Estimation UKF Vs EKF Output Estimation UKF Vs EKF


0.7 7
x3 measurements y measurements
x3 UKF y UKF
x3 EKF y EKF
x3 true y true

6.5
0.65

0.6
x3 × 103 /mol/L

pH/-

5.5

0.55

0.5
4.5

0.45 4
0 200 400 600 800 1000 1200 1400 1600 1800 2000 0 200 400 600 800 1000 1200 1400 1600 1800 2000
Time/min Time/min

(c) x3 State Estimation (d) y Output Estimation Estimation


Figure 3. Result of Experiment I Perfect Model Estimation
6

Square Error UKF VS EKF Square Error UKF VS EKF


12 0.14
UKF UKF
EKF EKF

0.12
10

0.1
8
SE x1 × 1011 /L2 /mol2

SE x2 × 109 /L2 /mol2


0.08

0.06

4
0.04

2
0.02

0 0
0 200 400 600 800 1000 1200 1400 1600 1800 2000 0 200 400 600 800 1000 1200 1400 1600 1800 2000
Time/min Time/min

(a) x1 Square Error (b) x2 Square Error

Square Error UKF VS EKF Square Error UKF VS EKF


0.14 70
UKF UKF
EKF EKF

0.12 60

0.1 50
SE x3 × 109 /L2 /mol2

0.08 40
SE y × 103 /−

0.06 30

0.04 20

0.02 10

0 0
0 200 400 600 800 1000 1200 1400 1600 1800 2000 0 200 400 600 800 1000 1200 1400 1600 1800 2000
Time/min Time/min

(c) x3 Square Error (d) y Square Error


Figure 4. Result of Experiment I Perfect Model Error
7

x1 State Estimation UKF Vs EKF x2 State Estimation UKF Vs EKF


0.98 0.56
x1 measurements x2 measurements
x1 UKF x2 UKF
x1 EKF x2 EKF
0.97 x1 true x2 true
0.54

0.96
0.52

0.95
0.5

0.94

x2 × 103 /mol/L
x1 × 103 /mol/L

0.48

0.93

0.46
0.92

0.44
0.91

0.42
0.9

0.89 0.4

0.88 0.38
0 200 400 600 800 1000 1200 1400 1600 1800 2000 0 200 400 600 800 1000 1200 1400 1600 1800 2000
Time/min Time/min

(a) x1 State Estimation (b) x2 State Estimation

x3 State Estimation UKF Vs EKF Output Estimation UKF Vs EKF


0.7 7
x3 measurements y measurements
x3 UKF y UKF
x3 EKF y EKF
x3 true y true

6.5
0.65

0.6
x3 × 103 /mol/L

pH/-

5.5

0.55

0.5
4.5

0.45 4
0 200 400 600 800 1000 1200 1400 1600 1800 2000 0 200 400 600 800 1000 1200 1400 1600 1800 2000
Time/min Time/min

(c) x3 State Estimation (d) y Output Estimation Estimation


Figure 5. Result of Experiment II Plant-Model Mismatch Estimation
8

Square Error UKF VS EKF Square Error UKF VS EKF


15 0.12
UKF UKF
EKF EKF

0.1

10 0.08
SE x1 × 1011 /L2 /mol2

SE x2 × 109 /L2 /mol2


0.06

5 0.04

0.02

0 0
0 200 400 600 800 1000 1200 1400 1600 1800 2000 0 200 400 600 800 1000 1200 1400 1600 1800 2000
Time/min Time/min

(a) x1 Square Error (b) x2 Square Error

Square Error UKF VS EKF Square Error UKF VS EKF


0.25 18
UKF UKF
EKF EKF

16

0.2
14

12
SE x3 × 109 /L2 /mol2

0.15
SE y × 103 /−

10

8
0.1

4
0.05

0 0
0 200 400 600 800 1000 1200 1400 1600 1800 2000 0 200 400 600 800 1000 1200 1400 1600 1800 2000
Time/min Time/min

(c) x3 Square Error (d) y Square Error


Figure 6. Result of Experiment II Plant-Model Mismatch Error

You might also like