马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
请大家帮下忙?怎么产生间隔服从指数分布,幅度服从锐利分布的随机脉冲信号?
下面是我用s-函数写的程序,但是结果不正确,请大家帮忙看下。
(1)产生间隔为0.1,0.2,0.3,……,宽度为0.2的脉冲序列
function [sys,x0,str,ts] = my132(t,x,u,flag,T,r)
T=0;
r=0.1;
switch flag,
case 0,
[sys,x0,str,ts]=mdlInitializeSizes;
case 1,
sys=mdlDerivatives(t,x,u);
case 2,
sys=mdlUpdate(t,x,u);
case 3,
sys=mdlOutputs(t,x,u,T,r);
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 = 0;
sizes.NumOutputs = 1;
sizes.NumInputs = 0;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1;
sys = simsizes(sizes);
x0 = [];
str = [];
ts = [0.01 0];
function sys=mdlDerivatives(t,x,u)
sys = [];
function sys=mdlUpdate(t,x,u)
sys = [];
function sys=mdlOutputs(t,x,u,T,r)
if t>=T&&t<=T+r
sys =0;
elseif t>T+r&&t<=T+r+0.2
sys=1;
else
T=r+0.2+T;
r=r+0.1;
sys=mdlOutputs(t,x,u,T,r);
end
function sys=mdlGetTimeOfNextVarHit(t,x,u)
sampleTime =1;
sys = t + sampleTime;
function sys=mdlTerminate(t,x,u)
sys = [];
(2)产生间隔为rand,宽度为0.2的脉冲。借助与(1)的思想,但运行的结果不正确,请大家把那个我看下,是不是方法错了。还又没有其他的方法
function [sys,x0,str,ts] = my132(t,x,u,flag,T,r)
T=0;
r=rand;
switch flag,
case 0,
[sys,x0,str,ts]=mdlInitializeSizes;
case 1,
sys=mdlDerivatives(t,x,u);
case 2,
sys=mdlUpdate(t,x,u);
case 3,
sys=mdlOutputs(t,x,u,T,r);
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 = 0;
sizes.NumOutputs = 1;
sizes.NumInputs = 0;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1;
sys = simsizes(sizes);
x0 = [];
str = [];
ts = [0.01 0];
function sys=mdlDerivatives(t,x,u)
sys = [];
function sys=mdlUpdate(t,x,u)
sys = [];
function sys=mdlOutputs(t,x,u,T,r)
if t>=T&&t<=T+r
sys =0;
elseif t>T+r&&t<=T+r+0.2
sys=1;
else
T=r+0.2+T;
r=rand;
sys=mdlOutputs(t,x,u,T,r);
end
function sys=mdlGetTimeOfNextVarHit(t,x,u)
sampleTime =1;
sys = t + sampleTime;
function sys=mdlTerminate(t,x,u)
sys = [];
请大家帮忙,感谢感谢! |