Reputation: 1708
Assume that you have a Simulink simulation where a certain signal is first positive and after some time t in a given interval, it becomes negative. Your goal is to find the zero-crossing.
A first approach would be to plot the signal over the given interval, save it and calculate the zero-crossing.
When repeating this simulation numerous times for varying parameters, it would be beneficial to be able to stop the simulation after the signal has become negative. Then there is already enough information for the calculation of the zero-crossing in Matlab. How could you do that?
Upvotes: 4
Views: 12105
Reputation: 11238
Another ways:
You can use Hit Crossing Block in Simulink to find time at the moment of hitting zero.
Another way - use any Trigger or Resettable system. It detects the zero crossing too. For example: this question at SO.
Of course you can also use User Defined function
to detect zero crossing by your hand and do whatever you want with the signal at the same time.
About making a lot of simulations and then stops:
you can use Check Upper Static Bound for automatically stops simulation at the moment when zero will be crossed in n
th time. For example:
I set upper bound = 10
for this block and this stops at 10th crossing.
There are a lot of ways to save function values in this points or just array of times but this is an another question :)
Upvotes: 3
Reputation: 13886
Yes, use the Stop Simulation block with the appropriate logical input to the block:
Upvotes: 3
Reputation: 14939
You can use an if / else
block to control the flow in the Simulink model. In the if / else
block, you can choose the condition if u > 0
, continue as normal if it's true, and use the else
-option to bypass the rest of the flow you would otherwise run. For instance jump directly to the scope.
Upvotes: 3