马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
重新編寫以後放入Simulink內已經可以執行了
不過y的參數會一直為0,並不會更新
請問問題是出自哪邊呢??
%S-function for LMS block
function [sys,x0,str,ts] = LMS(t,x,u,flag,w,mu,L)
L=9;
w=zeros(L,1);
x=zeros(L,1);
mu=0.05;
y=0;
d=0;
e=0;
switch flag,
case 0,
[sys,x0,str,ts]=mdlInitializeSizes;
case 1,
sys=mdlDerivatives(t,x,u);
case 2,
sys=mdlUpdate(t,x,u,w,mu,L);
case 3,
sys=mdlOutputs(t,x,u,w,d,mu,L,y,e);
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
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 9;
sizes.NumOutputs = 1;
sizes.NumInputs = 2;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1;
sys = simsizes(sizes);
x0 = zeros(9,1);
str = [];
ts = [1/10000 0];
function sys=mdlDerivatives(t,x,u)
sys = [];
function sys=mdlUpdate(t,x,u,w,mu,L,y,e)
x(L:2) = x(L-1:1);
x(1)=u(2);
d=u(1);
%e=u(1)
y=w'*x
e=d-y
sys= w+mu*x*e; % w(k) = w(0) + mu*x*e
w=sys
function sys=mdlOutputs(t,x,u,w,d,mu,L,y,e)
sys = y;
function sys=mdlGetTimeOfNextVarHit(t,x,u)
sampleTime = 1;
sys = t + sampleTime;
function sys=mdlTerminate(t,x,u)
sys = [];
% end mdlTerminate |