2008年11月27日星期四

让瞬间信号保持1s或更长时间的模块

某些时候,我们需要将一个瞬间出现的信号保持1s或其他的时间长度,比如将触发器触发获得的信号保持指定的时间长度,那么可以采用如下一种方法:
* 采用Monostable模块保持指定的时间长度;
* 在模型中放入一个Triggered Subsystem模块,用于保持这个瞬时信号;
* 在模型中放入一个Matlab function模块,用于将瞬时信号转化成正的标量;
* 用乘法器将Monostable模块的输出和Triggered Subsystem模块的输出相乘即可。



再封装一下,就实现了输入一个脉冲信号,输出一个宽度为1s的幅值为同样大小的方波信号。

2008年11月25日星期二

有趣的Matlab注释-自己写m文件函数帮助的技巧

每当我们help一个函数的时候,我们可以看到,Matlab会在最后加上See also,其实,自己写的m文件帮助也可以加上See also 后面带有链接这种功能的东西
如果在函数的第二行开始写注释,就可以实现用help function命令显示帮助信息的功能,这可能大家都知道了,就不多说了,关键是如何实现See also
See also 的具体实现不知道Matlab是怎么做到的,但是,只要我们注意一下写的格式,就可以写出See also来:
在See also FUNCTIONNAME的后面,一般是英文句号,其后一定要有空格,并且See also 必须这样写,不可以写成see also 或者别的什么,最重要的,See also 后面的函数名字要全部大写
function testHelp
%testHelp tests help
% You can get help from it
% See also TESTHELP.

出来的效果如下:
testHelp tests help
You can get help from it
See also testhelp.

可以看到,上面的testhelp被自动小写,而且加了链接
如果有一个字母没有大写,比如第一个t:

function testHelp
%testHelp tests help
% You can get help from it
% See also tESTHELP.


效果如下:
testHelp tests help
You can get help from it
See also testhelp.

可以看到,除了t之外,后面的esthelp被链接了
如果英文的句号后面没有空格:
function testHelp
%testHelp tests help
% You can get help from it
% See also TESTHELP.

效果如下:
testHelp tests help
You can get help from it
See also

这下一点也显示不出来了,很有意思,如果有多个函数需要see also,直接打逗号再写就可以了。

The Interesting Characters of Triggered Subsystem

Maybe sb. is not very familiar with Triggered Subsystem. In fact, there are many interesting characters in Triggered Subsystem.
This is the figure of Triggered Subsystems. One of its useful characters is that it keeps the value of the time when it has been triggered, until it is been triggered the next time. For example:Make the Trigger input of the Triggered Subsystem the Step signal, whose step time has been set to 1s. Thus the Triggered Subsystem would be triggered at 1 second. And the input of the empty Triggered Subsystem is Clock block. It is interesting to guess what is the output.
The answer is that at 1 second, the Triggered Subsystem keeps the value of that time until the simulation ended. As is shown in the below.
This is to say that at the time of simulation, we can use this model to save some value which we are interested in. Also, we can use the command of PERSISTENT to define the persistent variable in m-file to save some value while simulating.

2008年11月19日星期三

Get An Exact Result By Simulink Without Shorten The Step Size

If we want to get a exact result from simulink, we have to shorten the step size of simulation. But if it needs a very long time?
Sometimes, in a very long time simulaion, there is only a very short period when we have to shorten the step size. And at the other periods, we needn't to simulated in a very low speed, for only a litter time are important which we have to focus on. For example, only a little time when the moto works, which is so called the important period.In this situation, we can change the step size dynamically. Here is a very simple way to get it:
When the moto are working, we can make a Enable Subsystem to work which include a Pulse Generator block. If you want a step size of 1s at that time, you should make the period of the Pulse Generator to be double of 1s, and then you can make sure that the step size have changed to 1s even if it was 100s before!The blocks in the Enable Subsystem is shown below:

2008年11月18日星期二

触发子系统特性浅析

Triggered模块就是触发模块,也许有的人对他并不熟悉,其实,Triggered有许多有意思的地方需要我们去了解,而且,了解之后,我们可以利用它做很多有用的事情



上图就是Triggered模块的内部示意图,通过修改正上方的Trigger,可以指定是上升沿触发,还是下降沿触发,还是either,都触发。
我们以上升沿触发为例,说明它的一个特殊的功效。
* Triggered模块在触发之后,保持了它触发那一瞬间的值。
也就是说,在Triggered模块被触发之后,只要还没有被再次触发,它将一直输出触发那一瞬间的值,比如
我们让触发器为上升沿触发,接入step信号,step time 设定为 1s,那么将在仿真1s时触发Triggered Subsystem,Triggered Subsystem的输入是时间,内部为空,如上图所示,那么输出是什么呢?模块如下图所示

答案是,输出将在1s以后一直保持1,因为step上升的时间是1s,因此Triggered Subsystem保存了这个值,直到被下次触发。结果如下图所示:

也就是说,在仿真的时候,我们可以利用这一特性,保存一些我们需要的值。

关键是我们要认识到触发子系统不被触发的时候保存了输出,而不是将输出恢复到触发前的水平。