How do a check if a non-negative signal is 'equal to' zero?
1 view (last 30 days)
Show older comments
MathWorks Support Team
on 21 Sep 2022
Answered: MathWorks Support Team
on 15 Nov 2022
I have a non-negative signal that is occasionally equal to 0. However, the floating point values and the width of my timesteps in my Simulink model are such that the signal is usually never actually equal to 0. How can I check for the signal reaching 0?
Accepted Answer
MathWorks Support Team
on 21 Sep 2022
Comparing to Threshold
The simplest way is to compare to a threshold value and check that the signal value is less than or equal to some value close to 0, like 0.001. There are a few ways to do this, including using a 'Compare to Constant' block. More information on a 'Compare to Constant' block can be found by referring to the link below:
A 'Hit Crossing' block could also be useful in this case, as it will output true when a crossing point is hit. More information on 'Hit Crossing' can be found by referring to the link below:
Both of these blocks have zero-crossing detection enabled by default. Zero-crossing detection enables Simulink to detect discontinuities without resorting to excessively small timesteps, so these blocks in conjunction with a threshold value will determine when the value is 0 or close to 0 accurately. More information on zero-crossing detection can be found by referring to the link below:
Derivative Checking
Another way that is less straightforward but could potentially still be useful is to check the derivative of the signal. This will require using a 'Derivative' block in Simulink. More information on the 'Derivative' block can be found by referring to the link below:
Since the signal bounces off of zero in the model, the derivative will change from negative to positive whenever zero is reached. In this case, we can check for the derivative crossing zero using a 'Compare to Constant' block with zero-crossing detection enabled as above.
0 Comments
More Answers (0)
See Also
Categories
Find more on General Applications 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!