"Matlab Function" calling sequence in Simulink

2 views (last 30 days)
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

Answers (1)

Debarati Banerjee
Debarati Banerjee on 22 Jun 2016
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 Comment
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.

Sign in to comment.

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!