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保存了这个值,直到被下次触发。结果如下图所示:

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

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

在不改变步长的情况下提高simulink的仿真精度

一般情况下,如果我们需要提高simulink的仿真精度,我们会缩短仿真步长,但是如果整个仿真持续很长很长时间呢?
有一种比较广泛的特殊情况,我们无需缩短步长,仍然可以提高仿真精度,这样,就大大减少了我们等待simulink完成仿真的时间~~
问题描述:
在有些时间较长的仿真中,可能存在某一个或几个时刻,要求仿真步长非常短,以达到足够的精度,而在其余时间,整个系统的仿真步长可以较大。比如某个时候发动机需要工作0.017s,而在其他不工作的时刻,系统只需按1s或者10s的步长运行100,000s即可。如果将整个的仿真步长限制在0.001s,这样仿真时间就太长了,得不偿失。
问题的解决:
如何解决这个问题呢,我想了如下一个方法,在此抛砖引玉,希望大家都能发表一下自己的意见:当发动机工作的时候,利用使能子系统(Enable Subsystem)让一个方波信号(Pulse Generator)开始输出(事实上输出并不用做什么,只是用他的采样时间),令方波信号的周期在你希望的步长的2倍上,如上文就是0.002s,其他时刻方波信号不进行输出(使能子系统不工作)。这样的话,即使将整个系统的仿真最大步长设置为10s,当发动机工作时候,还能够提供0.001s的工作精度,并且,Simulink的仿真时间并没有显著没有增长!
使能子系统仿真模块内部构造如下图所示:

Introduce to My Bolg

Welcome to my space!
I am a phD. of a Chinese university, I will write some of my research in the blog in the future. If this space became a communication place of our research, I would be very happy!
This is the end of today's log, it is so short and I have to make it known to all that my English is not very good, possibly very bad. But I will do my best to make my foreigner friends easy to learn!

2008年11月16日星期日

Changing From Microsoft to Google

Today I decide to change my blog address from Windows Live of Microsoft to blogger of Google.
Well, let me tell you what my early blog address is: http://kokyo52.spaces.live.com/
I wish to have a new begin with the help of Google here. And thanks Microsoft of giving me a place in the Internet to display myself before.
Welcome Everybody to My New Home!