马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
刚学s函数, 想用s函数寫出一個如下圖的LMSBLOCK,可是结果总是不对
其中output端口,主要需要的是error和wts所以只有設定2個output
輸入端口因為有關聯到y(n)所以我又多牽入一個input給他所以設定3個input
麻煩大家帮我看看是那里不对,多谢了
%S-function for LMS block
function [sys,x0,str,ts] = LMS(t,x,u,flag,T,w,mu)
switch flag,
case 0,
[sys,x0,str,ts]=mdlInitializeSizes(T,w,mu);
case 1,
sys=mdlDerivatives(t,x,u);
case 2,
sys=mdlUpdate(t,x,u);
case 3,
sys=mdlOutputs(t,x,u,w);
case 4,
sys=mdlGetTimeOfNextVarHit(t,x,u);
case 9,
sys=mdlTerminate(t,x,u);
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
function [sys,x0,str,ts]=mdlInitializeSizes(T,w,mu)
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = length(w)-1;
sizes.NumOutputs = 2;
sizes.NumInputs = 3;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1;
sys = simsizes(sizes);
x0 = zeros(length(w)-1,1);
str = [];
ts = [T 0];
function sys=mdlDerivatives(t,x,u)
sys = [];
function sys=mdlUpdate(t,x,u,n)
sys(1) = [u(1);n(1:end)];
sys(2) = [u(2);n(1:end)];
sys(3) = [u(3);x(1:end-1)];
function sys=mdlOutputs(t,x,u,w)
e=[u(1);n]-[u(2);n]
sys(1) = w+mu*[u(3);x]*e;
sys(2)=e;
function sys=mdlGetTimeOfNextVarHit(t,x,u)
sampleTime = 1;
sys = t + sampleTime;
function sys=mdlTerminate(t,x,u)
sys = [];
% end mdlTerminate |