关于Simulink的sample time的问题

  在对simulink建模的过程中,有时候会遇到sample time出现错误的问题,比如下图是我在使用simulink自带的Recursive least square Estimator最小二乘估计器去估计质量和坡度的模型截图。

  但是在仿真的时候就会报错,报错内容如下:‘Error in port sample time. The "TestAlgorithmModel/Vehicle /Recursive Least Squares Estimator" block must operate at a discrete sample time. Either connect discrete-time signals to the "Regressors" and "Output" input ports of the block or explicitly provide a discrete time in the "Sample Time" setting in the block dialog.’

  大致意思就是端口的采样时间出错了,必须得使用离散的采样时间点。但其实我模型的solver(求解器)都已经设置为discrete了,而且我已经把用到了continuous中的各个模组全部替换成 discrete中的模组了(比如积分模块,用的就是discrete中的 discrete-time integrator)。还是这样报错的情况下,只能另想他法了。

  最后找到的解决办法是,在估计器(Estimator)的输入处加上Zero-Order hold模块,如下图所示,并且把Zero-Order hold的仿真时间设置的和离散采样步长一样就可以了,然后问题就真的解决了!

   下面就来探讨一下Zero-Order hold这个模块的作用如何,网上有结论是说这玩意儿是把输入信号每过一段时间跟新一次,并且保持到下一次采样之前,相当于就是把信号离散化处理(也可以是重新修改信号的采样时间),原话地址:https://zhidao.baidu.com/question/368276493483526644.html

  但是我们要追根溯源,https://ww2.mathworks.cn/help/simulink/slref/zeroorderhold.html,官方文件里说他是将具有连续采样时间的输入信号转换为具有离散采样时间的输出信号。和它同样功能的还有Unit delay 和memory,但是官方解释感觉不太明白,于是参考:http://www.ece.northwestern.edu/CSEL/local-apps/matlabhelp/toolbox/simulink/slref/zeroorderhold.html,这篇里面解释的就比较清楚了,Zero-Order Hold blocks between the fast-to-slow transitions.the sample rate of the Zero-Order Hold must be set to that of the slower block. For slow-to-fast transitions, use the Unit Delay block. 也就是说快转慢用zero-order hold,慢转快用Unit Delay。

猜你喜欢

转载自www.cnblogs.com/BennyCoding/p/12354469.html
今日推荐