0% found this document useful (0 votes)
53 views10 pages

Kalman Filter Implementation: First Part of Implementation

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views10 pages

Kalman Filter Implementation: First Part of Implementation

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

First part of implementation Kalman Filter

Implementation

Hamza Ouertani
AAKKURAD
Kalman Filter Implementation

I. Introduction
As a part of our project, the kalman filter is one of the main components that will help us to estimate
the state of charge and the state of health. The Simulink Kalman filter block estimates the capacity
of the lithium-ion cell and after this operation the value goes as input to the unscented kalman filter
to estimate the state of charge.
1. Objectives
• Provide a basic understanding of Kalman Filtering and assumptions behind its
implementation.
• Implement kalman filter on Simulink and define each parameter in the block.
• Provide some practicalities of implementation.
• C code development.
2. General Information
o What is a Kalman Filter and what can it do?
The KF was introduced by Rudolf Emil Kalman back in 1960. Kalman
proposed an optimal recursive estimator solution to the discrete data linear filtering
problem. Even though Kalman’s algorithm is based on advanced stochastic theory, the
end result can be summarized into two sets of equations: time update equations
(Predictor) and the measurement update equations (Corrector). Moreover, the KF
equations can be easily implemented in digital systems.
o Optimal in what sense?
If all noise is Gaussian, the Kalman filter minimizes the mean square error of the estimated
parameters.
o What if the noise is NOT Gaussian?
Given only the mean and standard deviation of noise, the Kalman filter is the best linear estimator.
o Why is Kalman Filtering so popular?

Because the kalman filter has a good result in practice due to optimality and structure, furthermore
convenient from for online real time processing. Additionally, it is easy to formulate and implement
given a basic understanding.
o Why use the word “Filter”?
The process of finding the “best estimate” from noisy data amounts to “filtering out” the noise.
However a Kalman filter also does not just clean up the data measurements, but also projects these
measurements onto the state estimate.
II. Kalman Filter Algorithm

1
Kalman Filter Implementation

Before I start, I would like to explain several fundamental terms such as variance, standard
deviation, normal distribution, estimate, accuracy, precision, mean, expected value and random
variable.
o Variance: is a measure of spreading of the data set from its mean.
o Standard Deviation: is the square root of the variance, The Standard deviation is denoted
by a Greek letter σ (sigma). Consequently, the variance is denoted by σ2.
o Normal Distribution: also known as the Gaussian (it is named after the mathematician Carl
Friedrich Gauss), and it is described by the following equation:

o Estimate is about evaluating the hidden state of the system. The aircraft true position is
hidden from the observer. We can estimate the aircraft position using sensors, such as radar.
The estimate can be significantly improved by using multiple sensors and applying
advanced estimation and tracking algorithms (such as Kalman Filter). Every measured or
computed parameter is an estimate.
o Accuracy: indicates how close the measurement is to the true value.
o Precision describes how much variability there is in a number of measurements of the same
parameter. Accuracy and precision form the basis of the estimate.
The following figure illustrates accuracy and precision.

1. the Kalman Filter’s block diagram


The following figure provides a detailed description of the Kalman Filter’s block diagram.

2
Kalman Filter Implementation

o Step 0: Initialization
As mentioned above, the initialization performed only once, and it provides two parameters:

Initial System State

Initial State Uncertainty


The initialization is followed by prediction.
o Step 1: Measurement
The measurement process shall provide two parameters:

Measured System State ( zn )

Measurement Uncertainty ( rn )
o Step 2: State Update
The state update process is responsible for system's current state estimation.
The state update process inputs are:

Measured Value

The Measurement Uncertainty ( rn)

3
Kalman Filter Implementation

Previous System State Estimate

Estimate Uncertainty
Based on the inputs, the state update process calculates the Kalman Gain and provides two outputs:

Current System State Estimate

Current State Estimate Uncertainty


These parameters are the Kalman Filter outputs.
o Step 3: Prediction
The prediction process extrapolates the current system state and the uncertainty of the current
system state estimate to the next system state, based on the system's dynamic model.
At the first filter iteration the initialization outputs are treated as the Previous State Estimate and
Uncertainty. On the next filter iterations, the prediction outputs become the Previous State Estimate
and Uncertainty.
The following table summarizes the five Kalman Filter equations.

4
Kalman Filter Implementation

III. Simulink Kalman Filter Block


1. Overview
In our case the filter is represented as follows:

Use the Kalman Filter block to estimate states of a state-space plant model given process and
measurement noise covariance data. The state-space model can be time-varying. A steady-state
Kalman filter implementation is used if the state-space model and the noise covariance matrices
are all time-invariant.

5
Kalman Filter Implementation

Kalman filter provides the optimal solution to the following continuous or discrete estimation
problems:
➢ Continuous-Time Estimation
➢ Discrete-Time Estimation

as part of our project we will work on the Discrete-Time Estimation with a sample time Ts=1s.
2. the Kalman Filter block parameters
▪ Time Domaine: To Specify whether to estimate continuous-time or discrete-time states:
- Discrete-Time (Default) — Block estimates discrete-time states (our case)
- Continuous-Time — Block estimates continuous-time states
▪ Use the current measurement y[n] to improve xhat[n]: I selected this option because if it’s
not selected, the delayed estimator (variant) is used. This option is available only
when Time Domain is Discrete-Time.
▪ Model source: I selected the InputPort option in this case, and as a result I Specified the
A,, C, matrices as input signals to the Kalman Filter block( I don’t use the B and D matrices
because I have not an input u). The block includes additional input ports A and C. Also, I
specified the following in the block parameters:
- Number of states — Number of states to be estimated, specified as a positive
integer. In our case is 1.
- Number of outputs — Number of measured outputs in the model, specified as
a positive integer. In our case is 1.

6
Kalman Filter Implementation

▪ Sample Time: specified as -1 or a positive scalar. This option is available only when Time
Domain is Discrete Time. In our case the sample time is Ts= 1s.
▪ Source: this option Specifies how to enter the initial state estimates and initial state
estimation error covariance, in this part I selected the inputPort as a result the block
includes an additional input port X0. A second additional input port P0 is added.
▪ R: is the Measurement noise covariance (=0.1).
▪ N: Process and measurement noise cross-covariance (=0).
▪ Add input port u: Unselecting this option removes the input port u from the block and
removes the B, D and Number of inputs parameters from the block dialog box which is
our case.
▪ Add input port Enable to control measurement updates: I Select this option because I
want to control the measurement updates. The block includes an additional input port
Enable. The Enable input port takes a scalar signal.
IV. C code
1. Generate c code from matlab Simulink:
Simulink Coder™ generates standalone C and C++ code from Simulink models for deployment in a wide
variety of applications. But before I generated the c code, I configured the model for code generation settings
in the Configuration Parameters dialog box. And, I Chose the appropriate solver and code generation target,
and check the model configuration for execution efficiency as shown below.

7
Kalman Filter Implementation

8
Kalman Filter Implementation

2. Development in CoIDE:

You might also like