天际 发表于 2008-10-14 22:38

动态时间间隔

请大家帮下忙?怎么产生间隔服从指数分布,幅度服从锐利分布的随机脉冲信号?
下面是我用s-函数写的程序,但是结果不正确,请大家帮忙看下。

(1)产生间隔为0.1,0.2,0.3,……,宽度为0.2的脉冲序列

function = my132(t,x,u,flag,T,r)
T=0;
r=0.1;
switch flag,
case 0,
    =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 =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= ;
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 = my132(t,x,u,flag,T,r)
T=0;
r=rand;
switch flag,
case 0,
    =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 =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= ;
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 = [];

请大家帮忙,感谢感谢!

天际 发表于 2008-10-14 22:40

补充:(1)的程序是正确的只有(2)中又问题
页: [1]
查看完整版本: 动态时间间隔