"Matlab Function" calling sequence in Simulink

1 回表示 (過去 30 日間)
Pedro Pérez de Ayala Rull
Pedro Pérez de Ayala Rull 2016 年 6 月 16 日
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
Pedro Pérez de Ayala Rull 2016 年 6 月 22 日
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 Center および File ExchangeInstall Products についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by