You are on page 1of 103

Institutionen fr systemteknik

Department of Electrical Engineering


Examensarbete
Observer for a vehicle longitudinal controller
Examensarbete utfrt i Reglerteknik
vid Tekniska hgskolan i Linkping
av
Peter Rytterstedt
LiTH-ISY-EX--2007/3950--SE
Linkping 2007
Department of Electrical Engineering Linkpings tekniska hgskola
Linkpings universitet Linkpings universitet
SE-581 83 Linkping, Sweden 581 83 Linkping
Observer for a vehicle longitudinal controller
Examensarbete utfrt i Reglerteknik
vid Tekniska hgskolan i Linkping
av
Peter Rytterstedt
LiTH-ISY-EX--2007/3950--SE
Handledare: Johanna Walln
isy, Linkpings universitet
Volker Maa
Mercedes Benz Technology Center, DaimlerChrysler AG
Examinator: Thomas Schn
isy, Linkpings universitet
Linkping, 1 April, 2007
Avdelning, Institution
Division, Department
Division of Automatic Control
Department of Electrical Engineering
Linkpings universitet
SE-581 83 Linkping, Sweden
Datum
Date
2007-04-01
Sprk
Language
Svenska/Swedish
Engelska/English

Rapporttyp
Report category
Licentiatavhandling
Examensarbete
C-uppsats
D-uppsats
vrig rapport

URL fr elektronisk version


http://www.control.isy.liu.se
http://www.ep.liu.se/2007/3950
ISBN

ISRN
LiTH-ISY-EX--2007/3950--SE
Serietitel och serienummer
Title of series, numbering
ISSN

Titel
Title
Observatr fr en lngsregulator i fordon
Observer for a vehicle longitudinal controller
Frfattare
Author
Peter Rytterstedt
Sammanfattning
Abstract
The longitudinal controller at DaimlerChrysler AG consists of two cascade
controllers. The outer control loop contains the driver assistance functions such
as speed limiter, cruise control, etc. The inner control loop consists of a PID-
controller and an observer. The task of the observer is to estimate the part of
the vehicles acceleration caused by large disturbances, for example by a changed
vehicle mass or the slope of the road.
As observer the Kalman lter is selected. It is the optimal lter when the
process model is linear and the process noise and measurement noise can be mod-
eled as Gaussian noise. In this Masters thesis the theory for the Kalman lter
is presented and it is shown how to choose the lter parameters. Simulated an-
nealing is a global optimization technique which can be used when autotuning,
i.e., automatically nd the optimal parameter settings. To be able to perform
autotuning for the longitudinal controller one has to model the environment and
driving situations.
In this Masters thesis it is veried that the parameter choice is a compromise
between a fast but jerky, or a slow but smooth estimate. As the output from
the Kalman lter is directly added to the control value for the engine and brakes,
it is important that the output is smooth. It is shown that the Kalman lter
implemented in the test vehicles today can be exchanged with a rst-order lag
function, without loss in performance. This makes the lter tuning easier, as
there is only one parameter to choose.
Change detection is a method that can be used to detect large changes in the
signal, and react accordingly for example by making the lter faster. A lter
using change detection is implemented and simulations show that it is possible to
improve the estimate using this method. It is suggested to implement the change
detection algorithm in a test vehicle and evaluate it further.
Nyckelord
Keywords Kalman lter, longitudinal controller, lter tuning, simulated annealing, change
detection
Abstract
The longitudinal controller at DaimlerChrysler AG consists of two cascade
controllers. The outer control loop contains the driver assistance functions such
as speed limiter, cruise control, etc. The inner control loop consists of a PID-
controller and an observer. The task of the observer is to estimate the part of
the vehicles acceleration caused by large disturbances, for example by a changed
vehicle mass or the slope of the road.
As observer the Kalman lter is selected. It is the optimal lter when the
process model is linear and the process noise and measurement noise can be mod-
eled as Gaussian noise. In this Masters thesis the theory for the Kalman lter
is presented and it is shown how to choose the lter parameters. Simulated an-
nealing is a global optimization technique which can be used when autotuning,
i.e., automatically nd the optimal parameter settings. To be able to perform
autotuning for the longitudinal controller one has to model the environment and
driving situations.
In this Masters thesis it is veried that the parameter choice is a compromise
between a fast but jerky, or a slow but smooth estimate. As the output from
the Kalman lter is directly added to the control value for the engine and brakes,
it is important that the output is smooth. It is shown that the Kalman lter
implemented in the test vehicles today can be exchanged with a rst-order lag
function, without loss in performance. This makes the lter tuning easier, as
there is only one parameter to choose.
Change detection is a method that can be used to detect large changes in the
signal, and react accordingly for example by making the lter faster. A lter
using change detection is implemented and simulations show that it is possible to
improve the estimate using this method. It is suggested to implement the change
detection algorithm in a test vehicle and evaluate it further.
v
Acknowledgments
This Masters thesis has been performed between October 2006 and March 2007 at
the Mercedes Technology Center, DaimlerChrysler AG in Sindelngen, Germany.
It completes my international studies for a Master of Science degree in Applied
Physics and Electrical Engineering at Linkpings Universitet, Sweden.
I would like to express my greatest gratitude to my supervisor at DaimlerChrysler,
Volker Maa, who has always had time for my questions and helped me in any way
possible. The teams EP/ERW and GR/EAT deserve many thanks for welcoming
me at the department, and for answering questions about the cars and develop-
ment tools that have come up during this thesis. My supervisor Johanna Walln
and examiner Thomas Schn at Linkpings Universitet, who have given insightful
comments and tips, also have a part in this thesis.
Finally I would like to thank Marie Rytterstedt, Peter Juhlin-Dannfelt and Erik
Almgren for proof-reading, and my girlfriend for her support and encouragement.
Sindelngen, March 2007
Peter Rytterstedt
vii
Contents
1 Introduction 1
1.1 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Problem Formulation . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.4 DaimlerChrysler AG . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.5 Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.6 Outline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.7 Limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2 Driver Assistance Systems 5
2.1 Anti-lock Braking System . . . . . . . . . . . . . . . . . . . . . . . 5
2.2 Traction Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.3 Stability Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.4 Speed Limiter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.5 Cruise Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.6 Hill Descent Control . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.7 Forward Collision Mitigation System . . . . . . . . . . . . . . . . . 6
2.7.1 Distance Warning . . . . . . . . . . . . . . . . . . . . . . . 7
2.7.2 Brake Assist System . . . . . . . . . . . . . . . . . . . . . . 7
2.8 Adaptive Cruise Control . . . . . . . . . . . . . . . . . . . . . . . . 7
2.9 Lane Guidance System . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.10 Blind-spot Warning . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.11 Systems Supported by the Controller . . . . . . . . . . . . . . . . . 8
3 Basic Filter Theory 11
3.1 State-Space Models . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.2 Discretization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.3 Observer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.4 Observability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.5 Kalman Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.5.1 Process and Measurement Model . . . . . . . . . . . . . . . 15
3.5.2 Discrete Time Kalman Filter Equations . . . . . . . . . . . 15
3.5.3 Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.5.4 Steady State . . . . . . . . . . . . . . . . . . . . . . . . . . 17
ix
x Contents
3.5.5 Block Diagram of the Stationary Kalman Filter . . . . . . . 17
3.5.6 Design Parameters . . . . . . . . . . . . . . . . . . . . . . . 17
3.6 Shaping Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.6.1 Shaping Filters for Non-Gaussian Process Noise . . . . . . . 19
3.6.2 Shaping Filters for Non-Gaussian Measurement Noise . . . 19
4 Choosing the Kalman Filter Parameters 21
4.1 Estimating the Covariances . . . . . . . . . . . . . . . . . . . . . . 21
4.2 Choosing Q and R Manually . . . . . . . . . . . . . . . . . . . . . 22
4.3 Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.3.1 Open-Loop Simulation . . . . . . . . . . . . . . . . . . . . . 23
4.3.2 Closed-Loop Simulation . . . . . . . . . . . . . . . . . . . . 24
4.4 Autotuning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
4.4.1 Evaluation Using RMSE . . . . . . . . . . . . . . . . . . . . 25
4.4.2 Autotuning Using Matlab . . . . . . . . . . . . . . . . . . . 25
4.4.3 Simulated Annealing . . . . . . . . . . . . . . . . . . . . . . 26
5 Kalman Filter Implementation 33
5.1 Overview of the Inner Control Loop . . . . . . . . . . . . . . . . . 33
5.2 Modeling the Acceleration . . . . . . . . . . . . . . . . . . . . . . . 35
5.3 Errors in the Acceleration Model . . . . . . . . . . . . . . . . . . . 38
5.4 Kalman Filter Model . . . . . . . . . . . . . . . . . . . . . . . . . . 43
5.5 Choosing the Filter Parameters . . . . . . . . . . . . . . . . . . . . 44
6 Alternative Kalman Filter Models 49
6.1 Vehicle Speed as Feedback . . . . . . . . . . . . . . . . . . . . . . . 49
6.2 Modeling the Disturbance a
z
. . . . . . . . . . . . . . . . . . . . . 50
6.2.1 First-Order Lag Function . . . . . . . . . . . . . . . . . . . 50
6.2.2 First-Order Gauss-Markov Process . . . . . . . . . . . . . . 52
6.2.3 Identifying the Time Constant . . . . . . . . . . . . . . . . 53
6.2.4 Testing the Model of a
z
. . . . . . . . . . . . . . . . . . . . 55
6.2.5 Higher-Order Derivative of a
z
. . . . . . . . . . . . . . . . . 56
6.3 Implementation and Testing in Arjeplog . . . . . . . . . . . . . . . 59
6.4 Comparing the Kalman Filter Models . . . . . . . . . . . . . . . . 60
6.5 Comparing the Kalman Filter with a First-Order Lag Function . . 61
7 Change Detection 67
7.1 Idea of Change Detection . . . . . . . . . . . . . . . . . . . . . . . 67
7.2 One Kalman Filter with Whiteness-Test . . . . . . . . . . . . . . . 68
7.3 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
7.4 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
8 Conclusions and Future Work 75
8.1 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
8.2 Future Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
List of Notations 77
Bibliography 79
A Matlab Implementation of lsqnonlin 81
B Matlab Implementation of Simulated Annealing 83
C Time Constant Identication 88
xii Contents
Chapter 1
Introduction
This chapter wil l give an introduction to the problem investigated in this Masters
thesis. DaimlerChrysler AG, where the thesis project has been performed, wil l be
presented, as wel l as an outline for the thesis.
1.1 Background
Driver assistance systems are more and more becoming standard in the new vehi-
cles built today. The tasks for these systems are to support and relieve the driver,
but not to take the driving task from him or her. By vehicle longitudinal regula-
tion, one understands the inuence of the vehicle in its driving direction by means
of a controller. In this Masters thesis the focus will be on the driver assistance
systems supported by the longitudinal controller at DaimlerChrysler AG.
The longitudinal controller can be thought of as two cascade controllers, see
Figure 1.1. The outer controller contains the driver assistance functions (such as
Speedtronic, Distronic, DSR, etc - for further information see Chapter 2). v is here
the actual vehicle speed. a
d1
, a
d2
, . . ., a
dn
are the desired accelerations calculated
by the assistance functions. The block called Coord. (coordinator) in the gure
chooses which of the functions that should have aect, depending on the drivers
choice. It also contains a jerk damper, so that the vehicle is traveling smoothly,
even when switching between the dierent assistance functions.
The resulting calculated acceleration a
d
is delivered to the inner control loop,
whose task is to make the vehicle have the same acceleration as the desired value.
The inner controller delivers a desired torque T to the actuators engine, brake and
gearbox, which are aecting the vehicle. The current speed v and acceleration a
are measured and used as feedback signals by the controllers.
The inner controller contains a PID-controller and an observer. The task of the
observer is to estimate the part of the vehicles acceleration caused by disturbances
not included in the vehicle model. A Kalman lter is chosen as observer, and this
Masters thesis will explain the function and implementation of the Kalman lter
in more detail.
1
2 Introduction
... -
a
dn
-
v
DSR
-
a
d3
-
v
Distronic
-
a
d2
-
v
Speedtronic
-
a
d1
Coord.
-
a
d
PID
Observer
-
T
Vehicle
6
v, a
Outer controller Inner controller
Figure 1.1. Overview of the longitudinal controller in the vehicle. The driver assis-
tance functions in the outer control loop calculates accelerations a
di
. The coordinator
(Coord) chooses which of the functions that should have aect and delivers a desired ac-
celeration a
d
to the inner control loop. The inner control loop consists of a PID-controller
and an observer. They deliver a desired torque T to the engine, brake and gearbox which
are aecting the vehicle. The speed v and acceleration a are used as feedback signals.
1.2 Problem Formulation
The Kalman lter attached parallel to the PID-controller should estimate the part
of the vehicles acceleration caused by large disturbances (for example a changed
mass or slope of the road). The lter is directly attached to the engine and brakes,
and it is therefore important that the output from the lter is smooth. Otherwise
the comfort is negatively aected.
The Kalman lter has to be tuned to work optimally. For this purpose the
theory behind the lter and the methods for lter tuning had to be better inves-
tigated.
1.3 Objective
The goal of this thesis is to explain the function of the Kalman lter, describe
methods for choosing the parameters, and to nd good parameter settings justied
by theoretical and practical methods. It should also be examined if the structure
of the lter can be improved.
1.4 DaimlerChrysler AG 3
1.4 DaimlerChrysler AG
DaimlerChrysler AG is a major automobile and truck manufacturer formed in 1998
by the merge of Daimler-Benz in Germany (the manufacturer of Mercedes-Benz)
and the Chrysler Corporation in USA. The company produces cars, trucks, vans
and busses under the brands Chrysler, Dodge, Jeep, Mercedes-Benz, Smart and
Maybach, among others. In January 2007 the company was the second largest
auto manufacturer.
At Mercedes Technology Center in Sindelngen, Germany, over 35000 employ-
ees are producing the C-Class, E-Class, S-Class, CLS-Class, CL-Class and May-
bach cars. 9500 persons are working with development. The team working with
driving assistance systems is developing control systems such as adaptive cruise
control and hill descent control.
1.5 Method
The necessary theory describing the Kalman lter will be presented using literature
studies. Dierent methods for choosing the lter parameters will be explained
and implemented. Using previous Masters theses at DaimlerChrysler the process
model for the vehicles longitudinal dynamics will be developed. The model of the
disturbance used in the existing Kalman lter will be examined. Then a stationary
Kalman lter is designed for the model and good working parameters will be found
using simulation. The development of the observer is performed in Matlab and
Simulink, and simulations are made o-line. The lter will then be extended with
an algorithm for change detection. It will be examined if this makes the lter both
work properly in case of small noise as well as respond quickly in case of sudden
larger changes (as is two competitive goals with the Kalman lter).
1.6 Outline
In the introductory chapter the purpose and method of the thesis is presented. An
overview of the dierent driver assistance systems supported by the longitudinal
controller is given in the second chapter. Chapter three discusses some basic esti-
mation lter theory needed to implement an observer in the controller. Dierent
possibilities to choose and tune the lter parameters are presented in chapter four.
In chapter ve the model for the longitudinal dynamics of the vehicle is derived,
and an initial version of the Kalman lter is implemented and tested. Chapter
six starts with a presentation of some more complex models used to model the
estimated parameter, and continues with a discussion of the advantages and dis-
advantages of using these models. At the end of chapter six a comparison between
the developed Kalman lter and a standard low-pass lter is made. Chapter seven
discusses the possibilities given by some ideas picked up from the area of Change
Detection, and an algorithm that uses this theory is simulated and evaluated.
Finally, in the last chapter, conclusions are drawn and some extensions for the
thesis are presented.
4 Introduction
1.7 Limitations
The use of an observer in an inner control-loop to estimate the model errors was
suggested in [1]. A comparison between this method and the use of a PID-controller
was made in [19]. However, the advantages and disadvantages of attaching an
observer in parallel to a PID-controller (as described in this Masters thesis) have
not been examined. It is a method used for about a year in test vehicles at
DaimlerChrysler and accepted as a basis for this thesis.
The sensors used in this Masters thesis to measure the speed and acceleration
of the vehicle use Kalman lters and sensor fusion techniques to obtain stable
measurements. It has not been examined if the lter described in this thesis
would make better estimates by using unltered data.
Chapter 2
Driver Assistance Systems
To better understand the task of the control ler discussed in this thesis, an intro-
duction to driver assistance systems is given in this chapter. Among the driver
assistance systems there are comfort functions, which relieve the driver in his/her
tasks, passive safety functions, which reduce the consequence of an accident, and
active safety functions which help the driver to avoid accidents.
2.1 Anti-lock Braking System
Anti-lock braking system (ABS) prevents the wheels from locking and maintains the
steering ability of the vehicle during hard braking. During bad road conditions,
ABS will also reduce the stopping distance. The system measures the velocity
of all four wheels, and if one of the sensors reports an abnormal deceleration it
concludes that the wheel is about to lock and the pressure in the braking system
is reduced. [7]
2.2 Traction Control
The functioning of the traction control system is very similar to that of the ABS.
The system prevents the wheels from slipping during acceleration by using the
same velocity sensors as the ABS. If the vehicle starts to slip, the engine power is
reduced in order to maintain control of the vehicle. [7]
2.3 Stability Control
A stability control system basically measures the yaw rate of the vehicle, i.e., the
rotation in the ground plane, and compares it with the desired trajectory. If the
deviation is greater than a certain threshold, the system will activate the brakes
on one side of the vehicle to correct this. When the German automotive supplier
Bosch launched their stability control system they called it electronic stability
program (ESP). [7]
5
6 Driver Assistance Systems
2.4 Speed Limiter
The speed limitation function is used to make sure that the driver does not ex-
ceed a set speed. The driver can set a variable or permanent limit speed. The
variable limit can easily be set and changed during driving. It is automatically
deactivated if the driver pushes down the accelerator pedal beyond the pressure
point, often referred to as kickdown. This is useful when overtaking. The per-
manent limit is used for permanent long-term speed restrictions, such as driving
on winter tires. The permanent limit speed is set using the on-board computer,
and it cannot be exceeded by kickdown. This function is called Speedtronic by
DaimlerChrysler. [25]
2.5 Cruise Control
The cruise control, sometimes called speed control or autocruise, automatically
controls the speed of the vehicle. The driver can easily set and change the desired
speed during driving, and cruise control maintains the set speed and accelerates
and brakes the vehicle automatically if necessary. If the driver pushes down the
accelerator pedal to temporarily drive faster, the cruise control adjusts the vehicles
speed to the last stored speed when he/she again releases the accelerator pedal.
This is useful when overtaking. [25]
2.6 Hill Descent Control
The hill descent control system is essentially a low-speed cruise control system for
steep descents. It uses the ABS brake system to control each wheels speed and
keeps the speed of travel to the speed set in the operating system. It is possible to
drive at a higher or a lower speed than that set in the operating system at any time
by manually braking or accelerating. The driver will be able to maintain control of
the vehicle when driving down hills with slippery or rough terrain and the system is
therefore especially helpful in o-road conditions. The hill descent control system
used in DaimlerChrysler vehicles is called Downhill Speed Regulation (DSR). [26]
2.7 Forward Collision Mitigation System
Col lision mitigation system (CMS) uses radar sensors to detect obstacles which
are in the path of the vehicle. Most manufacturers have a similar functionality
when it comes to the intervention strategy. They use increasing warning levels as
the threat approaches. If the driver does not brake himself, the CMS will reduce
the impact speed by applying the brakes when a collision with the leading vehicle
appears to be unavoidable. [7]
2.8 Adaptive Cruise Control 7
2.7.1 Distance Warning
This function warns the driver when the distance to the vehicle in front is too
small. A message or a warning lamp in the instrument cluster then lights up. If
the driver is approaching the vehicle in front at high speed, he/she will also hear a
signal. The driver has to apply the brakes in order to maintain the correct distance
and avoid a collision. [25]
If the system has detected a risk of collision and the driver does not brake
or steer himself/herself, the vehicle is automatically braked gently and the seat
belts are retracted gently two or three times to warn the driver. This helps to
reduce the consequence of an accident, but the driver has to apply the brakes
himself/herself in order to avoid a collision. This system is called pre-safe brake
in DaimlerChrysler vehicles. [25]. At this point, if the driver applies the brakes,
the system interprets this action as emergency braking, and activates the brake
assist system to reduce impact speed. [7]
2.7.2 Brake Assist System
Brake assist system (BAS) operates in emergency braking situations. If the driver
pushes down the brake pedal quickly, BAS automatically boosts the braking force
and thus shortens the stopping distance. If the vehicle is equipped with radar
sensors, the system calculates the brake pressure necessary to avoid a collision.
When the driver pushes down the brake pedal forcefully, the system automatically
boosts the braking force to a level appropriate to the trac situation. The brake
assist system is deactivated and the brakes will function as normal when the driver
releases the brake pedal, there are no obstacles detected in the path of the vehicle
and there is no longer a risk of collision. In DaimlerChrysler vehicles this function
is called BAS Plus. [25]
2.8 Adaptive Cruise Control
Adaptive cruise control (ACC) is also known as active cruise control or intelli-
gent cruise control. ACC uses a forward looking sensor, usually radar or laser, to
monitor the distance to leading vehicles. If the system is active and the time gap
to the leading vehicle falls below a certain threshold, the vehicle will automatically
brake in order to maintain distance. In Europe there are government restrictions
which limit the permitted braking rate. If the vehicle detects that a higher decel-
eration is required to avoid colliding with the leading vehicle, an audible warning
is given to the driver. If there is no vehicle in front, ACC operates in the same
way as cruise control. [7]
DaimlerChrysler oers adaptive cruise control under the name Distronic. It
functions at speeds between 30 and 200 km/h. With the Distronic system, the
distance to the leading vehicle is set as a time between one and two seconds. The
system uses radar sensors to measure the distance to the vehicle in front. [25]
Some DaimlerChrysler vehicles are equipped with a system called Distronic
Plus, which functions at speeds between 0 and 200 km/h. If Distronic Plus detects
8 Driver Assistance Systems
that the vehicle in front has stopped, it will cause the vehicle to brake and come to
a halt. Once the vehicle is stationary, it will remain so without the driver having to
push down the brake pedal. If the vehicle in front pulls away, and the driver pulls
the cruise control lever or briey pushes down the accelerator pedal, the vehicle
automatically pulls away and adapts its speed to the vehicle in front. [25]
2.9 Lane Guidance System
Lane guidance system refers to systems that try to help the driver stay in the lane.
Systems typically use an audible warning or a steering wheel torque to alert the
driver if the vehicle is approaching the lane markings. The steering wheel torque
used by some of the systems will automatically steer the vehicle back into the
center of the lane, thus working almost like an autopilot. Another idea is to try
to mimic the sounds and vibrations that are generated by rumble strips, i.e., the
grooved lane markings that are sometimes used on motorways to indicate lane
departure. [7]
2.10 Blind-spot Warning
The general idea behind a blind-spot warning system is to lower the risk of lane
change accidents by warning the driver about vehicles in the blind spot. There are
dierent techniques for achieving this but usually ocular vision or radar is used. [7]
2.11 Systems Supported by the Controller
In this Masters thesis, the focus will be on those driver assistance systems that
are supported by the longitudinal controller at DaimlerChrysler AG. These are
Speed limiter
Cruise control
Adaptive cruise control
Collision mitigation system
Brake assist system
Hill descent control
Figure 2.1 gives an overview of the vehicles sold by DaimlerChrysler. The vehicles
are listed together with the driver assistance systems that are used in the vehicles.
2.11 Systems Supported by the Controller 9

Speed-
tronic
Cruise
Control
Distance
Warning
Distronic
Distronic
Plus
DSR
Pre-
Safe
Brake
BAS-
Plus
C - Class WS203
x x
C - Class CL203
x x
CL - Class 215
x x x x
CL - Class 216
x x x x x x x
CLK - Class 209
x x x x
CLS - Class 219
x x x x
E - Class 211
x x x x
R - Class 251
x x x x
S - Class 221
x x x x x x x
SL - Class 230
x x x x
SLK - Class 171
x x
M - Class 164
x x x x x
G - Class 463
x x
GL - Class X164
x x x x x
Sprinter
x x
Viano 639
x x
Vito 639
x x
Crafter (VW)
x x



Figure 2.1. Driver assistance systems supported by the vehicle longitudinal controller
at DaimlerChrysler. The gure shows which DaimlerChrysler vehicles are using the
systems. The names that are used in the gure are the names used by DaimlerChrysler.
10 Driver Assistance Systems
Chapter 3
Basic Filter Theory
This chapter starts with an introduction to state-space models often used when
working with control systems. It is shown how to transform a continuous time
model into a time discrete model. Then some basic theory for observers is pre-
sented. One popular observer is the Kalman lter. The Kalman lter is certainly
one of the greater discoveries in the history of statistical estimation theory and
possibly the greatest discovery in the twentieth century [11]. The equations for
this lter are presented and the function of the stationary Kalman lter is ex-
plained. In the end of this chapter it is described how to construct shaping lters
for non-Gaussian process noise and non-Gaussian measurement noise.
3.1 State-Space Models
To design an estimation lter one rst needs a mathematical model of the con-
trolled process. Sir Isaac Newton (1642-1727) discovered that the sun and its
planets are governed by laws of motion that depend only upon their current rel-
ative positions and current velocities. By expressing these laws as a system of
dierential equations and feed them with the current positions and velocities he
could uniquely determine the positions and velocities of the planets for all times.
Almost every physical system can in the same way be described using dierential
equations. [11]
The order of a dierential equation is equal to the order of the highest deriva-
tive. When doing control design it is preferable to have all equations of rst order.
One can reduce the form of any system of higher order dierential equations to
an equivalent system of rst-order dierential equations by introducing new vari-
ables. [9]
In this Masters thesis a special type of dierential equations will be used,
called ordinary dierential equations (ODE). This model is also referred to as the
continuous-time state-space model. When the equations describing a system are
11
12 Basic Filter Theory
linear, the model can be written as the linear state-space model [3]
x(t) = Ax(t) +Bu(t) +Gw(t) (3.1)
y(t) = Cx(t) +e(t) (3.2)
The variables x = [x
1
, x
2
, ..., x
n
]
T
in (3.1) and (3.2) are commonly called state
variables (or states) and they represent all important characteristics of the sys-
tem at the current time. The process model (3.1) describes the dynamics of the
system. The variable u represents a known external signal, typically available to or
controlled by the system. The variable w is used to model unknown disturbances
or model uncertainties, which cannot be directly measured. They can only be
observed through their inuence on the output. The measurement model (3.2)
describes how the noisy measurements y are related to the internal variables. e is
here some noise added to the measurement. [3]
Usually e and w are modeled as unpredictable random processes with null as
mean value and a known variance, often referred to as Gaussian noise. It can
be shown that a system described by (3.1) and (3.2) with e and w modeled as
Gaussian noise is a Markov Process. This means that it satises the Markov
Property [3]
p[x(t)|x(), < t
1
] = p[x(t)|x(t
1
)], t > t
1
(3.3)
The construction p[A|B] in this statement should be read the probability of A
given B. In words this means that the past up to any time t
1
is fully characterized
by the value of the process at t
1
, or The future is independent of the past if the
present is known. This is an important property, because when trying to predict
future states of the system with a good model, one only needs to know the current
state. [3]
3.2 Discretization
Almost every physical system is best described using a continuous-time model, but
the controller is often implemented in a computer using discrete methods. The
model therefore has to be sampled and changed into a discrete time state-space
model. How this is done is explained in this section, based on [10] and [13].
The continuous dynamic system described by (3.1) and (3.2) can be trans-
formed into a discrete state-space system, assuming that the input signal u is
piecewise constant during the sampling interval T. This is usually the case when
the input u is generated by a computer. This gives the linear discrete time-
invariant state-space model
x(kT +T) = A
d
x(kT) +B
d
u(kT) +G
d
w(kT) (3.4)
y(kT) = C
d
x(kT) +e(kT) (3.5)
The index d is referring to the discrete form of the matrices. Often an easier and
more compact form of (3.4) and (3.5) is being used
x
k+1
= A
d
x
k
+B
d
u
k
+G
d
w
k
(3.6)
y
k
= C
d
x
k
+e
k
(3.7)
3.3 Observer 13
In this Masters thesis the indices d will be left out, when there is no risk of
confusion.
The discrete form of the matrices are calculated using the matrices in (3.1)
and (3.2) as
A
d
= e
AT
(3.8)
B
d
=
T
_
0
e
AT
Bdt (3.9)
C
d
= C (3.10)
There are several ways to calculate e
AT
. One of them is
e
AT
= L
1
(sI A)
1
(3.11)
where L
1
is the inverse Laplace transform. Other methods are using Taylor series
approximation or the Pad approximation, see [11] for a more detailed description.
There are several possibilities to calculate the matrix G
d
. Assuming that the
stochastic input e also is constant during the sampling intervals, the same method
can be used as for the matrix B
d
. G
d
is then calculated using A and G from (3.1)
giving [13]
G
d
=
T
_
0
e
AT
Gdt (3.12)
This method, called zero-order hold, is used by the command c2d (=con-
tinuous to discrete) in Matlab when nothing else is specied [24].
It is seldom the case that e is constant during the sampling intervals [13].
Another alternative is triangle approximation, where the input e is assumed
piecewise linear over the sampling period. This method is generally more accurate
than zero-order hold when the input e is assumed to be smooth [24]. Other meth-
ods include impulse-invariant discretization (where the impulse response of the
discretized system is matched with that of the continuous system) and Tustin
approximation (which instead matches the frequency response of the systems).
3.3 Observer
When designing a controller it is important to have information about the states
of the system. Normally all states cannot be measured. An observer may be used
to estimate the unknown states with help from the available measured states and
the measured signals y and u. In this section some basic theory about the observer
is discussed, based on parts from [9] and [3].
Consider the discrete time system described by (3.6) and (3.7). The matrices A,
B and C are time invariant and known, and the signals u and y can be measured.
The states x cannot be measured but are needed for controlling purposes. An
14 Basic Filter Theory
initial approach to estimate the states would be to simulate the system using only
the known input values u
x
k+1
= A x
k
+Bu
k
(3.13)
where x
k
is the estimated value of x at time step k. To measure the quality of the
estimation, the dierence y
k
C x
k
can be used. This dierence should be null
if the estimate x
k
is equal to the real state x
k
, and will also be so in absence of
errors. This will in practice, however, never be the case, since there are always
model errors and disturbances w as well as measurement noise e. A good way to
improve the estimates is to use y
k
C x
k
as a feedback, such that
x
k+1
= A x
k
+Bu
k
+L(y
k
C x
k
) (3.14)
In words this can be written as
Estimated state = Predicted state + L Correction term
The correction term reects the dierence between the predicted measurement
and the actual measurement as explained above. In the context of lters this term
is often called the measurement innovation or the residual.
The matrix L is here a design parameter and it adjusts how much the residuals
should aect the estimated states. It is a trade o between how fast the estima-
tions converge toward the measurement (high L gives a fast convergence) and how
sensitive the estimate is to measurement noise (high L gives a more noise sensitive
estimate).
The optimal value of L can be calculated in dierent ways, resulting in dierent
types of observers. One type of observer is the Kalman lter, described in detail
in Section 3.5.
3.4 Observability
The observer estimates the states x with the help of measurements y. Therefore,
there has to be a connection between the states and the measurement, the states x
has to be seen in the output y. This limitation is formulated with the help of
the observability matrix O, described in [9] as
O =
_
_
_
_
_
_
_
C
CA
CA
2
.
.
.
CA
n1
_
_
_
_
_
_
_
(3.15)
All states are observable if and only if O has full rank. This criteria does
however not give any information about how good the estimate will be. When a
matrix has full rank, none of the rows can be written as a linear combination of
3.5 Kalman Filter 15
the other rows. If the matrix does not have full rank, then there is one or more
rows that are unnecessary. The easiest way to compute the rank of a matrix is
given by the Gauss elimination algorithm. In Matlab this is calculated with the
command rank.
3.5 Kalman Filter
The Kalman lter is very powerful in several aspects. It supports estimates of
past, present, and future states, and it can do so even when the precise nature of
the modeled system is unknown [11]. In the following sections the basic theory of
the Kalman lter is presented, based on parts from [23], [12] and [13].
3.5.1 Process and Measurement Model
The Kalman lter is a set of equations that calculates the optimal L, given a linear
model of the system and statistical information about the process noise w and
measurement noise e. When the system and noise are modeled in the way described
in this section, the Kalman lter will compute the value of L that minimizes the
variance of the state estimation error, i.e., x
k
x
k
. [23]
The Kalman lter estimates the states of a discrete time controlled process
described in the form of (3.6) and (3.7), repeated below
x
k+1
= Ax
k
+Bu
k
+Gw
k
y
k
= Cx
k
+e
k
The random variables w and e are assumed to be independent of each other,
Gaussian, and with normal probability distributions according to
p(w) N(0, Q) (3.16)
p(e) N(0, R) (3.17)
The covariance matrices are thus dened R = E{e
k
e
T
k
} and Q = E{w
k
w
T
k
}
with E{e
k
} = E{w
k
} = 0. The process noise covariance matrix Q, measurement
noise covariance matrix R and the matrices A, B, C and G might change with
each time step or measurement, but in this Masters thesis they will be assumed
stationary and known.
3.5.2 Discrete Time Kalman Filter Equations
In this section the Kalman lter equations will be presented to give an overview
of how the lter works, following the presentation in [23] and [12]. Note that
the equations can be algebraically manipulated into several forms. Therefore the
equations presented here might dier from those found in other literature. For
more information, for example on how to derive the equations, see [3], [11] or [12].
The Kalman lter estimates a process by using a feedback control. The lter
estimates the process state at some time and then obtains feedback in the form
16 Basic Filter Theory
of (noisy) measurements. As such, the equations for the Kalman lter are divided
into two groups; predictor equations and measurement update equations.
The discrete Kalman lter predictor equations are [13]
x
t|t1
= A x
t1|t1
+Bu
t
(3.18)
P
t|t1
= AP
t1|t1
A
T
+GQG
T
(3.19)
which translates the estimate from the last time step x
t1|t1
to obtain the esti-
mate for the current time step. x
t|t1
refers to the estimate of x at the current
time step t given all the measurements prior to this time step, also referred to as
the a priori state estimate. P
t|t1
in (3.19) is dened
P
t|t1
= E[(x
t
x
t|t1
)(x
t
x
t|t1
)
T
] (3.20)
and is the estimation error covariance given measurements prior to this time step,
also referred to as the a priori estimate error. Note that P
t|t1
is calculated using
the estimate error from the last time step, P
t1|t1
, and the process noise covari-
ance (or model uncertainties), Q. P
t|t1
can be thought of as the uncertainties
of how the states x are evolving.
The discrete Kalman lter measurement update equations are [13]
L
t
= P
t|t1
C
T
(CP
t|t1
C
T
+R)
1
(3.21)
x
t|t
= x
t|t1
+L
t
(y
t
C x
t|t1
) (3.22)
P
t|t
= (I L
t
C)
1
P
t|t1
(3.23)
The measurement update equations are responsible for the feedback, i.e., for im-
proving the estimate incorporating a new measurement. They can also be thought
of as corrector equations. (3.21) computes the Kalman gain L
t
that minimizes the
estimation error covariance P
t|t
= E[(x
t
x
t|t
)(x
t
x
t|t
)
T
]. The correction (3.22)
generates the state estimate by incorporating the new measurement y
t
. Together
are (3.18) and (3.22) forming (3.14) in Section 3.3. The nal step (3.23) is to
obtain the estimate error covariance P
t|t
, which is needed in the next time step.
After each predictor and measurement update pair, the calculated values x
t|t
and P
t|t
are saved so they can be used in the next time step. This update is
performed with the time update equations
x
t1|t1
= x
t|t
(3.24)
P
t1|t1
= P
t|t
(3.25)
The process is then repeated using these values in the algorithms for the next
time step. This recursive nature of the Kalman lter is practical when doing the
implementation. [23]
3.5.3 Initialization
The initial values x
1
and P
1
have to be chosen before starting the lter. x
1
is
chosen with knowledge about the state x. For example, if x is a random constant
3.6 Shaping Filter 17
with normal probability distribution, the best choice is x
1
= 0. P
1
is the
uncertainty in the initial estimate x
1
. When one is absolutely certain that the
initial state estimate is correct, then P
1
should be set to 0. Otherwise the best
choice is the variance of x. However, the choice is not critical. [12],[23]
3.5.4 Steady State
If the matrices A, C, Q and R are time-invariant, both the estimation error covari-
ance P
k
and the Kalman gain L
k
will converge to a stationary value. If this is the
case, these parameters can be pre-computed by either running the lter o-line,
or by calculating the stationary value P as described in [12] and [19]
P = APA
T
+GQG
T
APC
T
(CPC
T
+R)
1
CPA
T
(3.26)
This equation is referred to as the algebraic Riccati equation. The stationary value
of L can then be calculated as
L = APC
T
(CPC
T
+R)
1
(3.27)
3.5.5 Block Diagram of the Stationary Kalman Filter
The computational procedure and the relation of the lter to the system is illus-
trated as a block diagram in Figure 3.1. The Kalman lter recursively computes
values of x using the pre-calculated stationary values of P and L, the initial esti-
mate x
t1|t1
and the input data y
t
. [23]
3.5.6 Design Parameters
Design parameters for an observer are the matrices A, B, C and L. If the Kalman
lter equations (3.26) and (3.27) are used to calculate L, the design parameters
are Q, R and G instead of L. If the matrices are time dependent, the functionality
to calculate new values for L also has to be implemented, but in this Masters
thesis they will be assumed stationary. In Chapter 4 it will be discussed how
to choose the parameters Q and R. The model used in this Masters thesis is
developed in Chapter 5.
3.6 Shaping Filter
When implementing a Kalman lter, it is necessary to have all disturbances acting
as Gaussian noise, i.e., a random signal with null as mean value. For many physical
systems encountered in practice, it may not be justied to assume that all noises
are Gaussian. If the spectrum of a signal is known, the signal can be described
as the output of a lter driven by Gaussian noise. Using this, a model with
non-Gaussian noise can be extended to a lter driven by Gaussian noise. These
lters are called shaping lters, and they shape the Gaussian noise to represent
the spectrum of the actual system. The lter can be included in the original state-
space system, giving a new linear state-space model driven by Gaussian noise.
18 Basic Filter Theory
u
t
-
B
-
+
f
x
t

delay

x
t1
A
6
+
?
w
t
+
-
C
-
+
f
?
e
t
+
y
t

+
f
L

+
f
x
t|t

x
t|t
?
delay
-
x
t1|t1
A
-
+
f
u
t
6
B
6
+
x
t|t1
6
+
-
C
6

Discrete System
Measurement
Discrete Kalman Filter
Figure 3.1. Kalman lter block diagram. This gure shows the computational pro-
cedure of the Kalman lter, and its relation to the system. The blocks Discrete Sys-
tem and Measurement are a graphically representation of the state-space model (3.6)
and (3.7). The Kalman lter recursively computes values of x using the pre-calculated
stationary values of P and L, and the input signals y and u. It can here be seen how the
estimate x
t|t
delivered from the Kalman lter is saved in the delay block, so that it can be
used in the next time step. The variable x
t|t1
is calculated A x
t1|t1
+Bu
t
as in (3.18).
The estimate for the current time step x
t|t
is calculated x
t|t1
+ L(y
t
C xt|t 1) as
in (3.22). [11]
3.6 Shaping Filter 19
This is done for systems with non-Gaussian process noise and non-Gaussian
measurement noise in the next two sections, following the theory in [11].
3.6.1 Shaping Filters for Non-Gaussian Process Noise
Consider a system given on the form
x
1
= A
1
x
1
+G
1
w
1
(3.28)
y = C
1
x
1
+e (3.29)
where w
1
is non-gaussian noise and e is zero-mean Gaussian noise. Suppose w
1
can be modeled by a linear shaping lter according to
x
SF
= A
SF
x
SF
+G
SF
w (3.30)
w
1
= C
SF
x
SF
(3.31)
where w is Gaussian noise. Then the lter can be included in the original state-
space system, giving the new state-space system
x = Ax +Gw (3.32)
y = Cx +e (3.33)
where
x =
_
x
1
x
SF
_
(3.34)
A =
_
A
1
G
1
C
SF
0 A
SF
_
(3.35)
G =
_
0
G
SF
_
(3.36)
C =
_
C
1
0

(3.37)
3.6.2 Shaping Filters for Non-Gaussian Measurement Noise
Consider a system given on the form
x
1
= A
1
x
1
+G
1
w (3.38)
y = C
1
x
1
+e
1
(3.39)
In this case, e
1
is non-Gaussian noise and w is Gaussian noise. Suppose e
1
can be
modeled by a linear shaping lter according to
x
SF
= A
SF
x
SF
+G
SF
e (3.40)
e
1
= C
SF
x
SF
(3.41)
where e is Gaussian noise. In this case the new state-space system becomes
x = Ax +GW (3.42)
y = Cx (3.43)
20 Basic Filter Theory
where
x =
_
x
1
x
SF
_
(3.44)
A =
_
A
1
0
0 A
SF
_
(3.45)
G =
_
G
1
0
0 G
SF
_
(3.46)
C =
_
C
1
C
SF

(3.47)
W =
_
w
v
_
(3.48)
Chapter 4
Choosing the Kalman Filter
Parameters
In this chapter dierent possibilities on how to choose and tune the Kalman lter
parameters are presented. First it wil l be shown how to estimate the parameters
using information about the process and measurement noise. Then it wil l be de-
scribed how to tune the parameters using knowledge about the parameters inuence
on the behavior of the lter, using open-loop or closed-loop simulation, and nal ly
using autotuning. A global optimization technique cal led simulated annealing is
implemented for autotuning in Matlab and Simulink.
4.1 Estimating the Covariances
The Kalman lter assumes that all disturbances are stochastic variables known in
advance. If the system is linear and both the process noise w and measurement
noise e have a normal distribution, it can be shown that the Kalman lter is the
optimal lter (in the sense of minimizing the variance of the estimate error). In
this case the covariance matrices Q and R should be estimated using measures of
the noises e and w. [12]
Each element of R is dened as [3]
R
ij
= E[(e
i
e
i
)(e
j
e
j
)
T
] (4.1)
where e
i
is the mean value of e
i
, and the formulation E[] means the statistical
expected value of . The matrix R is a symmetric n n matrix, where n is the
number of elements in e. The diagonal elements of the covariance matrix are the
variances of the components of e, while the o-diagonal elements are the scalar
covariances between its components. If the components of e is independent of each
other, the o-diagonal elements of R should be set to 0.
By investigating the measured signals, it is possible to obtain an estimation of
the covariance matrix R. Assume that the information in the measured signal y
21
22 Choosing the Kalman Filter Parameters
is constant. The elements of R can then be estimated as in [4] and [2] using
R
i
=
1
N 1
N

t=1
(y
i
(t) y
i
)
2
(4.2)
where i is the i:th measured signal, y
i
is the mean value of y
i
, and N is the number
of samples used for the estimation. The uncertainties of the measured signals are
here assumed to be independent, which results in a diagonal R matrix.
Now assume that the necessary information in the measured signal is of low
frequency, for example the speed of the vehicle. The measurement noise e can
then be estimated by low-pass ltering the signal y as [2]
e = y(t) y (4.3)
where y is the low-pass ltered signal. The elements of R can then be calculated
as

R
ij
=
1
N
N

t=1
e
i
(t)e
j
(t) (4.4)
where i and j are the index of the measured signals and N is the number of samples
used for the estimation. The estimation of the covariance matrix can be performed
in Matlab using the command covf [18].
The denition of the covariance matrix for the process noise Q is similar as
for R and it can also be estimated using a similar method. The problem that
might arise is the fact that not all states in the state vector are measurable.
4.2 Choosing Q and R Manually
A drawback of the Kalman lter is that knowledge about process and measurement
noise statistics is required. It may be possible to determine the measurement noise
covariance from measurements, but determining the process noise covariance is
more dicult, for example when not all the states are measurable. Instead, a
common approach is to test dierent choices of Q and R until the Kalman lter
shows acceptable behavior. To understand how the parameter choice aects the
lter, a discussion of the function of the parameter will now be held based on parts
from [12] and [11].
L is calculated using A, C, Q and R, and will therefore depend on which char-
acteristics the process noise and the measurement noise are given in the model.
The inuence on L from dierent choices of R and Q can be understood by insert-
ing (3.7) in (3.22), which gives
x
k
= x

k
+L
k
(y
k
C x

k
)
= x

k
+L
k
Cx
k
+L
k
e
k
L
k
C x

k
= x

k
+L
k
C(x
k
x

k
) +L
k
e
k
(4.5)
4.3 Simulation 23
This shows that the state estimate x
k
is adjusted using the dierence between the
estimate x and the real state x, as well as the measurement noise e. Both terms
are multiplied with the gain L. A large Q results in a large L, which means a fast
lter with good trust in the measurements, but it also makes the observer more
sensitive to the measurement noise e. A large R results in a small L, which means
that the measurements are not reliable. This demands good thrust in the model,
which makes the observer sensitive to errors in the model.
Assume that the parameters are chosen as Q = Q
1
and R = R
1
. Then the
stationary values of P and L can be calculated using (3.26) and (3.27). Assume
that the calculated values are P
1
and L
1
.
If Q and R is both multiplied with the same value , the resulting P in (3.26)
is according to [12] also multiplied with . This gives P = P
1
. The calculation
of L in (3.27) then becomes
L = APC
T
(CPC
T
+R)
1
= A(P
1
)C
T
(C(P
1
)C
T
+ (R
1
))
1
= AP
1
C
T

1
(CP
1
C
T
+R
1
)
1
= AP
1
C
T
(CP
1
C
T
+R
1
)
1
= L
1
(4.6)
In other words, L remains the same when Q and R is multiplied with the
same value. The quotient between Q and R is therefore the design parameter; the
absolute values do not matter. When choosing the parameters, R can be set to a
constant value and Q adjusted until the lter gets acceptable behavior.
4.3 Simulation
Using simulation in Simulink dierent parameter choices can be evaluated without
having to make a test drive in a real vehicle. Here two dierent simulation methods
will be explained, open-loop and closed-loop.
4.3.1 Open-Loop Simulation
One method is open-loop simulation. With this method, measurements done in a
test car can be recorded and given as input back to the model in Simulink. It is
now possible to simulate the Kalman lter with dierent parameters and compare
the outputs. The reason why this simulation method is called open-loop is that
the dierent parameter choices does not aect the behavior of the vehicle. The
lter is fed with the recorded measurements, but the output from the lter is not
connected to the controller run in the simulation. This type of simulation is used
to produce all the diagrams presented in the next chapters.
24 Choosing the Kalman Filter Parameters
4.3.2 Closed-Loop Simulation
The other type of simulation used is closed-loop simulation. With this method
a scenario including the vehicle and the road is simulated. The output from the
lter is attached to the controller and the behavior of the vehicle is aected by how
well the lter is performing. Figure 4.1 shows the Simulink model used by the
closed-loop simulation. The model consists of several subsystems, all developed by
DaimlerChrysler, and one of them is the controller containing the Kalman lter.
Figure 4.1. Closed-loop simulation. The vehicle, its controller and the environment are
simulated together. The output of the lter will here aect the behavior of the vehicle.
The environment and the actions of the driver are specied using simulation scenarios. It
is also possible to specify another vehicle which is traveling in front, a so-called rabbit.
Simulation Scenarios
For the closed-loop simulation two dierent scenarios are prepared. The rst
scenario represents the vehicle driven up and down a hill. The vehicle is unloaded
and the driver has activated the cruise control with a set speed of 120 km/h. The
rst part of the hill has a slope of 10% (meaning uphill), and the second part
has a slope of 15% (meaning downhill).
The second scenario represents the vehicle driven on a straight road. The
vehicle is heavy loaded. Total mass of the vehicle is 1.8 times the normal mass.
The vehicle is driven at 80 km/h and the driver has activated the cruise control.
The driver adjusts the speed by using the cruise control lever, rst by increasing
the set speed to 120 km/h and then by decreasing it again to 80 km/h.
4.4 Autotuning 25
4.4 Autotuning
Tuning the lter, i.e., choosing the values of the process noise covariance Q and
measurement noise covariance R so that the lter performance is optimized with
respect to some performance measure, is a challenging task. Performing it manu-
ally is time-consuming with no guarantee for optimality. Poor tuning may result
in unsatisfactory performance of an otherwise powerful algorithm. It is there-
fore often desirable to develop automated systematic procedures for Kalman lter
tuning.
A systematic method of choosing Q and R is to perform many simulations using
dierent parameters and evaluate the performance. A performance evaluation
variable may be the variance of the state estimation error, x
k
x
k
(which is also
minimized with the Kalman lter). [12]
4.4.1 Evaluation Using RMSE
The observer gives a so called point estimate x of the state vector x using the
inputs u and measurements of the output y. Suppose that it is possible to gener-
ate M realizations of the data u and y and apply the same estimator to all of them.
For evaluation it is necessary to measure the performance of this estimation. One
such performance measure is the root mean square error (RMSE) described in [13]
RMSE(k) =

_
1
M
M

j=1
||x
k
x
(j)
k
||
2
2
(4.7)
where the subindex 2 stands for the 2-norm, also called the euclidean norm. (The
euclidean norm is dened ||x||
2
=
_
x
2
1
+ +x
2
n
.) This is an estimate of the
standard deviation of the estimation error norm at each time instant. A scalar
measure for the whole data sequence is
RMSE =

_
1
k
k

i=1
1
M
M

j=1
||x
k
x
(j)
k
||
2
2
(4.8)
The scalar performance measure can be used for auto-tuning, as long as it is
possible to generate several data sets under the same premises. Optimally this
should be done using real-life testing (instead of simulation), but this might not
be possible, for instance when it is too expensive to repeat the same experiment
many times. [12]
4.4.2 Autotuning Using Matlab
To automatically nd the optimal parameters for the Kalman lter implemented
at DaimlerChrysler, an optimization algorithm is developed in Matlab. The
algorithm starts with some parameter values, then simulates the system using
these values for the Kalman lter and calculates a cost function based on RMSE
explained in the previous section. The cost function measures how good the actual
26 Choosing the Kalman Filter Parameters
parameters are working. The optimization algorithm then changes the values,
simulates again and calculates a new value for the cost function. The algorithm
continues until optimal values for the parameters are found.
The source code for the script implementing this optimization technique is
found in Appendix A. The code is a modied example from the Optimization
Toolbox [6], and it uses a function called lsqnonlin.
Using this optimization technique does not give a satisfactory result. After sev-
eral (about 100) restarts with dierent starting parameters the script each time
ends up giving almost the same parameters back to the user. The optimization
function does not vary the parameters enough to see if there are any better solu-
tions.
One reason is that Matlabs optimization functions are designed to nd local
minima and they can be fooled, especially by oscillatory functions. They will only
nd a global minimum if it is the only minimum and the function is continuous.
Global optimization problems are typically quite dicult to solve. Methods for
global optimization problems can be categorized based on the properties of the
problem that are used and the types of guarantees that the methods provide for
the nal solution. Simulated annealing is a popular approach for the global
optimization of continuous functions when derivatives of the objective functions
are not available. [21]
4.4.3 Simulated Annealing
The rest of this chapter will be used to present an algorithm implementing the
theory of simulated annealing. More theory of the algorithm can be found in [15],
and the implementation in Matlab developed to do optimization with Simulink
is found in Appendix B.
Simulated annealing (SA) is a stochastic global minimization technique. Given
a function E(s) depending on some parameter vector s = [s
1
, ...s
n
], the SA al-
gorithm attempts to locate a good approximation to the global minimum of the
function.
The name and inspiration come from annealing in metallurgy, a technique in-
volving heating and controlled cooling of a material to increase the size of its
crystals and reduce their defects. The heat causes the atoms to become unstuck
from their initial positions (a local minimum of the internal energy) and the slow
cooling gives them more chances of nding congurations with lower internal en-
ergy than the initial one.
By analogy with this physical process, each step of the SA algorithm considers
some random neighbor s of the current parameter state s, and probabilistically
decides between moving the system to state s or staying in s. This probability is a
function P(E(s), E( s), T) depending on the corresponding values of the function
for the states s and s, and on a parameter T (called the temperature), that is
gradually decreased during the process. There are dierent possibilities to choose
the function P, as long as some constraints are fullled. This will be explained
later.
Another explanation of the simulated annealing algorithm goes as follows. Con-
4.4 Autotuning 27
sider a man running in the mountains. His task is to nd the place with the lowest
altitude. The cost function that should be minimized is in this case the mans
altitude, and the variable T is his current strength. To nd the place with the
lowest altitude (the global minimum) he sometimes has to try running up the hills,
otherwise he may be stuck in a valley (local minimum) not knowing that a better
solution is hiding in another valley behind the next hill. The mans will to go
uphill is larger at the beginning, when his strength T is large. When T tends to
zero the man will only has the strength to run downhill.
Pseudo-Code
The following pseudo-code describes the simulated annealing algorithm. It starts
at a state s
0
and recursively explores the search space using the method described
above. The algorithm continues until a maximum number of evaluations k
max
has been reached, or until a state with the target function value e
target
or less
is found. The function call neighbor(s) should generate a randomly chosen
neighbor of a given state s. The function call random() should return a random
value in the range [0, 1]. The annealing schedule is dened by tempfunction(),
which should yield the temperature to use, given the fraction r of the time that
has passed so far.
s = s0; // Initial state
e = E(s); // Initial function value
s_best = s; // Initial best parameters
e_best = e; // Initial function minimum
T = initialtemperature(k_max); // Initial temperature
k = 0; // Evaluation count
while k < k_max and e > e_target // While not good enough
s_neighbor = neighbor(s); // Pick some neighbor
e_neighbor = E(s_neighbor) // Compute its function value
if e_neighbor < e_{best} then // Is this a new best?
s_best = s_neighbor; // Yes, save it
e_best = e_neighbor;
end if
if random() < P(e, e_neighbor, T) // Move to the neighbor state?
s = s_neighbor; // Yes, change state
e = e_neighbor;
end if
T = tempfunction(T,k/k_max); // Calculate new temperature
k = k + 1; // Count evaluations
end while
return s_best; // Return best solution found
Implementation of the SA-Algorithm
In order to apply the SA method to a specic problem, one must specify the
parameter search space, the neighbor selection method, the probability transition
28 Choosing the Kalman Filter Parameters
function, and the annealing schedule (temperature function). These choices can
have a signicant impact on the eectiveness of the method. Unfortunately, there
are no choices that will be good for all problems, and there is no general way to
nd the best choices for a given problem. It has therefore been observed that
applying the SA method is more an art than a science.
In the following subsections it is explained how the algorithm is implemented.
The general demands and calculations are described here, and the complete imple-
mentation of the algorithm in Matlab can be found in Appendix B. The script
can be used to perform auto-tuning on the lter.
Choosing the Neighbors
The neighbors of the current state have to be chosen so that the function values of
the neighboring states are not too far away from the function value of the current
state. This makes the probability of moving to the new state higher, and in this
way the algorithm can move on nding a good solution. It is true that choosing
a neighbor far away from the current state could lead to nding the best solution
faster, but this also leads to a low probability of moving to the new solution and
the risk of getting stuck in a non-optimal solution is higher.
In the Matlab implementation found in Appendix B, the neighbors s to the
current state s are found by moving a random distance from s in a random direc-
tion. The distance has been chosen as a value between 0.5 and +0.5 times the
current parameter vector s. The Matlab-code is as follows
move = (rand(1,3)-0.5).*s; % Randomize between -0.5 and +0.5
s_neigbour = s + move; % Calculate new parameters
Transition Probability Function P
The function P calculates the probability of making the transition from the current
state s to a candidate new state s. The function depends on the corresponding
function values E(s) and E( s), and the temperature T. The probability (a number
between 0 and 1) should be greater than 0 when E( s) > E(s). This is an essential
requirement meaning that the system may move to the new state even when its
solution is worse than the current one. It is this feature that prevents the method
from becoming stuck in a local minimum. As the algorithm evolves and T goes to
zero, the probability P must tend to zero if E( s) > E(s) and to a value greater
than zero if E( s) < E(s). This makes the system favor moves that go downhill
and avoid those that go uphill. When T is zero the algorithm will fall down to
the nearest local minimum.
In the implementation found in Appendix B the probability is calculated as
P =
_
1 if E( s) < E(s)
e
E(s)E( s)
T
otherwise
(4.9)
This is the method used in [21] and [15]. However, there is no mathematical
justication for using this particular formula in SA, other than the fact that it
corresponds to the requirements explained above. The Matlab-code is as follows
4.4 Autotuning 29
function P = transition_P(E, E_neighbor, T)
if E_neighbor < E
P = 1; % Always go down the hill
else
P = exp((E-E_neighbor)/T); % Move if temperature is high
end
end
Annealing Schedule
The annealing schedule must be chosen with care. The initial temperature must be
large enough to make the uphill and downhill transition probabilities nearly
the same. To do that, one must have an estimate of the dierence E( s) E(s) for
a random state and its neighbors. The temperature must then decrease so that it
is zero, or nearly zero, when the algorithm is supposed to nish. For this thesis
an exponential schedule has been chosen, where the temperature decreases by a
xed cooling factor 0 < < 1 at each step. The temperature T
k
for the current
time step k is calculated using the cooling factor and the temperature from the
previous time step, T
k1
, as
T
k
= T
k1
(4.10)
The initial temperature T
0
and the cooling factor now have to be chosen.
Typically they are obtained by trial and error and tuned to the function E, which
should be minimized. In the problem at hand, this function depends on the simu-
lated model, and as the evaluation of this function involves running a simulation
in Simulink, such tuning procedures are impractical. What is needed is an au-
tomatic and reasonable way of setting these parameters based on some initial
information obtained by the algorithm. Such a method is presented in [21] and
used in this Masters thesis.
Let s
0
be the initial state of the system. To pick the initial temperature T
0
,
generate a set of solutions that lies in the neighborhood of s
0
. Let s
bestn
and s
worstn
be the best and worst among the neighbor solutions. If E(s
worstn
) > E(s
0
), dene
the maximum uphill move as maxmove = E(s
worstn
) E(s
0
). Otherwise, dene
maxmove = E(s
0
) E(s
bestn
).
It is now reasonable to assume that the initial temperature T
0
is high enough
if an uphill move maxmove will be accepted with a relatively high probability,
say 0.9. Setting P = 0.9 for an uphill move of maxmove, (4.9) gives
0.9 = e

maxmove
T
(4.11)
and T = T
0
can be calculated.
Next, the cooling parameter is calculated. To do this, assume that the nal
acceptance probability for an uphill maxmove should be very low, say 10
6
. If
the nal probability is too high, the algorithm still behaves like a random search.
As k
max
is the maximum number of function evaluations allowed, this is also the
number of times the temperature is reduced. (4.9) now gives
10
6
= e
maxmove
T
0

k
max
(4.12)
30 Choosing the Kalman Filter Parameters
and can be obtained.
Restarting
The SA-algorithm uses a random method to nd the solution, which means that
several executions may give dierent outputs. When a better solution is needed,
and more computer time is available, instead of justifying the maximum number
of iterations allowed (k
max
), it is sometimes better to start the algorithm over
with a new initial state s
0
. Moving back to a solution that was signicantly better
rather than always moving from the current state is called restarting. The decision
to restart could be based on a xed number of evaluation steps, or based on the
current function value being too high from the best value so far. The Matlab
implementation found in Appendix B can be executed recursively and the starting
parameter state s
0
for the next iteration is set to the best solution found in the
previous iteration. In this way the algorithm can be left running for a long time,
restarting over and over again using the previous best solution found as the new
initial solution.
Results
Figure 4.2 shows one execution of the SA script with 200 closed-loop simulations
in the rst scenario (the hill) described in Section 4.3.2. The upper diagram is the
cost function described in Section 4.4.1, calculated by using the dierence between
the lter estimate and the real value. The diagram shows that the SA-algorithm
is trying to nd the global minimum of the cost function, but does not get stuck in
local minima. The allowance for parameter changes causing a higher value of the
cost function is high in the beginning, but decreases together with the temperature
shown in the lower diagram.
4.4 Autotuning 31
Figure 4.2. One execution of the simulated annealing (SA) algorithm using 200 evalu-
ations. By analogy with the physical process, each step of the SA algorithm probabilis-
tically decides between moving the system to the new state or staying in the old state.
The probability depends on the parameter T (called the temperature). The top diagram
shows the RMSE costfunction for all the states evaluated. The bottom diagram shows
the temperature that is gradually decreasing during the process. As can be seen, the
current solution changes almost randomly when T is large. This allowance for uphill
moves saves the method from becoming stuck at local minima.
32 Choosing the Kalman Filter Parameters
Chapter 5
Kalman Filter
Implementation
In this chapter the model for the longitudinal dynamics of the vehicle is derived,
and an initial version of the Kalman lter is implemented and tested. First the
function of the observer in the context of the inner control loop wil l be explained
and then a model for the expected acceleration of the vehicle wil l be derived. It
wil l be shown that this model cannot take al l driving situations into consideration,
resulting in a large error in the calculated acceleration. To deal with this error, a
Kalman lter is implemented. In the end of this chapter a discussion wil l be held
on how to best choose the lter parameters.
5.1 Overview of the Inner Control Loop
Before implementing the Kalman lter, a short explanation of its surroundings,
the inner control loop of the vehicle longitudinal controller, is needed.
An overview of the inner control loop is given in Figure 5.1. (For a complete
diagram of the outer and inner control loop, refer to Figure 1.1.) The controlled
system is the vehicle with its actuators engine, brake and gearbox. The desired
engine torque T
e
and the desired brake torque T
b
are calculated and given as input
to the actuators. The output from the controlled system is the actual motion
of the vehicle and can be thought of as the actual speed v
real
and the actual
acceleration a
real
.
The block Sensors in the gure contains signal processing software which
analyzes the motion of the vehicle and gives information back to the controller.
The measured speed v
m
and acceleration a
m
are derived from wheel speed sensors.
Input to the controller is the desired acceleration a
des
. The momentary devi-
ation a
dev
from the desired value is calculated as
a
dev
= a
des
a
m
(5.1)
This deviation is fed into a PID-controller which calculates a control value to the
33
34 Kalman Filter Implementation
-
a
des
+
f -
a
dev
PID
-
+
f -
a
c
F
1
-
T
F
2
T
e
, T
b
q-
Vehicle
v
real
, a
real

Sensors

v
m
Observer
a
z
6

a
m

Figure 5.1. Inner control loop of the longitudinal controller. Input to the controller
is the desired acceleration a
des
. Sensors are measuring the real speed v
real
and accel-
eration a
real
of the vehicle, and the task is to get a
real
= a
des
. The deviation a
dev
is
given as input to a PID-controller. The control value a
c
is converted by two conver-
sion functions F
1
and F
2
into the torques T
e
and T
b
, which are given as input to the
vehicles actuators engine and brake, respectively. The observer looks at the torques T
e
and T
b
and calculates the expected acceleration of the vehicle. The output a
z
from the
observer is the estimated dierence between the expected acceleration and the measured
acceleration. This is summarized with the output from the PID-controller, forming a
c
.
actuators which minimizes the deviation. The output from the PID-controller will
form the variables T
e
and T
b
described above, after passing through two conversion
steps F
1
and F
2
.
The block F
1
calculates the needed torque T on the wheel axis from the corre-
sponding acceleration a
c
, using the equation
T = r
w
(a
c
m+F
resistance
) (5.2)
Since m is the standard mass of the vehicle plus the moments of inertia of the
wheel axis and other rotating parts, then a
c
m is the force needed to get the desired
acceleration a
c
. The other force taken into consideration here, F
resistance
, is acting
on the vehicle in its opposite direction of travel and is called drive resistance.
It consists of the force due to air resistance, losses due to tire deection, etc, and
will be described in detail in Section 5.2. By adding F
resistance
to a
c
m and then
multiplying with the wheel radius r
w
, T is the torque needed on the wheel axis to
give the vehicle the acceleration a
c
.
The output torque T is fed into another block, called F
2
in the gure, before
delivery to the actuators. F
2
coordinates the work of the engine, brake and gear-
box. Depending on the calculated torque T, action is taken either by the brake or
the engine, whereas the engine also can be used to decelerate.
a
c
is, as explained above, the control value from the controller given as input
to the block F
1
. It consists of two parts: the output from the PID-controller, and
the output from the block Observer. The task of the observer is to estimate
5.2 Modeling the Acceleration 35
T
e
-
G
e
-
T
engine
T
b
-
G
b
-
T
brake
Longitudinal Dynamics
-
v
real
a
real
Vehicle Model
Figure 5.2. Modeling engine and brake. The blocks G
e
and G
b
model the dynamics
of the engine and brake respectively. T
e
and T
b
are the desired torques given as input.
The engine and brake models calculate the estimated output torques T
engine
and T
brake
.
The model of the longitudinal dynamics uses these values to calculate the speed and
acceleration of the vehicle.
the drive resistance parameters and other unknown parameters not taken into
consideration by F
1
. This is performed by looking at the torques T
e
and T
b
given
to the actuators, and calculate an expected acceleration. The dierence between
the expected acceleration and the measured acceleration gives a hint about the
model error. This error, called a
z
, is subtracted from the output from the PID-
controller to form a
c
.
The block called Vehicle is further described in Figure 5.2. The blocks G
e

and G
b
model the dynamics of the engine and brake as transfer functions with
torques T
engine
and T
brake
as outputs. These transfer functions and the equations
describing the vehicle longitudinal dynamics will be presented in the next section.
5.2 Modeling the Acceleration
A model for the expected longitudinal acceleration of the vehicle will now be
presented. Assume just for this section that the speed of the vehicle is v and
the acceleration of the vehicle in its driving direction is a. These are the variable
names used in this section for deriving the model, in later sections the acceleration
calculated by the model will be called a
exp
, and for the vehicle speed the measured
value v
m
will be used.
Using the classical mechanical law from Newton,

F = ma, the forces acting
on the vehicle can be written as
ma = F
drive
F
brake
F
resistance
(5.3)
where F
drive
is the force acting on the vehicle through the transmission and engine,
and F
brake
is the force from the braking system. The drive resistance F
resistance
is modeled as
F
resistance
= F
air
+F
roll
(5.4)
36 Kalman Filter Implementation
When a wheel is rolling, energy losses occur due to deection of the tire. This
is modeled as a force acting on the wheel in the opposite direction of rolling
F
r
= c
rr
N (5.5)
where N is the normal force acting on the wheel from the ground and c
rr
is the
rolling resistance coecient [20]. N is in this case dened as
N =
mg
n
(5.6)
where m is the mass of the vehicle, g is the gravitational acceleration and n is the
number of wheels. Assuming that all wheels have the same c
rr
, the total rolling
resistance acting on the vehicle from all wheels can be calculated
F
roll
= F
r
n = c
rr
mg
n
n = c
rr
mg (5.7)
The air resistance F
air
is modeled as follows. When an object is moving through
air at relatively high speed, the object experiences a force acting on it against its
direction of travel. This force can according to [14] be written as
F
air
=
1
2
c
d
A
w
(v +v
wind
)
2
(5.8)
where is the density of the air, c
d
is the drag coecient and A
w
is a reference
area related to the projected front area of the object. v
wind
is the unknown speed
of the wind and it will therefore be neglected in this model.
F
drive
and F
brake
depend on the torques acting on the wheel axis, T
drive
and
T
brake
, and the wheel radius r
w
as
F
drive
=
T
drive
r
w
(5.9)
F
brake
=
T
brake
r
w
(5.10)
The torque acting on the wheel axis T
drive
depends on the output torque from the
engine T
engine
, the gearbox and dierential ratios i
g
and i
d
, the eciency factor
for the drivetrain , the moment of inertia for engine and gear, I
e
and I
g
, and the
moment of inertia for the front and rear wheel axis, I
f
and I
r
, as follows [20]
T
drive
= i
d
i
g
T
engine
(i
2
d
i
2
g
I
e
+i
2
d
I
g
)
a
r
w
(I
f
+I
r
)
a
r
w
(5.11)
Inserting (5.4), (5.7), (5.8), (5.9), (5.10) and (5.11) in (5.3) yields
ma =
1
r
w
i
d
i
g
T
engine
(i
2
d
i
2
g
I
e
+i
2
d
I
g
)
a
r
2
w
(I
f
+I
r
)
a
r
2
w

1
r
w
T
brake

1
2
c
d
A
w
v
2
c
rr
mg (5.12)
5.2 Modeling the Acceleration 37
Now let
m = m+
I
f
+I
r
r
2
w
+i
2
d
i
2
g
I
e
r
2
w
+i
2
d
I
g
r
2
w
(5.13)
Inserting (5.13) in (5.12) gives
ma =
i
d
i
g
r
w
T
engine

1
r
w
T
brake

c
d
A
w
2
v
2
c
rr
mg (5.14)
Dividing with m yields the equation for the vehicle acceleration as
a =
i
d
i
g
r
w
m
T
engine

1
r
w
m
T
brake

c
d
A
w
2 m
v
2

c
rr
mg
m
(5.15)
In previous work at DaimlerChrysler [19], models for the engine and brake were
prepared. The results are averages of several tests with dierent vehicles and will
be presented here and used in this Masters thesis. See [19] for more details.
The engine is modeled as a transfer function G
e
(s) as
G
e
(s) = L{g
e
(t)} =
k
1

2
0
s
2
+ 2D
0
s +
2
0
e
sT
t1
(5.16)
which relates the input torque T
e
to the output torque from the engine, T
engine
,
as
T
engine
(t) = g
e
(t) T
e
(t) (5.17)
In the same way, the brake is modeled as a transfer function G
b
(s) as
G
b
(s) = L{g
b
(t)} =
k
2
T
t2
s + 1
e
sT
t3
(5.18)
which relates the input torque T
b
to the output torque from the brake, T
brake
, as
T
brake
(t) = g
b
(t) T
b
(t) (5.19)
The parameters in the models were found in [19] using system identication and
chosen to the mean values of dierent test drives with dierent vehicles as
k
1
= 1

0
= 16.7 rad/s
D = 0.82
T
t1
= 90 ms
k
2
= 0.98
T
t2
= 80 ms
T
t3
= 140 ms
Adding this information to (5.15) gives the model for the longitudinal acceler-
ation of the vehicle used by the Kalman lter
a(t) =
i
d
i
g
r
w
m
(g
e
(t) T
e
(t))
1
r
w
m
(g
b
(t) T
b
(t))
c
d
A
w
2 m
v(t)
2

c
rr
mg
m
(5.20)
In Section 5.4 this calculated (expected) acceleration will be called a
exp
.
38 Kalman Filter Implementation
0 10 20 30 40 50 60
-1.5
-1
-0.5
0
0.5
1
1.5
Speedtronic: step down and up again
Time [s]
A
c
c
e
l
e
r
a
t
i
o
n

[
m
/
s
2
]
a expected
a measured
Figure 5.3. Test drive using cruise control. The vehicle is traveling with a speed
of 60 km/h when the driver changes the set desired speed to 30 km/h, then after
nearly 30 seconds changes back to 60 km/h again. The gure shows the calculated ex-
pected acceleration (solid line) and the measured acceleration (dashed line). The mea-
surement has been recorded during a test with a relatively nervous controller, causing
the large oscillations between 10 and 20 seconds.
5.3 Errors in the Acceleration Model
A thorough validation of the acceleration model is not a subject of this Masters
thesis. But to verify that the model seems reasonable, some tests will now be
presented. During test drives, the signal a
m
from the sensors is recorded. This
measurement of the actual acceleration is then compared with the expected accel-
eration calculated by the model in (5.20). In this section ve such recordings will
be presented.
Figure 5.3 shows a test drive using cruise control (explained in Section 2.5).
The vehicle is traveling with a speed of 60 km/h when the driver changes the set
desired speed to 30 km/h, then after nearly 30 seconds changes back to 60 km/h
again. The gure shows the calculated expected acceleration (solid line) and the
measured acceleration (dashed line).
Figure 5.4 shows a similar test drive using cruise control, this time with set
speeds 60 km/h, 30 km/h, 60 km/h and then 30 km/h again.
In both Figure 5.3 and Figure 5.4 it can be observed that the agreement be-
tween the measured and calculated expected acceleration is relatively good. The
main characteristics of the acceleration has been captured by the model. Some dif-
ferences between the calculated and the measured signal can be seen in the gures.
This is expected, as the model does not exactly describe the specied vehicle. The
model parameters have been chosen as the mean values from several test drives
5.3 Errors in the Acceleration Model 39
0 10 20 30 40 50 60
-2
-1.5
-1
-0.5
0
0.5
1
1.5
Speedtronic: step up
Time [s]
A
c
c
e
l
e
r
a
t
i
o
n

[
m
/
s
2
]
a expected
a measured
Figure 5.4. Test drive using cruise control. The vehicle is traveling with a speed
of 60 km/h when the driver changes the set desired speed rst to 30 km/h, then back
to 60 km/h, and at last to 30 km/h again. The solid line is the calculated expected
acceleration and the dashed line is the measured acceleration.
with dierent vehicles [19]. Therefore the model does not exactly comply with the
vehicle being used here.
Figure 5.5 shows the vehicle traveling with a constant speed of 30 km/h on
a bumpy road. The vehicle looses speed and the controller tries to compensate,
resulting in an oscillatory behavior. As can be seen, also here the agreement
of the measured and calculated acceleration can be recognized. An outstanding
feature of the calculated value is that it is always a bit, and sometimes up to 0.5 s
faster than the measured value. The reason for this could be that the identied
time-delays in the models for the engine and brake are too small when applied
to the vehicle used in the tests. Another reason is that the measurement of the
acceleration in the vehicle contains a low-pass lter with some time-delay. In
Figure 5.5, the calculated value is always a bit higher than the measured value.
The reason for this might be that the rolling resistance on the bumpy road is
higher than expected, and that the mass of the vehicle is higher than set in the
model, due to one extra passenger.
As can be seen in Figure 5.6 and Figure 5.7, the model does not perform as well
when changing the working conditions. In Figure 5.6 a test has been made using
the same vehicle but with an attached trailer with a mass of 2000 kg. The vehicle
is traveling using cruise control, with a desired speed of 60 km/h. After 16 seconds
the desired speed is changed to 80 km/h. As can be seen, the calculated expected
acceleration does not comply with the the measured acceleration in this case. The
large errors in the calculations is because of a wrong value of the parameter m,
the mass of the vehicle. In the current model, the vehicle mass is a constant
40 Kalman Filter Implementation
20 25 30 35 40 45 50
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
Constant speed, bumpy road
Time [s]
A
c
c
e
l
e
r
a
t
i
o
n

[
m
/
s
2
]
a expected
a measured
Figure 5.5. Test drive using cruise control on a bumpy road. The vehicle is traveling
with a constant speed of 30 km/h. It looses speed and the controller tries to compensate,
in this test resulting in an oscillating behavior. The test has been done using a relatively
nervous controller.
0 5 10 15 20 25 30 35 40 45
-0.5
0
0.5
1
1.5
2
2.5
Speedtronic: step up and down, trailer 2000 kg
Time [s]
A
c
c
e
l
e
r
a
t
i
o
n

[
m
/
s
2
]
a expected
a measured
Figure 5.6. Test drive with a heavy trailer (2000 kg). The vehicle and trailer are
traveling using cruise control, with a desired speed of 60 km/h. After 16 seconds the
desired speed is changed to 80 km/h. As can be seen the calculated expected acceleration
does not comply with the the measured acceleration. The large errors in the calculations
is because of a wrong value of the parameter m, the mass of the vehicle.
5.3 Errors in the Acceleration Model 41
0 5 10 15 20 25
-6
-5
-4
-3
-2
-1
0
1
2
3
Driving up and down a hill, incline: 20% up, 15% down
Time [s]
A
c
c
e
l
e
r
a
t
i
o
n

[
m
/
s
2
]
a expected
a measured
Figure 5.7. Test drive up and down a steep hill using cruise control. First the slope of
the road is 0 % (horizontal road), then changed to 20 % (uphill), then to 15 % (downhill).
The calculated acceleration does not comply with the measured acceleration. The reason
is that the model does not include the case of a changed road slope.
parameter. Figure 5.7 shows a test drive with the same vehicle, this time without
trailer but with a changing slope. The vehicle is driven up and down a steep
hill. First the slope of the road is 0 % (horizontal road), then changed to 20 %
(uphill), then to 15 % (downhill). As expected, the calculated acceleration does
not comply with the measured acceleration. The model does not include the case
of a changing slope.
It should be mentioned that all models have errors. It does not matter how
complex the model is, it will in practice never exactly describe the real physical
system. In many implementations there are good reasons to keep the model simple.
Especially for real time systems it is a good practice to keep models as simple as
possible to avoid time consuming computations and dubious parameters.
In this case the model for the vehicle acceleration in (5.20) does not comply
with the real system in all situations. The following are some examples of what
might happen. Two of the cases have already been mentioned before in this text.
The total mass of the vehicle is not m as in the model, due to extra pas-
sengers, baggage or a trailer. This aects the calculation of m in (5.13) as
well as F
roll
in (5.7) and has a large eect on the calculation of the expected
acceleration in (5.20). The value of the parameter m is set to the mass of
the vehicle including full tank, plus 80 kg for the weight of the driver. If the
attached trailer is equipped with brakes, the large change in the mass will
only be experienced when accelerating. When braking, the trailer brake will
help and compensate partially for the extra weight.
42 Kalman Filter Implementation
The parameter c
rr
in (5.7) is in the model set to a constant value. In practice,
however, the rolling resistance changes depending on the driving conditions,
for example in case of tire-pressure drop or when driving on sand. According
to [8] the real value of the parameter can vary up to 3.5 times the standard
value.
In the calculation of the air resistance F
air
in (5.8), the speed of the wind
v
wind
cannot be taken into account. In real life the wind speed can have
a large impact on the actual resistance. The drag coecient c
d
might also
change, as well as the reference area A
w
(for example due to extra baggage).
According to [8] the real value of F
air
can be up to 9 times the calculated
value.
All the parameters in (5.16) and (5.18) have been estimated with system
identication. From several test drives the mean values have been selected.
These parameters dier from those found in a real vehicle. As an example
the interval for the engine parameters in (5.16) were found to be [19]
15.1 <
0
< 19.2
0.54 < D < 1.05
0.07 < T
t1
< 0.12
The slope has been totally neglected in the derived model. When driving the
vehicle in a slope, a force F
slope
arises having a direct eect on the vehicles
acceleration. Assume that the slope of the road is , the longitudinal force
acting on the vehicle is given by
F
slope
= mg sin (5.21)
Engine and brake might not behave as expected due to inaccuracy, errors or
change in the friction coecient of the brakes. This is observed to happen
relatively often. For example, the friction coecient of the brake may vary
between +10% and 15% during a normal vehicle stop maneuver.
Actually there is a longitudinal acceleration sensor mounted in the vehicles
that could be used to estimate the slope . The sensor measures the sum of the
vehicles acceleration and the gravitational component parallel to the ground, as
a
sensor
= a +g sin (5.22)
where a
sensor
is the sensor value and a is the longitudinal acceleration of the
vehicle. One problem with the sensor is that it might be dicult making good
estimates of the road slope while cornering. In [16] it is proposed how to do road
slope and vehicle mass estimation using Kalman ltering.
5.4 Kalman Filter Model 43
5.4 Kalman Filter Model
The model for the vehicle longitudinal acceleration a in (5.20) has to be changed
to comply with the real world. Therefore, let the calculated expected accelera-
tion a
exp
be dened as
a
exp
=
i
d
i
g
r
w
m
T
engine

1
r
w
m
T
brake

c
d
A
w
2 m
v
2
m

c
rr
mg
m
(5.23)
This is the model that was derived in Section 5.2. Then the real vehicle accelera-
tion a
real
is
a
real
= a
exp
+a
z
(5.24)
where a
z
is called disturbance acceleration. This state variable represents the
part of the vehicles acceleration caused by disturbances not described by the
model for the longitudinal dynamics. It should cover all the model errors found in
the previous section, and is connected parallel to the PID-controller as described
in Section 5.1 and shown in Figure 5.1. Given a good description on how the
state a
z
is changing, the Kalman lter can be used to estimate this state.
The process noise is modeled in continuous time under the assumption that
the state a
z
undergoes slight changes each sampling period. According to [3] such
changes can be modeled by a continuous time Gaussian noise w as
a
z
(t) = w(t) (5.25)
where
E[w(t)] = 0 (5.26)
E[w(t)w()] = q(t ) (5.27)
The scalar value q is here the process noise intensity (assumed to be time-invariant)
and () is the Dirac (impulse) delta function [3].
Using the state-space model presented in (3.1) and (3.2), and choosing the
state vector x = a
z
, the continuous time state-space model for the Kalman lter
becomes
x =
_
0

. .
A
x +
_
1

. .
G
w (5.28)
y =
_
1

. .
C
x +e (5.29)
Here y = x+e = a
z
+e means that the Kalman lter needs a measurement of the
signal a
z
. This can be provided by feeding it with a new constructed signal a

.
With the denition a
m
= a
real
+e together with (5.24), a

can be dened as
a

= a
m
a
exp
= a
z
+e (5.30)
44 Kalman Filter Implementation
In this way, the Kalman lter will estimate the state a
z
, given the information
that a

is a noisy measurement of the true value. How noisy the measurement is


can be dened by modeling e. Here e will be modeled as Gaussian noise in the
same way as w
E[e(t)] = 0 (5.31)
E[e(t)e()] = r(t ) (5.32)
The scalar value r is here the measurement noise intensity. It is assumed to be
time-invariant.
The system is observable, as can be veried using the rank test in Section 3.4.
This means that the state is uniquely determinable from the inputs and outputs
in the model.
The state-space model is discretized into a digital state-space model with sam-
ple time T, using the theory in Section 3.2. In this case it is easy, resulting in
x
k+1
=
_
1

. .
A
d
x
k
+
_
1

. .
G
d
w
k
(5.33)
y
k
=
_
1

. .
C
d
x
k
+e
k
(5.34)
5.5 Choosing the Filter Parameters
Dierent values of the noise intensities q and r will now be chosen and the per-
formance evaluated using open-loop simulation described in Section 4.3.1. It is
possible to use other methods from Chapter 4, for example the script for autotun-
ing developed in Section 4.4. However, since the estimated signal a
z
in this case
will be directly connected to the engine and brakes (see Figure 5.1), the signal
will direct aect the comfort of the driver and passengers. Therefore this section
will show the function of the developed Kalman lter by choosing the parameters
manually.
As explained in Section 4.2 the quotient between q and r is the design param-
eter, the absolute values do not matter. Therefore r is set to 1 and the Kalman
lter is simulated using dierent values for q. The gures that follow have been
generated using measured data from test drives. The Kalman lter is fed with the
signal y = a

= a
m
a
exp
, and those values are also shown in the gures as dots.
Figure 5.8 shows two dierent Kalman lters, one with q = 1 and the other
with q = 0.01. As can be seen, the one using q = 1 is faster and follows the
measured values more accurately. This was expected, as choosing a high q always
means a faster lter. The faster lter is more sensitive to measurement noise,
while the slower lter delivers a smoother estimate of a
z
. The measurement is
taken from a test drive on a bumpy road.
Figure 5.9 shows the same parameter choices, but this time with a measurement
of a vehicle driven up and down a steep hill. The output from the Kalman lter
with q = 1 follows the measurement almost exactly. It can be seen that, comparing
5.5 Choosing the Filter Parameters 45
2 2.5 3 3.5 4 4.5 5 5.5 6 6.5 7
-1.2
-1
-0.8
-0.6
-0.4
-0.2
0
Time [s]
D
i
s
t
u
r
b
a
n
c
e

[
m
/
s
2
]
a

= a
m
-a
exp
Kalman filter (q=1)
Kalman filter (q=0.01)
Figure 5.8. Simulation of two fast lters with dierent parameters (q = 1 and q = 0.01)
using a measurement of a test drive on a bumpy road. The lter with q = 1 is fastest
and follows the measured values most accurate. This was expected, as choosing q high
always means a faster lter. The faster lter is also more sensitive to measurement noise.
The slower lter delivers a smoother estimate of a
z
.
with the faster lter, a smaller q makes the time delay for large signal changes
unavoidable larger. The Kalman lter q = 0.01 still reacts relatively fast and
when only looking at these two gures (5.8 and 5.9) q = 0.01 seems a logical
choice.
However, every unnecessary oscillation or jerk in the estimate a
z
will have a
direct eect of the control values for the engine and brakes. It has been observed
during test drives that the comfort is negatively aected by having a too fast lter.
With this in mind, two slower lters are evaluated, shown in the next two gures.
This time q = 0.001 and q = 0.0003 are simulated. Figure 5.10 shows the drive
on the bumpy road. The Kalman lter now ignores the oscillations even more,
making it better for controlling purposes. The price one has to pay, as shown in
Figure 5.11, is an even slower lter.
The time delay for the lter with q = 0.0003 is so large that the driver will
probably feel it when driving up and down the hill shown in Figure 5.11. The
hill is rather steep, and the change from the horizontal road to a slope of 20%
comes very fast. The task of choosing the optimal parameters is in this case a
compromise between ignoring small changes in the signal, or react fast to large
changes. A linear lter of this type cannot do both.
Figure 5.12 shows the slowest lter (with q = 0.0003) during a drive on a very
bumpy road. The oscillations of the signal y = a

= a
m
a
exp
are even larger
than in the previous gures. Even the slowest of the tested Kalman lters is in
46 Kalman Filter Implementation
4 6 8 10 12 14 16 18
-2
-1.5
-1
-0.5
0
0.5
1
1.5
2
2.5
Time [s]
D
i
s
t
u
r
b
a
n
c
e

[
m
/
s
2
]
a

= a
m
-a
exp
Kalman filter (q=1)
Kalman filter (q=0.01)
Figure 5.9. Simulation of the two fast lters using a measurement of a test drive of a
vehicle driving up and down a steep hill. The output from the Kalman lter with q = 1
follows the measurement almost exactly. It can be seen that, comparing with the faster
lter, a smaller q makes the time delay for large signal changes unavoidably larger. The
Kalman lter q = 0.01 still reacts relatively fast.
this case not slow enough. But choosing a slower lter will also make the time
delay for changes even larger. The ideal lter would ignore these oscillations, but
still react fast to large changes.
5.5 Choosing the Filter Parameters 47
2 2.5 3 3.5 4 4.5 5 5.5 6 6.5 7
-1.2
-1
-0.8
-0.6
-0.4
-0.2
0
Time [s]
D
i
s
t
u
r
b
a
n
c
e

[
m
/
s
2
]
a

= a
m
-a
exp
Kalman filter (q=0.001)
Kalman filter (q=0.0003)
Figure 5.10. Simulation of two slow lters (q = 0.001 and q = 0.0003) using measure-
ments from a test drive on a bumpy road. The slow Kalman lters ignore the oscillations
even more, making them better for controlling purposes.
4 6 8 10 12 14 16 18
-2
-1.5
-1
-0.5
0
0.5
1
1.5
2
2.5
Time [s]
D
i
s
t
u
r
b
a
n
c
e

[
m
/
s
2
]
a

= a
m
-a
exp
Kalman filter (q=0.001)
Kalman filter (q=0.0003)
Figure 5.11. Simulation of the two slow lters (q = 0.001 and q = 0.0003) using
measurements from a test drive with a vehicle driving up and down a steep hill. When
trying to avoid small changes and oscillations, the price one has to pay is a slower lter.
48 Kalman Filter Implementation
14 16 18 20 22 24 26 28 30
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
Time [s]
D
i
s
t
u
r
b
a
n
c
e

[
m
/
s
2
]
a

= a
m
-a
exp
Kalman filter (q=0.0003)
Figure 5.12. Simulation of the slowest Kalman lter using a measurement of a very
bumpy road. Even this lter is in this driving situation not slow enough. But choosing
such a slow lter will also make the time delay for changes even larger.
Chapter 6
Alternative Kalman Filter
Models
As shown in Chapter 5, the behavior of the Kalman lter is easy to understand
when using simple models. Another advantage of using simple models is low com-
putational eort. This chapter derives some more complex models, with the aim
of explaining how the Kalman lter implemented in the test vehicles is working.
First a model is presented which can be used when it is not possible to measure
the acceleration. Then other models of the parameter a
z
is derived. At the end of
this chapter it is shown that the implemented Kalman lter behaves like a low-pass
lter.
6.1 Vehicle Speed as Feedback
In some situations it is not practical to use the signal a

= a
m
a
exp
as feedback
to the lter, for example when the signal a
m
is not available. This is the case
at DaimlerChrysler when using hill descent control (explained in Section 2.6). In
this situation the measurement of the acceleration by conventional methods is not
considered good enough. In this case the measurements of the vehicle speed, v
m
,
can be used instead. The Kalman lter is then designed using the state vector
x =
_
x
1
x
2
_
=
_
v
real
a
z
_
(6.1)
so that
v
real
= a
real
= a
z
+a
exp
(6.2)
a
z
= w (6.3)
Input to the lter is the signal a
exp
, as dened in (5.23), and the (assumed noisy)
measurement v
m
of the vehicle speed v
real
, with
v
m
= v
real
+e (6.4)
49
50 Alternative Kalman Filter Models
where e is the measurement noise and w is the process noise, modeled as described
in Section 5.4. Notice that e is the noise in the measurement of the speed, and
not the acceleration as in Section 5.4. The state-space model becomes
x =
_
0 1
0 0
_
. .
A
x +
_
1
0
_
. .
B
a
exp
+
_
0
1
_
. .
G
w (6.5)
y =
_
1 0

. .
C
x +e (6.6)
The noises w and e are modeled as Gaussian noises with intensities r and q.
Simulating the lter with the same measurements as in Chapter 5 shows that the
basic behavior remains the same. Figure 6.1 shows the output from the lter when
fed with the measurement from the test drive on the bumpy road. The process
noise intensity q has been chosen to 5 and measurement noise intensity r is 1.
Figure 6.2 shows the same lter simulated with the measurement from the drive
up and down the steep hill. The dotted line is a

= a
m
a
exp
as dened in (5.30),
which still can be used as a reference. The dashed line in the gures is the output
from the lter in Section 5.5, which used a

as feedback. As can be seen the


overall behavior is the same.
The Kalman lter now has to estimate both v
real
and a
z
, resulting in higher
computational costs. Choosing a smaller q makes the lter slower, and choosing a
larger q makes it faster, just as before. Of course the value of q is not the same as
in Section 5.5 because the measurements are no longer the same.
6.2 Modeling the Disturbance a
z
The model of a
z
so far says that its rst derivative is equal to Gaussian noise. This
means that a
z
undergoes slight changes each sampling period. These changes are
uncorrelated, which means that the derivative changes each period to a value
independent of the last value. This model allows the derivative of a
z
to jump
quickly from a positive value to a negative, which does not comply with the real
parameter the lter is trying to estimate. a
z
represents large changes in the
environment of the vehicle, such as changes in the mass of the vehicle or the slope
of the road. These parameters do not change so quickly, and therefore another
model will now be examined.
6.2.1 First-Order Lag Function
For a rst-order lag function with input signal u, the output signal y satises the
ordinary dierential equation
y +y = u (6.7)
where is the time constant of the step response. The transfer function is
G(s) =
1
1 +s
(6.8)
6.2 Modeling the Disturbance a
z
51
2 2.5 3 3.5 4 4.5 5 5.5 6 6.5 7
-1.8
-1.6
-1.4
-1.2
-1
-0.8
-0.6
-0.4
-0.2
0
Time [s]
D
i
s
t
u
r
b
a
n
c
e

[
m
/
s
2
]
a

=a
m
-a
exp
Kalman filter with v as feedback
Kalman filter from Chapter 5 (q=0.0003)
Figure 6.1. Simulation of the Kalman lter using the measurement from the drive on
a bumpy road. Input to the lter is the measurement of the vehicle speed. q has been
chosen to 5. The solid line is the Kalman lter with the measurement of v as feedback.
The dashed line is the lter developed in Section 5.5. As can be seen the overall behavior
of the lter remains the same.
To evaluate the frequency response for the function, set s = j and plot the
magnitude of the function
|G(j)| =
1

1 +
2

2
(6.9)
is here the frequency of the input in radians per second. Figure 6.3 shows the
Bode plot of the transfer function with three dierent values of . Dene the break
frequency
0
as

0
=
1

(6.10)
Then the magnitude of the function is approximately
|G(j)|
_
1 when <
0

0
j
when >
0
(6.11)
The rst-order lag function dampens all signals with frequencies higher than the
break frequency
0
and can be used as a low-pass lter. As can be seen in the
plot, a larger means a lower break frequency, which complies with the denition
in (6.10). A larger also means a slower response. [9]
52 Alternative Kalman Filter Models
4 6 8 10 12 14 16 18
-2
-1.5
-1
-0.5
0
0.5
1
1.5
2
2.5
Time [s]
D
i
s
t
u
r
b
a
n
c
e

[
m
/
s
2
]
a

=a
m
-a
exp
Kalman filter with v as feedback
Kalman filter from Chapter 5 (q=0.0003)
Figure 6.2. Simulation of the Kalman lter using the measurement from the vehicle
driving up and down a steep hill. q is set to 5. The solid line is the Kalman lter with
the measurement of v as feedback. The dashed line is the lter developed in Section 5.5.
As can be seen the overall behavior of the lter remains the same.
6.2.2 First-Order Gauss-Markov Process
The rst-order lag function can be used to model physical systems. The input u
in (6.7) is then set to w, where w represents Gaussian noise. With this choice of u
the function is called a rst-order Gauss-Markov process [22]. This function has
turned out to be important in applied work since it seems to t a large number of
physical systems with reasonable accuracy but still has a very simple mathematical
description [5].
The described function will now be used to model a
z
. Let
a
z
+
1

a
z
= w (6.12)
Now the problem is to choose a reasonable and the intensity of the noise w.
According to [3] the autocorrelation of the Gauss-Markov process in (6.12) can be
written as
E[a
z
(t
1
)a
z
(t
2
)] = e

|t
1
t
2
|
E[a
z
(t
1
)
2
] (6.13)
The autocorrelation is a measure of how well the signal matches a time-shifted
version of itself, where t
1
and t
2
denes the time shift. This means that the value
of a
z
at a sample time t
k
will depend on the value at the last sample time t
k1
, as
a
z
(t
k
) = e

T
a
z
(t
k1
) +w(t
k1
) (6.14)
6.2 Modeling the Disturbance a
z
53
Bode Diagram
Frequency (rad/sec)
P
h
a
s
e

(
d
e
g
)
M
a
g
n
i
t
u
d
e

(
d
B
)
-50
-40
-30
-20
-10
0
=1
=0.5
=0.25
10
-1
10
0
10
1
10
2
-90
-45
0
Figure 6.3. Bode plot of the rst-order lag function, with three dierent values of .
Larger means a lower break frequency.
where T is the sampling interval [5]. If is chosen very large ( approaches ),
a
z
will be integrated Gaussian noise just as before. If is small the correlation is
high.
6.2.3 Identifying the Time Constant
The technique of system identication is used to build mathematical models of a
dynamic system based on measurement data. This is done by adjusting param-
eters within a given model until its output coincides as well as possible with the
measured output [17]. Matlab contains a toolbox called System Identication
Toolbox [18]. It contains all the common techniques to adjust parameters in all
kinds of linear models, including state-space models, as well as some nonlinear
models. In this section an introduction is given on how to use this toolbox to
identify the unknown parameters in a model.
A Matlab script is found in Appendix C, which creates a model of a
z
described
by (6.12) and denes and the intensity of w as parameters to be identied. As
identication data measurements of the slope of the road during a test drive up and
down the steep hill is used. This data set will represent the maximum dynamic
of a
z
that the lter will have to estimate. When driving a vehicle at 30 km/h
over this steep hill, the highest demands on the lter is said to be reached. As
54 Alternative Kalman Filter Models
identication data the part of a
z
caused by the slope of the road is chosen. This
is done by setting
a
real
z
g sin() (6.15)
where g is the gravitational acceleration and is the slope of the road.
When the noise intensity is set to a constant value, the script can be used to
choose the optimal value of . An intensity value of 1 results in the optimal choice
7. In Figure 6.4 the output from the model is compared with the measurement.
As can be seen, the identied model does not t the identication data exactly.
4 6 8 10 12 14 16 18
-2.5
-2
-1.5
-1
-0.5
0
0.5
1
1.5
y
1
Measured Output and 1-step Ahead Predicted Model Output
Measured Output
Model Fit: 83.67%
Figure 6.4. Identication of time constant . Setting the noise intensity to a constant
value and identify the parameter gives = 7, results in a model t of 83.67%. Letting
the script identify the noise intensity with = 7 will give a model t of over 99%.
Setting the parameter to 7 and letting Matlab identify the noise intensity,
results in a model t of over 99%. The noise intensity is then identied to 70.
This means that by choosing = 7, it is possible to nd a perfect t by adjusting
the parameter for the noise intensity. In fact, by choosing any value of larger
than 0.1 and then letting Matlab nd the optimal noise intensity, results in a
model t of at least 90%, and > 0.3 gives a t of over 95%. For = 0.3 the
optimal noise intensity is identied to 91. A smaller choice of demands a larger
noise intensity to make a good model t.
Figure 6.5 shows the calculated signal a
real
z
and the predicted output from the
model with = 0.3 and noise intensity calculated by Matlab.
The quality of the model can be tested by looking at what the model could not
reproduce in the data, the residuals
(t) = y(t) y(t) (6.16)
6.2 Modeling the Disturbance a
z
55
4 6 8 10 12 14 16 18
-2.5
-2
-1.5
-1
-0.5
0
0.5
1
1.5
y
1
Measured Output and 1-step Ahead Predicted Model Output
Measured Output
model Fit: 96.26%
Figure 6.5. Identication of time constant . Here = 0.3 is chosen and the noise
intensity is identied to 91, giving a model t of 96.26%.
where y is the validation data and y is the output from the model. The residuals
should not be correlated with the past inputs u. If they are, then there is a part
of y that originates from the past input that has not been picked up properly by the
model. The command resid in Matlab computes the correlation function of
the residuals from the model, as well as 99% condence intervals assuming that the
residuals are Gaussian. The rule is that if the correlation function go signicantly
outside these condence intervals, do not accept the corresponding model as a good
description of the system. In that case the model can be improved, for example
by adjusting the number of parameters in the model [17].
6.2.4 Testing the Model of a
z
Modeling a
z
using the equation for the rst-order Gauss-Markov process (6.12)
with state vector x = [x
1
, x
2
]
T
= [v, a
z
]
T
gives the state-space model
x =
_
0 1
0
1

_
. .
A
x +
_
1
0
_
. .
B
a
exp
+
_
0
1
_
. .
G
w (6.17)
y =
_
1 0

. .
C
x +e (6.18)
The Kalman lter using this model is simulated in the same way as in Section 5.5.
Figure 6.6 shows the lter during the drive on the very bumpy road. Here is
set to 7, r is set to 1 and q is set to 70. Figure 6.7 shows the estimate of a
z
during simulating driving up and down the steep hill. As can be seen, there are no
56 Alternative Kalman Filter Models
relevant dierences in comparison to the simple model used in Section 5.4. This
means that both models can be used to estimate a
z
in the simulated situations,
giving the same performance.
14 16 18 20 22 24 26 28 30
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
Time [s]
D
i
s
t
u
r
b
a
n
c
e

[
m
/
s
2
]
a

=a
m
-a
exp
Kalman filter with a
z
modeled as Gauss-Markov Process
Kalman filter from Chapter 5 (q=0.001)
Figure 6.6. Kalman lter with a
z
modeled as a Gauss-Markov process. The gure
shows a simulation using recorded data from the vehicle driving on a very bumpy road.
is set to 7, r is set to 1 and q is set to 70. When comparing with the Kalman lter
developed in Section 5.4, no relevant changes can be found.
6.2.5 Higher-Order Derivative of a
z
In this section the model proposed by [19] will be examined. Recall Section 5.4
where it was stated that the changes in the parameter a
z
can be modeled by setting
the rst derivative of a
z
to Gaussian noise, according to
a
z
(t) = w(t) (6.19)
where
E[w(t)] = 0 (6.20)
E[w(t)w()] = q(t ) (6.21)
This was implemented and tested in Chapter 5, and it was shown that it is possible
to get an arbitrary fast (or slow) estimate by adjusting the noise parameter q.
Another way of modeling the changes is by setting a higher derivative of the
parameter equal to Gaussian noise, for example
a
z
(t) = w(t) (6.22)
6.2 Modeling the Disturbance a
z
57
4 6 8 10 12 14 16 18
-3
-2
-1
0
1
2
Time [s]
D
i
s
t
u
r
b
a
n
c
e

[
m
/
s
2
]
a

=a
m
-a
exp
Kalman filter with a
z
modeled as Gauss-Markov Process
Kalman filter from Chapter 5 (q=0.001)
Figure 6.7. Kalman lter with a
z
modeled as a Gauss-Markov process. The gure is
generated using recorded data from the vehicle driving up and down a steep hill. is set
to 7, r is set to 1 and q is set to 70. When comparing with the Kalman lter developed
in Section 5.4, no relevant changes can be found.
This is used in [19] and also suggested as an alternative by [3] when making
estimates for kinematic models. For example when estimating position and
speed

of an object, one might use the state vector x = [x
1
, x
2
]
T
= [,

]
T
. The
speed of the object undergoes slight changes, which often are modeled as Gaussian
noise with

= w.
There is still the possibility to choose according to
a
z
(t) +
1

a
z
(t) = w(t) (6.23)
For the problem at hand, there is no practical need to estimate the extra state a
z
,
but in order to take advantage of (6.22) or (6.23), the state vector is chosen as
x =
_
_
x
1
x
2
x
3
_
_
=
_
_
v
real
a
z
a
z
_
_
(6.24)
The state-space model becomes
x =
_
_
0 1 0
0 0 1
0 0
1

_
_
. .
A
x +
_
_
1
0
0
_
_
. .
B
a
exp
+
_
_
1 0 0
0 1 0
0 0 1
_
_
. .
G
w (6.25)
y =
_
1 0 0

. .
C
x +e (6.26)
58 Alternative Kalman Filter Models
e is Gaussian noise as before with intensity r. Here w consists of three components,
w = [w
1
, w
2
, w
3
]
T
, meaning that Gaussian noise is added to all three equations in
the state-space model. The covariance matrix for w is
Q =
_
_
q
1
0 0
0 q
2
0
0 0 q
3
_
_
(6.27)
meaning that the noise components of w are independent of each other, with noise
intensities q
1
, q
2
and q
3
. A possible approach when adding process noise to all
estimated parameters in the state-space model, is to set all intensities to the same
value, so that
Q = q
_
_
1 0 0
0 1 0
0 0 1
_
_
(6.28)
This method makes the choice of the parameters easier, but w
1
, w
2
and w
3
still
remain independent of each other. [13]
The design parameters are the noise intensities for each of the Gaussian noises
w
1
, w
2
, w
3
and e, and the value of . As has been explained in Section 3.5.6, the
noise intensities are dependent of each other. Letting the values of q
1
, q
2
and q
3
remain constant while changing the value of r, will aect all three estimates in
the state vector. By letting r be constant, the three estimates can be adjusted
individually. Therefore, the parameters to choose are the intensities of w
1
, w
2
and w
3
, and the value of .
As can be seen in (6.24), (6.25) and (6.26), the equations in the model are
v
real
= a
exp
+a
z
+w
1
(6.29)
a
z
= a
z
+w
2
(6.30)
a
z
=
1

a
z
+w
3
(6.31)
y = v
m
= v
real
+e (6.32)
This might not seem logical, as (6.29) does not comply with the denition of a
z
given in (5.24). Also, the process noise w
2
could according to (6.30) be set to 0.
The state-space model is transformed into a discrete state-space model, using
the theory presented in Section 3.2. With the sample time T the result is
x
n+1
=
_
_
1 T
1
2
T
2
0 1 T
0 0 1
_
_
. .
A
d
x
n
+
_
_
T
0
0
_
_
. .
B
d
u
n
+
_
_
T
1
2
T
2 1
6
T
3
0 T
1
2
T
2
0 0 T
_
_
. .
G
d
w (6.33)
y =
_
1 0 0

. .
C
d
x
n
+e
n
(6.34)
6.3 Implementation and Testing in Arjeplog 59
The observability matrix O has full rank, which according to the test in Section 3.4
means that the system is observable
O =
_
_
C
d
C
d
A
d
C
d
A
2
d
_
_
=
_
_
1 0 0
1 T
1
2
T
2
1 2T 2T
2
_
_
(6.35)
Running the lter o-line in Simulink with measurements from test drives, the
parameters are set using trial-and-error, until the lter gets acceptable behavior.
The following parameter set is found to work properly
q
1
= 4.0 (6.36)
q
2
= 0.1 (6.37)
q
3
= 20.0 (6.38)
r = 0.2 (6.39)
= 0.500 (6.40)
With properly is meant that the lter with these parameters has the same behav-
ior as the other lters evaluated in this thesis, compare to Section 5.5, Section 6.1
and Section 6.2.4. Plots of the Kalman lter implemented in this section is not
shown here, but it will be used in Section 6.4, where a comparison of all lter mod-
els is made. Plots of this lter will also be shown in Section 6.5 in a comparison
with a low-pass lter.
6.3 Implementation and Testing in Arjeplog
The Kalman lter is implemented in the test vehicles at DaimlerChrysler. By the
implementation concern has to be taken to the dierent driver assistance functions
in the outer control loop, as well as to certain driving situations, as described below.
The Kalman lter can be halted, for example when the vehicle is stopped.
The estimate for a
z
in the state vector is then kept constant, while the
other estimates are set to initial values. This is done because there is no
information about the acceleration while the vehicle is standing still. This is
for example necessary when Distronic Plus is stopping the vehicle or when
Downhill Speed Regulation (DSR) is active and the tires are blocked. (Refer
to Section 2.8 and Section 2.6 for explanations of Distronic Plus and DSR.)
The Kalman lter can be restarted, for example when the vehicle is started,
when Distronic Plus tells the vehicle to start moving or when the vehicle has
moved against the desired direction of travel.
The output from the Kalman lter is limited to some maximum and min-
imum values, due to safety reasons. These values are changed if DSR is
active.
The Kalman lter was also evaluated during a testing expedition to Arjeplog in
Sweden. Some of the plots in this thesis have been generated there. The Kalman
lter was then thoroughly tested in dicult situations to detect adverse behavior.
60 Alternative Kalman Filter Models
6.4 Comparing the Kalman Filter Models
It is interesting to know if the models derived in this chapter can improve the
estimate in any way. Before continuing, a comparison between the dierent models
will therefore be made. This is done by adjusting the parameters so that the lters
become the same behavior when simulating the vehicle driving up and down the
steep hill, and then by comparing their output when simulating other situations.
By doing this, all the dierent models have almost the same performance with
respect to estimating large changes. The other driving situations (drive on bumpy
road for example) show if any of the models can ignore small changes better than
the other. Figure 6.8 shows the simulation of driving up and down the steep hill.
The parameters have been adjusted so that the dierent lters almost have the
same behavior. Only the output from the Kalman lter using the model derived
in Section 6.1 is a bit dierent than the others. Figure 6.9 and Figure 6.10 show
simulations of a test drive on two dierent bumpy roads. By looking at these
gures, it becomes obvious that the behavior of the dierent lters remain the
same.
4 6 8 10 12 14 16 18
-3
-2
-1
0
1
2
Time [s]
D
i
s
t
u
r
b
a
n
c
e

[
m
/
s
2
]
a

=a
m
-a
exp
a
z
Kalman filter from Chapter 5
a
z
Kalman filter with v as feedback
a
z
Kalman filter with a
z
as Gauss-Markov process
a
z
Kalman filter implemented in test vehicles
Figure 6.8. This gure shows the simulation of driving up and down the steep hill. The
parameters have been adjusted so that the dierent lters almost have the same behavior.
Only the output from the Kalman lter using the model derived in Section 6.1, plotted
with a dashed line, is a bit dierent than the others.
In this chapter dierent Kalman lter models have been tested and evaluated.
After some work with the models trying to tune the parameters, it turns out that
modeling a
z
in dierent ways does not make the estimate much better. In fact,
during this Masters project no simulated situation has been found where any of
the models examined in this chapter can make a better estimate than the simple
model used in Section 5.5.
6.5 Comparing the Kalman Filter with a First-Order Lag Function 61
2 2.5 3 3.5 4 4.5 5 5.5 6 6.5 7
-1.8
-1.6
-1.4
-1.2
-1
-0.8
-0.6
-0.4
-0.2
0
Time [s]
D
i
s
t
u
r
b
a
n
c
e

[
m
/
s
2
]
a

=a
m
-a
exp
a
z
Kalman filter from Chapter 5
a
z
Kalman filter with v as feedback
a
z
Kalman filter with a
z
as Gauss-Markov process
a
z
Kalman filter implemented in test vehicles
Figure 6.9. This gure shows a simulation of a test drive on a bumpy road. By looking
at the output from the dierent Kalman lters, it cannot be said that any of the lters
is better than the other.
The reason for this is that the Kalman lter remains a linear lter giving the
user to choose between a fast but jerky, or a slow but smooth estimate. With the
application at hand, it is important that the estimate is smooth, as the output
will be directly connected to the engine and brakes. Another conclusion is that
inserting more complexity and more parameters into the model makes the tuning
work more time consuming and harder to understand.
6.5 Comparing the Kalman Filter with a First-
Order Lag Function
With the application at hand, the process noise w and measurement noise e cannot
be measured or estimated. Instead the lter is tuned using a subjective feeling
about what is a good compromise when sitting in the car. A fast lter makes a
faster controller, but it does not necessary mean that the controller works better.
It has been noticed that a faster controller makes the deviation from the desired
speed smaller, but at the same time the drive gets more uncomfortable. The
demands on the lter correspond to those of an ordinary low-pass lter. Therefore
this section will try to explain the similarities between these lters.
The gures that follow show the similarities between the Kalman lter from
Section 6.2.5 and a rst-order lag function as described in Section 6.2.1. The
gures are from simulations in Simulink, using measured data. The output from
the Kalman lter is represented with a solid line. As reference a

= a
m
a
exp
is
also plotted with a dotted line. The dashed line is the output from a rst-order
62 Alternative Kalman Filter Models
14 16 18 20 22 24 26 28 30
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
Time [s]
D
i
s
t
u
r
b
a
n
c
e

[
m
/
s
2
]
a

=a
m
-a
exp
a
z
Kalman filter from Chapter 5
a
z
Kalman filter with v as feedback
a
z
Kalman filter with a
z
as Gauss-Markov process
a
z
Kalman filter implemented in test vehicles
Figure 6.10. This gure shows a simulation of a test drive on a very bumpy road. By
looking at the output from the dierent Kalman lters, it cannot be said that any of the
lters is better than the other.
lag function with time constant 1.1, when the signal a

= a
m
a
exp
is given as
input.
The measurement in Figure 6.11 comes from a test drive when the vehicle
drives up and down the steep hill, and Figure 6.12 comes from a drive on the
bumpy road. Figure 6.13 shows a test drive with an attached trailer of 2000 kg,
where the driver uses the cruise control lever to fast step the set speed up and
down several times, without giving the controller enough time to adjust the speed
completely.
The Kalman lter is very practical when the task is to extract information from
noisy measurements (also from many sensors in combination so called sensor
fusion) or estimating more than one parameter in a complex state-space model.
When knowing the intensities of the process noise w and measurement noise e,
the Kalman lter equations are used, as explained in Section 3.5, to calculate the
optimal gain L for the observer. Looking at the gures, it is obvious that the
Kalman lter with these parameters behaves as a low-pass lter. The calculated
gain L is used to adjust the frequency properties of the Kalman lter so that the
gain is high when the signal-to-noise ratio is high, but low when the ratio is low.
This behavior is also described in [12]. When knowing what type of behavior is
wanted from the lter, the same work can be done using traditional lter methods.
The Kalman lter used in the comparison does not have the signal a

as in-
put. Instead the measurement of the vehicle speed v
m
is used as described in
Section 6.2.5. Therefore it is not a regular low-pass lter. Instead, the Kalman
lter uses the measurement of the vehicle speed as input, and this is one example
of the advantage of developing lters using the Kalman model.
6.5 Comparing the Kalman Filter with a First-Order Lag Function 63
4 6 8 10 12 14 16 18
-3
-2
-1
0
1
2
Time [s]
D
i
s
t
u
r
b
a
n
c
e

[
m
/
s
2
]
a

=a
m
-a
exp
a
z
Kalman filter
a

low-pass filtered
Figure 6.11. The measurement in this gure comes from a test drive when the vehicle
drives up and down the steep hill. The dashed line is the output from a rst-order lag
function with time constant = 1.1. As can be seen the behavior is similar to the output
from the Kalman lter (solid line).
According to [12], the transfer function for the stationary Kalman lter is
G
kf
(s) = (sI A+LCA)
1
Ls (6.41)
where L is the steady-state gain parameters calculated by (3.27). Calculating G
kf
with the model used for the Kalman lter gives a matrix containing three transfer
functions from the input v
m
to each of the lter outputs v, a
z
and a
z
. Taking the
transfer function from v
m
to a
z
, letting s = e
i
and plotting its absolute value
gives the magnitude plot of the Bode diagram in Figure 6.14. The solid line is given
by the parameter set used in Section 6.2.5 and above in this section. The dashed
line shows a lter with smaller r and the dashed-dotted line shows a lter with a
larger r. The lter has the function of a high-pass lter. This is expected, as the
transfer function used in the plot estimates a
z
using measurements of the speed v.
Its characteristic is normal for all derivating lters. The lter with a smaller r has
a higher break frequency, and a larger r means lower break frequency. This was
also expected, because a smaller measurement noise means that the lter also can
dierentiate higher frequencies. [12]
64 Alternative Kalman Filter Models
10 12 14 16 18 20 22 24 26 28 30
-0.4
-0.3
-0.2
-0.1
0
0.1
0.2
Time [s]
D
i
s
t
u
r
b
a
n
c
e

[
m
/
s
2
]
a

=a
m
-a
exp
a
z
Kalman filter
a

low-pass filtered
Figure 6.12. The gure is from a simulation using recorded data from a test drive on
a bumpy road. The dashed line is the output from a rst-order lag function with time
constant = 1.1. As can be seen the behavior is similar to the output from the Kalman
lter (solid line).
10 15 20 25 30 35 40 45
-3
-2.5
-2
-1.5
-1
-0.5
0
0.5
1
1.5
Time [s]
D
i
s
t
u
r
b
a
n
c
e

[
m
/
s
2
]
a

=a
m
-a
exp
a
z
Kalman filter
a

low-pass filtered
Figure 6.13. The gure is from a simulation using recorded data from a test drive
with a heavy loaded trailer. The driver uses the cruise control lever to step the set
speed up and down several times, without giving the controller enough time to adjust
the speed completely. The dashed line is the output from a rst-order lag function with
time constant = 1.1. As can be seen the behavior is similar to the output from the
Kalman lter (solid line).
6.5 Comparing the Kalman Filter with a First-Order Lag Function 65
Bode Diagram
Frequency (rad/sec)
P
h
a
s
e

(
d
e
g
)
M
a
g
n
i
t
u
d
e

(
d
B
)
-70
-60
-50
-40
-30
-20
-10
r smaller (faster filter)
original Kalman filter
r larger (slower filter)
10
-3
10
-2
10
-1
10
0
10
1
-180
-135
-90
Figure 6.14. Bode Diagram of the transfer function from v
m
to a
z
, with the Kalman
lter presented in Section 6.2.5. The solid line is the parameters chosen in Section 6.2.5,
the dashed line is from a lter with smaller r and the dashed-dotted line is from a lter
with a larger r. The lter has the function of a normal high-pass lter. This is expected,
as the transfer function used in the plot estimates a
z
using measurements of the speed v.
The lter with a smaller r has a higher break frequency, and a larger r means lower break
frequency. A smaller measurement noise means that the lter also can dierentiate higher
frequencies.
66 Alternative Kalman Filter Models
Chapter 7
Change Detection
In this chapter an overview of dierent change detection algorithms is given, and
then one of them is chosen and implemented. An introduction on how to adjust
the parameters for this algorithm is given and simulations of dierent driving
situations are made. It wil l be shown that it is possible to improve the estimate
of a
z
using this algorithm.
7.1 Idea of Change Detection
When constructing a lter, it is desirable that the output follows the desired target
signal, ignoring the noise. The gain in a linear lter is a compromise between noise
attenuation and tracking ability. Choosing a large gain makes it fast and sensitive
to measurement noise, and choosing a low gain makes it slow when large changes
in the signal occurs.
When driving the vehicle on a straight road, a slow lter could be used. The
function could be satisfying for some time, but then suddenly the slope changes
and the model used by the lter is no longer correct. It would be practical to
be able to detect such changes in the environment, and react by making the lter
faster. The presentation that follow is based on [13], where a thorough explanation
of the subject is given.
Consider a lter trying to estimate a signal x. The lter uses measurements x
m
to calculate an estimate x. The measurement is modeled as
x
m,k
= x
k
+e
k
(7.1)
where e is the measurement noise. The quality of the estimate x can be tested by
looking at the residuals

k
= x
m,k
x
k
(7.2)
If there is no change in the system and the model is correct, then the residuals
are white noise, a sequence of independent stochastic variables with zero mean
and known variance. After a change either the mean or variance or both changes,
67
68 Change Detection
-
x
k
-
u
k
Kalman Filter
k
-
Distance
-
s
k
Stop rule
p -
Alarm
-
x
k
6
Change Detector
Figure 7.1. A change detector consists of distance measure and a stopping rule. The
distance measure transform the residuals from the Kalman lter to a signal s, repre-
senting the change in the residuals. The stopping rule decides whether the change is
signicant or not. If the change in the residuals is signicant, the change detector gives
an alarm and the Kalman lter can take appropriate action (for example by making the
lter faster).
that is, the residuals become large in some sense. This can be used by a change
detection algorithm. The problem is to decide what large is. Change detection
is also referred to as fault detection. It is often used to detect faults in a system,
for example when a sensor is broken or temporarily unavailable.
There are three dierent categories of change detection methods [13]
Methods using one lter, where a whiteness test is applied to the residuals.
The lter is temporarily made faster when a change is detected.
Methods using two lters, one slow and one fast, in parallel. Depending on
the residuals from the two lters, one of them is chosen as the currently best
one.
Methods using multiple lters in parallel, each one matched to certain as-
sumptions on the abrupt changes. For each lter the probability of that lter
being correct is calculated, and output is the weighted sum of the output
from all the individual lters, depending on their current probabilites.
In this chapter, a method using one lter will be implemented and tested.
7.2 One Kalman Filter with Whiteness-Test
The task of the change detector is to decide which of the following hypotheses is
correct, concerning the residuals from the Kalman lter
H
0
: is white noise (7.3)
H
1
: is not white noise (7.4)
A change detector consists of a distance measure and a stopping rule, as in
Figure 7.1. The residuals are transformed to a distance measure s
k
, that mea-
sures the deviation from the hypothesis H
0
. The stopping rule decides whether
the deviation is signicant or not. Dierent implementations of the distance mea-
sures s
k
are [13]
7.2 One Kalman Filter with Whiteness-Test 69
Change in mean. The residual itself is used, giving
s
k
=
k
(7.5)
Change in variance. The squared residual subtracted by a known normal
residual variance is used, giving
s
k
=
2
k
(7.6)
Change in correlation. The correlation between the residual
t
at the current
time step k and past outputs y
kl
or inputs u
kl
at a time step k l are
used as
s
k
=
k
y
kl
(7.7)
or
s
k
=
k
u
kl
(7.8)
for some value l.
Change in sign correlation. For instance, one can use the fact that white
residuals should in average change sign every second sample and use
s
k
= sign(
k

k1
) (7.9)
A stopping rule is created by low-pass ltering s
k
and comparing this value to a
threshold h. Two common low-pass lters described in [13] are
The CUmulative SUM (CUSUM) test
g
k
= max(g
k1
+s
k
, 0) (7.10)
The drift parameter inuences the low-pass eect.
The Geometric Moving Average (GMA) test
g
k
= g
k1
+ (1 )s
k
(7.11)
Here the forgetting factor is used to tune the low-pass eect. can be
chosen as 0, which means no low-pass eect and s
k
will in this case be
thresholded directly.
The stopping rule gives an alarm when g
k
> h. When an alarm is given, the
Kalman lter is temporarily made faster by adjusting the parameters, and g
k
is
reset to 0.
70 Change Detection
7.3 Implementation
In this section one change detection algorithm is implemented and tested. As
distance measure s
k
=
2
k
is chosen, and as stopping rule the CUSUM-test
g
k
= max(g
k1
+s
k
, 0). Inserting (7.6) in (7.10) gives
g
k
= max(g
k1
+
2
k
, 0)
= max(g
k1
+
2
k
, 0) (7.12)
Here has been dened as = +.
The Kalman lter from Chapter 5 with R = 1 and Q = 0.0003 is selected. This
gives L = L
slow
= 0.0172 and results in a slow lter. The change detector gives an
alarm when g
k
> h, and the Kalman lter is temporarily made faster by changing
the calculated value L to another value L
fast
. Choosing R = 1 and Q = 0.01 from
Chapter 5 gives L
fast
= 0.0951.
To choose the threshold h and the parameter in (7.12) for the change detec-
tion algorithm, the following steps are taken, inspired by the general advice given
in [13]
Start with a very large threshold h and choose to the size of the expected
change. Simulate the system with measurements from test drives on bumpy
roads. The Kalman lter should in these situations remain slow, ignoring
the noise. Adjust such that g
k
= 0 more than 50% of the time.
Then simulate the system with measurements where large changes occur, for
example driving up and down a steep hill, or stepping the cruise controller
set speed up and down with a heavy loaded vehicle. Set the threshold h so
the delay for detection of these large changes is reasonable.
Then simulate all the driving situations again. If faster detection is sought,
try to decrease . If fewer false alarms are wanted, try to increase . If there
is a subset of the change times that does not make sense, try to increase .
The parameters for the change detection found using this method are = 0.005
and h = 0.2.
7.4 Results
The Kalman lter with the change detection algorithm chosen in Section 7.3 is
simulated using measurements from test drives representing dierent driving sit-
uations. The output from the simulated Kalman lter is plotted in a diagram
together with the measured signal a
m
a
exp
. As a reference the output from the
original Kalman lter without change detection, presented in Section 6.2.5, is
also plotted. The discrete signal at the bottom of the diagrams is the output from
the change detection algorithm, called Alarm in Figure 7.1. When this signal is
high, the faster parameter of the Kalman lter is chosen.
Figure 7.2 is a simulation of a test drive up and down a steep hill, with a slope
of 20% up and 15% down. Figure 7.3 shows a vehicle with a trailer with a weight
7.4 Results 71
of 2000 kg driving up and down the same hill. Figure 7.4 shows the vehicle with
the trailer again, this time driving with cruise control. The driver is stepping the
set speed fast up and down without letting the vehicle reach the desired speed.
From the three gures it can be seen that the estimates from the Kalman lter
with change detection is faster than the original implementation. Faster estimates
are better in these driving situations because it would give the controller a better
chance to compensate for the large changes.
Figure 7.5 and Figure 7.6 each show a test drive on two dierent bumpy roads.
As can be seen, not so many alarms are given, and the change detection algorithm
does not aect the estimate. This shows that the change detection algorithm does
not aect the estimate when it is not necessary.
0 5 10 15 20 25
-3
-2
-1
0
1
2
3
Time [s]
D
i
s
t
u
r
b
a
n
c
e

[
m
/
s
2
]
a

= a
m
-a
exp
a
z
Kalman filter
a
z
Change Detection
Alarm
Figure 7.2. Simulation of a Kalman lter with change detection algorithm when driving
up and down a steep hill. The change detection algorithm detects the large changes and
makes the Kalman lter faster.
72 Change Detection
0 5 10 15 20 25
-6
-5
-4
-3
-2
-1
0
1
2
3
4
Time [s]
D
i
s
t
u
r
b
a
n
c
e

[
m
/
s
2
]
a

= a
m
-a
exp
a
z
Kalman filter
a
z
Change Detection
Alarm
Figure 7.3. Simulation of a Kalman lter with change detection algorithm when driving
up and down a steep hill with a 2000 kg trailer. The change detection algorithm detects
the large changes and makes the Kalman lter faster. (The original Kalman lter becomes
saturated at 3ms
2
. This is not implemented in the simulation for the lter with change
detection.)
10 15 20 25 30 35 40 45
-3
-2
-1
0
1
2
3
Time [s]
D
i
s
t
u
r
b
a
n
c
e

[
m
/
s
2
]
a

= a
m
-a
exp
a
z
Kalman filter
a
z
Change Detection
Alarm
Figure 7.4. Simulation of a Kalman lter with change detection algorithm when driving
with an attached trailer. The driver uses the cruise control lever to fast step up and down
witout letting the vehicle reach the desired speed. The change detection algorithm detects
the large changes and makes the Kalman lter faster than the original implementation.
7.4 Results 73
0 1 2 3 4 5 6 7 8 9 10
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
Time [s]
D
i
s
t
u
r
b
a
n
c
e

[
m
/
s
2
]
a

= a
m
-a
exp
a
z
Kalman filter
a
z
Change Detection
Alarm
Figure 7.5. Simulation of a Kalman lter with change detection algorithm when driving
on a bumpy road. The change detection algorithm does not give many alarms, and
therefore the estimate is not aected, as desired.
0 10 20 30 40 50 60
-0.6
-0.5
-0.4
-0.3
-0.2
-0.1
0
0.1
0.2
Time [s]
D
i
s
t
u
r
b
a
n
c
e

[
m
/
s
2
]
a

= a
m
-a
exp
a
z
Kalman filter
a
z
Change Detection
Alarm
Figure 7.6. Simulation of a Kalman lter with change detection algorithm when driving
on a very bumpy road. The change detection algorithm does not give many alarms, and
therefore the estimate is not aected, as desired.
74 Change Detection
Chapter 8
Conclusions and Future
Work
In this chapter the thesis is concluded with a short summary of the obtained results
and observations made. The chapter also includes a section in which interesting
future work is briey introduced.
8.1 Conclusions
In this Masters thesis the theory for the Kalman lter and lter tuning have been
presented. It has been shown how to implement a Kalman lter estimating the
part called a
z
of the vehicles acceleration caused by disturbances not included
in the model of the vehicle. The easiest method is to use a constructed sig-
nal a

= a
exp
a
m
as input to the lter, where a
exp
is the expected acceleration
calculated by the model and a
m
is the measured actual acceleration.
It has been shown that the lter parameters can be chosen either
by knowledge about the noise intensities (when they are not known they can
be estimated),
by running simulations in Simulink and optimizing the parameters using a
script in Matlab (for this purpose the algorithm simulated annealing has
been implemented),
or by adjusting the parameters as a compromise between a slow lter, or a
fast but jerky lter (to do this a subjective choice has to be made).
Some more complex models for the Kalman lter have been implemented and
tested. First it was shown how to use the speed of the vehicle as input to the
lter, instead of the constructed signal a

. Then two models of a


z
were derived
and tested, inspired by the rst-order lag function and the Gauss-Markov process.
These models have a higher computational cost, but it could not be proven that
they improve the estimate in any way.
75
76 Conclusions and Future Work
It has been shown that the Kalman lter implemented in the vehicles today
can be replaced by a rst-order lag function, with no loss in performance.
A change detection algorithm has also been implemented in Simulink and
simulations show that it is possible to improve the estimate using this algorithm.
8.2 Future Work
There are several interesting aspects that deserve further investigation.
The change detection algorithm implemented in Simulink should be tested
in a real vehicle. If this test shows a positive result, the parameters can then
be adjusted by practical methods to suit the actual application.
It is suggested to implement, simulate and test the other methods for change
detection described in this Masters thesis. For example the method of using
two lters in parallel, one slow and one fast, may be of interest.
It should be practically tested if the Kalman lter can be exchanged with
another simpler type of low-pass lter, as the simulations in this thesis sug-
gest.
As the parameters m (the mass of the vehicle) and (the slope of the
road) have a big impact on the calculation of the expected acceleration (see
Section 5.3) it would be interesting to see if the performance of the controller
could be improved by estimating these parameters, instead of estimating a
z
.
List of Notations
This table shows the symbols and abbreviations used in this thesis, together with
a reference to the page where they are dened.
Symbol Description Page
Slope of the road 42
a
c
Output from the controller 34
a
dev
Deviation from desired acceleration 33
a
des
Desired acceleration 33
a
exp
Calculated expected acceleration 43
a
m
Measured acceleration of the vehicle 33
a
real
Actual aceleration of the vehicle 33
a
z
Output from the observer 43
A
w
Air resistance reference area 36
c
d
Drag coecient 36
c
rr
Rolling resistance coecient 36
Eciency factor for the drivetrain 36
e Measurement noise 12
F
air
Air resistance 36
F
brake
Force from the brakes 35
F
drive
Force from transmission and engine 35
F
resistance
Drive resistance 35
F
roll
Rollin resistance 36
g Gravitational acceleration 36
i
d
Dierential ratio 36
I
e
Moment of inertia for the engine 36
I
f
Moment of inertia for the front axes 36
i
g
Gearbox ratio 36
I
g
Moment of inertia for the gear 36
I
r
Moment of inertia for the rear axes 36
L Observer gain 14
m Mass of the vehicle 36
m Mass and moments of inertia 37
P Covariance matrix 16
q Measurement noise intensity 43
77
78 List of Notations
Q Measurement noise covariance matrix 15
Density of the air 36
r Process noise intensity 44
r
w
Wheel radius 34
R Process noise covariance matrix 15
T
b
Desired brake torque 33
T
brake
Expected output torque from the brakes 35
T
drive
Output torque from the transmission and engine 36
T
e
Desired engine torque 33
T
engine
Expected output torque from the engine 35
u Input signal 12
v
m
Measured speed of the vehicle 33
v
real
Actual speed of the vehicle 33
v
wind
Speed of the wind 36
w Process noise 12
x State 12
x Estimate of the state 14
Abbreviation Description Page
ABS Anti-lock Braking System 5
ACC Adaptive Cruise Control 7
BAS Brake Assist System 7
CMS Collision Mitigation System 6
DSR Downhill Speed Regulation 6
ESP Electronic Stability Program 5
RMSE Root Mean Square Error 25
SA Simulated Annealing 26
Bibliography
[1] B. Adiprasito, Fahrzeuglngsfhrung im Niedergeschwindigkeitsbereich,
PhD thesis, Shaker Verlag, Aachen, 2004.
[2] P. Andersson, Air Charge Estimation in Turbocharged Spark Ignition Engines,
PhD thesis No. 989, Linkpings universitet, Linkping, 2005.
[3] Y. Bar-Shalom, X. Li and T. Kirubarajan, Estimation with Applications to
Tracking and Navigation, John Wiley & Sons, Inc., New York, 2001.
[4] G. Blom, Sannolikhetsteori och statistikteori med til lmpningar, Studentlit-
teratur, Lund, fourth edition, 1989.
[5] R.G Brown and P.Y.C Hwang, Introduction to Random Signals and Applied
Kalman Filtering, John Wiley & Sons, Inc., New York, third edition, 1997.
[6] T. Coleman, M.A Branch and A. Grace, Optimization Toolbox Users Guide,
The MathWorks, Inc., Natick, 1999.
[7] A. Eidehall, Tracking and threat assessment for automotive col lision avoid-
ance, PhD thesis No. 1066, Linkpings universitet, Linkping, 2007.
[8] M. Fach, Robustheits- und Stabilittsbetrachtung des Fahrzeuglngsreglers im
Mercedes Benz Pkw, Masters thesis, Universitt Stuttgart, Stuttgart, 2003.
[9] T. Glad and L. Ljung, Reglerteknik - Grundlggande teori, Studentlitteratur,
Lund, fourth edition, 2006.
[10] T. Glad and L. Ljung, Reglerteori - Flervariabla och olinjra metoder, Stu-
dentlitteratur, Lund, second edition, 2003.
[11] M. Grewal and A. Andrews, Kalman Filtering - Theory and Practice Using
Matlab, John Wiley & Sons, Inc., Ney York, second edition, 2001.
[12] F. Gustafsson, L. Ljung and M. Millnert, Signalbehandling, Studentlitteratur,
Lund, second edition, 2001.
[13] F. Gustafsson, Adaptive Filtering and Change Detection, John Wiley &
Sons, Inc. New York, 2001.
79
80 Bibliography
[14] U. Kienecke and L. Nielsen, Automotive Control Systems For Engine, Drive-
line and Vehicle, Springer-Verlag, Berlin, second edition, 2005.
[15] S. Kirkpatrick, C.D. Gelatt and M.P. Vecchi, Optimization by Simulated An-
nealing, Science(220) : 671-680, 1983.
[16] P. Lingman and B. Schmidtbauer, Road Slope and Vehicle Mass Estimation
Using Kalman Filtering, Vehicle System Dynamics Supplement 37 page 12-23,
2002.
[17] L. Ljung, System Identication - Theory for the User, Prentice Hall, Upper
Saddle River, second edition, 1999.
[18] L. Ljung, System Identication Toolbox Users Guide, The Math Works, Inc.,
Natick, 1995.
[19] D. Pfrommer, Regelung der Fahrzeuglngsdynamik unter Bercksichtigung der
unterschiedlichen Dynamik von Motor und Bremse, Masters thesis, Univer-
sitt Stuttgart, Stuttgart, 2005.
[20] K. Popp and W. Schiehlen, Fahrzeugdynamik, B.G. Teubner, Stuttgart, 1993.
[21] R. Regis and C. Shoemaker, A Stochastic Radial Basis Function Method
for the Global Optimization of Expensive Functions, Online Supplement, IN-
FORMS Journal on Computing, Acc. 2007-02-01
http://joc.pubs.informs.org/Supplements/Regis.pdf
[22] R. Rosander, Sensor Fusion between a Synthetic Attitude and Heading
Reference System and GPS, Masters thesis No. LITH-ISY-EX-3408-2003,
Linkpings Universitet, Linkping, 2003.
[23] G. Welch and G. Bishop, An Introduction to the Kalman Filter, Technical
Report TR95-041, University of North Carolina at Chapel Hill, Chapel Hill,
1995.
[24] Control System Toolbox Users Guide, The MathWorks, Inc., Natick, 1998.
[25] Owners Manual S-Class, DaimlerChrysler AG, Stuttgart, 2006.
[26] Owners Manual M-Class, DaimlerChrysler AG, Stuttgart, 2006.
Appendix A
Matlab Implementation of
lsqnonlin
function [q11,q22,q33] = opt_param_lsq(tolx, tolfun)
% Optimize control parameters using LSQNONLIN and Simulink model
if (nargin < 2)
warning(Using standard value for tolx and tolfun (0.001));
tolfun = 0.001;
tolx = 0.001;
end
load_system(opt_param_model) % Load the model
start_parameters = [0.1 1 10]; % Set initial values
% Set optimization options (for example termination options)
options =
optimset(LargeScale,off,Display,iter,
TolX,tolx,TolFun,tolfun);
% Run lsqnonlin to solve the optimization problem
best_parameters = lsqnonlin(@tracklsq, start_parameters,
[], [], options);
% Save the result
q11 = best_parameters(1);
q22 = best_parameters(2);
q33 = best_parameters(3);
% This is the call-back function used by lsqnonlin
function F = tracklsq(current_parameters)
81
82 Matlab Implementation of lsqnonlin
% Current values are passed by lsqnonlin
q11 = current_parameters(1);
q22 = current_parameters(2);
q33 = current_parameters(3);
% Calculate the observer
Q_d = [q11 0 0 ; 0 q22 0 ; 0 0 q33];
\textsc{Simulink}_model_parameters
% Create simulation options and run simulation
[tout,xout,yout] = sim(opt_param_model);
% Calculate the cost function value
% (In the model used, error is the 2:nd output)
error = yout(:,2);
% (lsqnonlin uses sqrt(F) as cost function, therefore ^2
F = rmse(error)^2;
end
function rmse = RMSE(error)
% Calculate a cost function based on the insignal error
error = estimated_value-real_value);
t = length(error);
rmse=sqrt(1/t*sum(error.^2));
Appendix B
Matlab Implementation of
Simulated Annealing
This is the developed optimization script implementing the simulated annealing
(SA) algorithm in Matlab.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [param_best, cost_best] = sim_annealing(param_start,steps_max)
%
% This Matlab function recursively tries to find the optimal
% parameters, using Simulink-simulation and
% the algorithm "simulated annealing".
%
% Required parameters:
% param_start = [q11 q22 q33], initial state for the algorithm
% steps_max, the maximum number of evaluations allowed
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [param_best, cost_best] =
sim_annealing(param_start,steps_max)
if(nargin<2)
error(Specifz initial values and max evaluations);
end
param_current = param_start; % Initial state
cost_current = sim_cost(param_current); % Initial error
cost_stop = 0.1
P_start = 0.9;
P_stop = 0.000001;
83
84 Matlab Implementation of Simulated Annealing
[temp_start alpha]=
init(param_current,cost_current,steps_max,P_start,P_stop);
param_best = param_current; % Initial "best" solution
cost_best = cost_current;
temp_current = temp_start; % Initial temperature
rand(state,sum(100*clock)); % reset random generator
disp(sprintf(
steps: \t [q11 \t q22 \t q33] = \t cost \t T=temp));
steps = 0; % Evaluation count.
% While time remains & not good enough
while steps < steps_max & cost_current > cost_stop
% Pick some neighbour
param_neighbour = neighbour(param_current);
% Compute its energy
cost_neighbour = sim_cost(param_neighbour);
if cost_neighbour < cost_best % Is this a new best?
param_best = param_neighbour;
cost_best = cost_neighbour; % Yes, save it.
end
% Should we move to the new state?
if rand < trans_P(cost_current, cost_neighbour, temp_current)
param_current = param_neighbour; % Yes, change state
cost_current = cost_neighbour;
end
steps = steps + 1; % One more evaluation
cost_history(steps) = cost_current; % Log the cost (path)
temp_history(steps) = temp_current;
temp_current = alpha*temp_current; % Cool down
disp(sprintf(%d: \t [%0.5g \t %0.5g \t %0.5g]
= \t %0.5g \t T=%0.5g, steps,
param_current(1), param_current(2), param_current(3),
cost_current,temp_current));
end
figure(1);
subplot(2,1,1), plot(cost_history), xlabel(costfunction);
subplot(2,1,2), plot(temp_history), xlabel(temperature);
85
% Print the best parameters and their evaluated cost value
param_best
cost_best
% Pick some neighbour to the current parameters
% Should try to get nearby values!
function n = neighbour(param)
n = [-1 -1 -1];
% Can not allow negative values
while n(1) < 0 | n(2) < 0 | n(3) < 0
% Randomize between -0.5 and +0.5
change = (rand(1,3)-0.5).*param;
% Calculate new parameters
n = param + change;
end
end
% Calculate the transition probability function P
% The probability that we move to new parameters
function P = trans_P(cost_current, cost_neighbour, temp)
if cost_current < cost_neighbour
P = 1; % Always go down the hill
else
% Go up the hill if the temperature is high,
% but stay if the temperature is low
P = exp((cost_current-cost_neighbour)/temp);
end
end
% sim_cost executes the simulation and returns the RMSE-error
function cost = sim_cost(param)
global simin_Ld1 simin_Ld2 simin_Ld3
q11 = param(1);
q22 = param(2);
q33 = param(3);
r_d = 0.2;
lrg_para_lrg;
% These parameters have to be defined as global
simin_Ld1 = L_d(1);
simin_Ld2 = L_d(2);
simin_Ld3 = L_d(3);
disp([Simulating...]);
86 Matlab Implementation of Simulated Annealing
sim(rdu_simmod_tl_fumo);
% Check global parameters
if(simin_Ld1 == max(simout_Ld1))
disp([OK]);
else
error(Parameters are not received by Simulink);
end
% Calculate the cost function value
error = simout_car_pos_g-simout_LRG_az_SGB;
% Pick out the interesting part (skip beginning!)
parterror = error(400:2600);
% Calculate cost (Root mean square error)
cost = rmse(parterror);
end
% Calculate a reasonable initial temperature and alpha
function [temp_start, alpha] =
init(param_start,cost_start,steps_max,P_start,P_stop)
cost_best=cost_start; % best of all the neighbours
cost_worst=cost_start; % worst of all the neighbours
for i=1:5
% Generate some random neighbours, evaluate costs
param_neighbour = neighbour(param_start);
cost_neighbour = sim_cost(param_neighbour);
% Save the worst and best neighbour costs
if( cost_neighbour < cost_best )
cost_best = cost_neighbour;
end
if( cost_neighbour > cost_worst )
cost_worst = cost_neighbour;
end
end
% Calculate the maximum uphill move needed
if( cost_worst > cost_start )
max_change = cost_worst - cost_start
else
max_change = cost_start - cost_best
end
87
% Set initial temperature so that this maximum move
% is accepted with a high probability P_start.
% P_start = exp(-max_change/temp_start) gives
temp_start = -max_change / log(P_start);
% Now calculate the cooling factor alpha
% P_stop = exp(-max_change/(temp_start*alpha^steps_max))
alpha = (-max_change / (temp_start*log(P_stop)))^(1/steps_max);
end
Appendix C
Time Constant Identication
Here is the Matlab identication script that was used to identify the unknown
parameter and the intesitiy of w in the rst-order lag function a
z
+a
z
= w.
% Identifies the parameter "tau" and "K" in the matrix A
% dot{x} = Ax + Bu + Ke
% y = Cx + Du + e
% The noise intensities of e is 1
load C:\Messungen\221_836_RS141p_pr21.mat
% Calculate the disturbance a_z due to the slope alpha
alpha = atan((B_LRdeSteigSe)/100);
real_az_Slope = -9.81*sin(alpha);
az = real_az_Slope;
T = 0.02; % Sampling time
tau_start = 0.5; % Start values
K_start = 1;
A = [-1/tau_start];
B = [0];
C = [1];
D = [0];
K = [K_start];
x0 = [0];
% Create state-space identification model
m = idss(A,B,C,D,K,x0,Ts,0);
m.as = [NaN]; % NaN means "please identify"
m.ks = m.k;
m.bs = m.b;
m.cs = m.c;
88
89
m.ds = m.d;
% Automatically adjust initial values to suit model
m_init = init(m);
% Load identification data, az output, no input
identificationData = iddata(az, zeros(length(az),1), T);
% Identify unknown parameters
model = pem(identificationData,m_init);
% Save the identified parameters
tau_save = -inv(model.A)
K_save = model.K
lambda = model.NoiseVariance
% Check the models ability to predict one step ahead
figure(15);
compare (identificationData,model,1);

You might also like