-
Notifications
You must be signed in to change notification settings - Fork 40
/
lti_disc.m
82 lines (76 loc) · 1.78 KB
/
lti_disc.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
%LTI_DISC Discretize LTI ODE with Gaussian Noise
%
% Syntax:
% [A,Q] = lti_disc(F,L,Qc,dt)
%
% In:
% F - NxN Feedback matrix
% L - NxL Noise effect matrix (optional, default identity)
% Qc - LxL Diagonal Spectral Density (optional, default zeros)
% dt - Time Step (optional, default 1)
%
% Out:
% A - Transition matrix
% Q - Discrete Process Covariance
%
% Description:
% Discretize LTI ODE with Gaussian Noise. The original
% ODE model is in form
%
% dx/dt = F x + L w, w ~ N(0,Qc)
%
% Result of discretization is the model
%
% x[k] = A x[k-1] + q, q ~ N(0,Q)
%
% Which can be used for integrating the model
% exactly over time steps, which are multiples
% of dt.
% History:
% 11.01.2003 Covariance propagation by matrix fractions
% 20.11.2002 The first official version.
%
% Copyright (C) 2002, 2003 Simo Särkkä
%
% $Id$
%
% This software is distributed under the GNU General Public
% Licence (version 2 or later); please refer to the file
% Licence.txt, included with the software, for details.
function [A,Q] = lti_disc(F,L,Q,dt)
%
% Check number of arguments
%
if nargin < 1
error('Too few arguments');
end
if nargin < 2
L = [];
end
if nargin < 3
Q = [];
end
if nargin < 4
dt = [];
end
if isempty(L)
L = eye(size(F,1));
end
if isempty(Q)
Q = zeros(size(F,1),size(F,1));
end
if isempty(dt)
dt = 1;
end
%
% Closed form integration of transition matrix
%
A = expm(F*dt);
%
% Closed form integration of covariance
% by matrix fraction decomposition
%
n = size(F,1);
Phi = [F L*Q*L'; zeros(n,n) -F'];
AB = expm(Phi*dt)*[zeros(n,n);eye(n)];
Q = AB(1:n,:)/AB((n+1):(2*n),:);