Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.

Topic: Problem about extended kalman filter in s function
Replies: 2   Last Post: Sep 11, 2013 10:12 PM

 Messages: [ Previous | Next ]
 liu Posts: 1 Registered: 11/22/10
Problem about extended kalman filter in s function
Posted: Nov 22, 2010 9:36 PM

hello&#65292;guys
i am working on inertia identification of pmsm using extended kalman filter in Matlab.Now i have a problem.I wrote a s function in simulink to identify the inertia and load torque of the system,the value of the result is correct but the convergence time is too slow.The normal convergence time is about 0.1s,but my program output more than 7s.
the code is below,thank you for your help.
function [sys,x0,str,ts] = EKFLITER(t,x,u,flag)
switch flag,
case 0,
[sys,x0,str,ts]=mdlInitializeSizes;
case 2,
sys=mdlUpdate(t,x,u);
case 3,
sys=mdlOutputs(t,x,u);
case {1,4,9},
sys=[];
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end

function [sys,x0,str,ts]=mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 3;
sizes.NumOutputs = 2;
sizes.NumInputs = 2;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 1;
sys = simsizes(sizes);
x0 = [0 0 1500];
str = [];
ts =1e-4;

function sys=mdlUpdate(t,x,u)
ts=1e-4;
A=[1 -x(3)*ts 0;0 1 0;0 0 1];
B=[x(3)*ts 0 0]';
P=diag([1 1 10]);
C=[1 0 0];
H=[1 0 0];
Q=diag([1e-5 1e-4 5e-6]);
R=5e-3;
y=u(2);
Y=C*x;
G=[1 -x(3)*ts u(1)-x(2)*ts;0 1 0;0 0 1];
%The first step
x=A*x+B*u(1);
P=G*P*G'+Q;%Here is the problem,everytime the programe run mdlupdate the P will be reset to diag([1 1 10]),how can i make this change
%The second step
K=P*H'/(H*P*H'+R);
Xe=x+K*[y-Y];
Pe=P-K*H*P;

%Result
sys(1)=Xe(1);
sys(2)=Xe(2);
sys(3)=Xe(3);

function sys=mdlOutputs(t,Xe,u)