-
Notifications
You must be signed in to change notification settings - Fork 0
/
KalmanParameters.m
executable file
·48 lines (45 loc) · 1.48 KB
/
KalmanParameters.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
function [sys,x0,str,ts] = KalmanParameters(t,x,u,flag,Fs,f,sigman,sigmav,M,lambda)
global T P U B;
T = 1/Fs;
wT = 2*pi*f*T;
P = [cos(wT) -sin(wT) 0;sin(wT) cos(wT) 0;0 0 exp(-lambda*T)];
% M = [m^2 0 0;0 m^2 0;0 0 m^2];
U = [sigmav^2 0 0;0 sigmav^2 0;0 0 sigmav^2];
B = [sigman^2];% B = [sigman2 0 0;0 sigman2 0;0 0 sigman2];
switch flag,
case 0
[sys,x0,str,ts] = mdlInitializeSizes(Fs,f,sigman,sigmav,M,lambda,T,P,U,B,wT); % Initialization
case 3
sys = mdlOutputs(t,x,u); % Calculate outputs
case { 1, 2, 4, 9 }
s = []; % Unused flags
otherwise
error(['Unhandled flag = ',num2str(flag)]); % Error handling
end;
% End of KalmanParameters function.
function [sys,x0,str,ts] = mdlInitializeSizes(Fs,f,sigman,sigmav,M,lambda,T,P,U,B,wT)
% Call function simsizes to create the sizes structure.
warning off;
sizes = simsizes;
% Load the sizes structure with the initialization information.
sizes.NumContStates= 0;
sizes.NumDiscStates= 0;
sizes.NumOutputs= 0;
sizes.NumInputs= 0;
sizes.DirFeedthrough=1;
sizes.NumSampleTimes=1;
% Load the sys vector with the sizes information.
sys = simsizes(sizes);
%
x0 = []; % No continuous states
%
str = []; % No state ordering
%
ts = [T 0]; % Inherited sample time
% End of mdlInitializeSizes.
%==============================================================
% Function mdlOutputs performs the calculations.
%==============================================================
function sys = mdlOutputs(t,x,u)
% global T P U B;
sys = [];