Info

此问题已关闭。 请重新打开它进行编辑或回答。

ekf matlab switch flag error

1 次查看(过去 30 天)
abbas ogur
abbas ogur 2017-6-24
关闭: Sabin 2025-6-20
hello every body i have to build an ekf model for PMSM motor so searched and found this code
function [sys,x0,str,ts]=EKM6a(t,x,u,flag,P,Q,R);
%global Rs Ld Lq Fm v_alpha v_beta i_alpha i_beta;
%global P Q R fid;
%global out fit;
Rs=5;
Ld=10e-3;
Lq=10e-3;
Fm=0.175;
T=5e-4;
%i=0;
Bd=[1/Ld 0;0 1/Lq;0 0;0 0];
H=[1 0 0 0;0 1 0 0];
switch flag
case 0
%ekmini;
sizes=simsizes;
sizes.NumContStates=0;
sizes.NumDiscStates=4;
sizes.NumOutputs=4;
sizes.NumInputs=4;
sizes.DirFeedthrough=0;
sizes.NumSampleTimes=1;
str=[];
ts=[0.0005 0];
x0=[0; 0; 0; 0];
sys = simsizes(sizes);
case 2
% Step 1:Initialization of the state vector and covariance matrices
Uk=[u(1);u(2)];
Y=[u(3);u(4)];
% Step 2:Prediction of the state vector
fx=[-Rs/Ld*x(1)+Fm/Ld*x(3)*sin(x(4)) ;-Rs/Lq*x(2)-Fm/Lq*x(3)*cos(x(4)) ;0 ;x(3) ];
F=[-Rs/Ld 0 Fm/Ld*sin(x(4)) Fm/Ld*x(3)*cos(x(4));0 -Rs/Lq -Fm/Lq*cos(x(4)) Fm/Lq*x(3)*sin(x(4));0 0 0 0;0 0 1 0];
x1=x+T*(fx+Bd*Uk);
% Step 3: Covariance estimation of prediction
P1=P+T*(F*P+P*F')+Q; % P1 is 4x4
% Step 4: Kalman filter gain computation
K1=P1*H'*inv(H*P1*H'+R);% K1 is 4x2
% Step 5: State vector estimation
h=[x1(1);x1(2)];
sys=x1+K1*(Y-h);
% Step 6: Covariance matrix of estimation error
P=P1-K1*H*P1;
case 3
sys=x;
case 4
sys=(round(t/T)+1)*T;
%sys=[];
case 9
sys=[];
end
if true
% code
end
the problem is when i run the code it's gave me the error below:
EKM6a
Not enough input arguments.
Error in EKM6a (line 14)
switch flag
i dont know how to solve this problem please help me
  2 个评论
Ge Zhang
Ge Zhang 2022-12-5
I have the same 'Not enough input' problem, did you find the way to fix it?
jessupj
jessupj 2022-12-5
you don't run the code. it's a function, so you have to CALL the function by passing it arguments.

回答(0 个)

此问题已关闭。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by