function [sys,x0,str,ts] =EKF(t,x,u,flag)
% The following outlines the general structure of an S-function.
switch flag,
%%%%%%%%%%%%%%%%%%
% Initialization %
%%%%%%%%%%%%%%%%%%
case 0,
[sys,x0,str,ts]=mdlInitializeSizes;
%%%%%%%%%%%%%%%
% Derivatives %
%%%%%%%%%%%%%%%
%%%%%%%%%%
% Update %
%%%%%%%%%%
case 2,
sys=mdlUpdate(t,x,u);
%%%%%%%%%%%
% Outputs %
%%%%%%%%%%%
case 3,
sys=mdlOutputs(t,x,u);
%%%%%%%%%%%%%%%%%%%%%%%
% GetTimeOfNextVarHit %
%%%%%%%%%%%%%%%%%%%%%%%
case {1,4,9}
sys=[];
%%%%%%%%%%%%%
% Terminate %
%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%
% Unexpected flags %
%%%%%%%%%%%%%%%%%%%%
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
% end sfuntmpl
%=============================================================================
% mdlInitializeSizes
% Return the sizes, initial conditions, and sample times for the S-function.
%=============================================================================
%
function [sys,x0,str,ts]=mdlInitializeSizes
global P0;
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 4;
sizes.NumOutputs = 4;
sizes.NumInputs = 4;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 1;
sys = simsizes(sizes);
% initialize the initial conditions
x0 = [0 0 0 0];
P0 = diag([0.1 0.1 0 0]);%P估计初值
% str is always an empty matrix
str = [];
ts = 1e-6;
% end mdlInitializeSizes
%=======================================================================
% mdlDerivatives
% Return the derivatives for the continuous states.
%=======================================================================
function sys = mdlUpdate(t,x,u)
global P0;
Rs = 2.875;%电阻
Ls = 0.0085;%电感
np = 2;%极对数
J = 0.008;%转动惯量
flux = 0.3;%磁链
B1 = 0;%阻尼系数
Q = diag([0.1 0.1 1 0.01]);
R = diag([0.2 0.2]);
T = 1e-6;
vs_ab = [u(1) u(2)]';
is_ab = [u(3) u(4)]';
H = [1 0 0 0; 0 1 0 0];
B = [1/Ls 0 0 0; 0 1/Ls 0 0]';
F = [-Rs/Ls 0 flux/Ls*sin(x(4)) flux/Ls*x(3)*cos(x(4));0 -Rs/Ls -...
flux/Ls*cos(x(4)) flux/Ls*x(3)*sin(x(4)); 0 0 0 0; 0 0 1 0];%雅克比矩阵
%非线性系统矩阵函数3/2*np^2*flux/J*(x(2)*cos(x(4))-x(1)*sin(x(4)))-B1*x(3)/J
f1 = [-Rs/Ls*x(1)+flux/Ls*x(3)*sin(x(4));-Rs/Ls*x(2)-flux/Ls*x(3)*cos(x(4)); 0; x(3)];
f2 = diag([1 1 1 1])+T*F;%系统转移矩阵
X_pred = x+T*(f1+B*vs_ab);%系统转移矩阵
Y_pred = H*X_pred;%测量预测值
Y = is_ab;
P_pred = f2*P0*f2'+Q;%预测值
K = P_pred*H'*inv(H*P_pred*H'+R);%增益
sys = X_pred+K*(Y-Y_pred);
P0 = P_pred-K*H*P_pred;%估计值
%=============================================================================
% mdlOutputs
% Return the block outputs.
%=============================================================================
%
function sys=mdlOutputs(t,x,u)
sys=x;
基于EKF的三相PMSM无传感器矢量控制
3星 · 超过75%的资源 需积分: 49 55 浏览量
2018-11-04
18:32:54
上传
评论 15
收藏 40KB RAR 举报
qq_34228913
- 粉丝: 4
- 资源: 10
最新资源
- date0425111111111111111111111
- 包含贪心算法的定义及python代码部分实现
- 自动驾驶-状态估计和定位之扩展卡尔曼滤波.pdf
- csdn之x-ca-key,x-ca-nonce,x-ca-signature与x-ca-signature-headers探索
- 基于TM1620数码显示芯片STM32单片机驱动程序软件源代码.zip
- 【tomcat6使用redis配置session共享】
- 包含杨辉三角的说明及java代码实现
- FDN371N-NL-VB一款SOT23封装N-Channel场效应MOS管
- AutomotiveSPICE-V4.0 中文版
- Java实现杨辉三角的生成和打印代码示例.md
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈