Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
90c897f6
Commit
90c897f6
authored
Mar 07, 2012
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding initial version of kalman filter code
parent
98541091
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
128 additions
and
0 deletions
+128
-0
filtering.h
dlib/filtering.h
+11
-0
kalman_filter.h
dlib/filtering/kalman_filter.h
+104
-0
kalman_filter_abstract.h
dlib/filtering/kalman_filter_abstract.h
+13
-0
No files found.
dlib/filtering.h
0 → 100644
View file @
90c897f6
// Copyright (C) 2012 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_FILTERiNG_HEADER
#define DLIB_FILTERiNG_HEADER
#include "filtering/kalman_filter.h"
#endif // DLIB_FILTERiNG_HEADER
dlib/filtering/kalman_filter.h
0 → 100644
View file @
90c897f6
// Copyright (C) 2012 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_KALMAN_FiLTER_H__
#define DLIB_KALMAN_FiLTER_H__
#include "kalman_filter_abstract.h"
#include "../matrix.h"
namespace
dlib
{
// ----------------------------------------------------------------------------------------
template
<
long
states
,
long
measurements
>
class
kalman_filter
{
public
:
kalman_filter
()
{
H
=
0
;
A
=
0
;
Q
=
0
;
R
=
0
;
x
=
0
;
xb
=
0
;
P
=
identity_matrix
<
double
>
(
states
);
got_first_meas
=
false
;
}
void
set_observation_model
(
const
matrix
<
double
,
measurements
,
states
>&
H_
)
{
H
=
H_
;
}
void
set_transitoin_model
(
const
matrix
<
double
,
states
,
states
>&
A_
)
{
A
=
A_
;
}
void
set_process_noise
(
const
matrix
<
double
,
states
,
states
>&
Q_
)
{
Q
=
Q_
;
}
void
set_measurement_noise
(
const
matrix
<
double
,
measurements
,
measurements
>&
R_
)
{
R
=
R_
;
}
void
update
(
)
{
P
=
A
*
P
*
trans
(
A
)
+
Q
;
const
matrix
<
double
,
states
,
measurements
>
K
=
P
*
trans
(
H
)
*
pinv
(
H
*
P
*
trans
(
H
)
+
R
);
x
=
xb
;
xb
=
A
*
x
;
P
=
(
identity_matrix
<
double
,
states
>
()
-
K
*
H
)
*
P
;
}
void
update
(
const
matrix
<
double
,
measurements
,
1
>&
z
)
{
P
=
A
*
P
*
trans
(
A
)
+
Q
;
const
matrix
<
double
,
states
,
measurements
>
K
=
P
*
trans
(
H
)
*
pinv
(
H
*
P
*
trans
(
H
)
+
R
);
if
(
got_first_meas
)
{
const
matrix
<
double
,
measurements
,
1
>
res
=
z
-
H
*
xb
;
x
=
xb
+
K
*
res
;
}
else
{
// Since we don't have a previous state estimate at the start of filtering,
// we will just set the current state to whatever is indicated by the measurement
x
=
pinv
(
H
)
*
z
;
got_first_meas
=
true
;
}
xb
=
A
*
x
;
P
=
(
identity_matrix
<
double
,
states
>
()
-
K
*
H
)
*
P
;
}
const
matrix
<
double
,
states
,
1
>&
get_current_state
()
{
return
x
;
}
const
matrix
<
double
,
states
,
1
>&
get_predicted_next_state
()
{
return
xb
;
}
private
:
bool
got_first_meas
;
matrix
<
double
,
states
,
1
>
x
,
xb
;
matrix
<
double
,
states
,
states
>
P
;
matrix
<
double
,
measurements
,
states
>
H
;
matrix
<
double
,
states
,
states
>
A
;
matrix
<
double
,
states
,
states
>
Q
;
matrix
<
double
,
measurements
,
measurements
>
R
;
};
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_KALMAN_FiLTER_H__
dlib/filtering/kalman_filter_abstract.h
0 → 100644
View file @
90c897f6
// Copyright (C) 2012 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#undef DLIB_KALMAN_FiLTER_ABSTRACT_H__
#ifdef DLIB_KALMAN_FiLTER_ABSTRACT_H__
namespace
dlib
{
}
#endif // DLIB_KALMAN_FiLTER_ABSTRACT_H__
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment