"Matlab Function" calling sequence in Simulink

1 次查看(过去 30 天)
Hi all,
I'm having a problem with a "Matlab function" block. The issue is that the function is written assuming that it will always be passed new data.
The function is a simple frequency estimator, which looks for zero crossings of the input signal and everytime it detects a new zero crossing, outputs the new frequency value based on the time between crossings.
The problem I'm having is that suddenly, it is outputting a very high frequency because it is getting several zero crossings in close proximity. The input to this function comes from a sine block, so there is no noise.
I have been logging the arguments passed to the function (sine wave value and time), and I have seen that the function is not always called with increasing time values. Sometimes it's called with the same time value twice or more, and sometimes it even receives past values.
I think this could have something to do with the solver going back and forth to find some zero crossing or something, but I haven't found any documentation describing this behavior and possible workarounds.
Thanks, Pedro

回答(1 个)

Debarati Banerjee
Debarati Banerjee 2016-6-22
I guess you are using 'Variable-Step Solver' for which you are seeing that sometimes its on the same Time values and sometimes it gets past values. You can get more information on this topic in this blog
Can you use Fixed Step solver for your case with a suitable Sample time (such that the Zero Crossings are not missed)?
Cheers, Debarati
  1 个评论
Pedro Pérez de Ayala Rull
Thanks for your answer Debarati. I'm out of office for the next two weeks, I'll give it a try when I'm back and let you know the results.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Install Products 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by