- Detecting when the signal changes signs.
- A counter that increases with every zero-value detection.
- A comparison block that compares the counter to the value "1".
How can I find the first zero crossing of a signal in Simulink?
5 次查看(过去 30 天)
显示 更早的评论
I have a Simulink model that acquires data in real time using release R2022b.
I would like to have a "control signal" that only activates when a signal reaches zero for the first time. It must not activate when it reaches zero at later times.
How can I do that?
采纳的回答
MathWorks Support Team
2023-2-3
One way to implement that detection system consists of three stages:
The screenshots below show an example of this implementation:
Stage 1 is a combination of a "Memory" block, which outputs the value of its input at the previous time step, a multiplication block, and a comparison to zero. The output of the multiplication block will only be zero or negative when the original signal (the cosine) changes signs, and the output of the comparison block ("<=") will be a value of "1" in those cases.
Stage 2
is a counter implemented through a "Triggered subsystem". This subsystem is activated by the comparison block. The count is stored inside a "Memory" block, and every time the subsystem is activated, the input to the memory is increased by one. The model is shown below.
Stage 3 is simply a comparison to the value "1". The counter from stage 2 will keep increasing as the signal crosses zero many times, and this third stage filters it to only detect the first zero crossing. Note that the signal drops back to zero after the second zero crossing. If you would like the output signal to persist at the value "1" for the rest of the simulation, consider adding another "triggered subsystem" activated by the output of the comparison block ("==").
The scope visualization is shown below:
2 个评论
Les Beckham
2023-2-3
编辑:Les Beckham
2023-2-3
I don't have Simulink right now so I can't test this, but wouldn't it be simpler to just OR the output of stage one with its past value, and get rid of stages 2 and 3? This is for the case where you want a rising edge only on the first zero crossing (and no falling edge thereafter).
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Subsystems 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!