필터 지우기
필터 지우기

How can I find the first zero crossing of a signal in Simulink?

조회 수: 7 (최근 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
MathWorks Support Team 2023년 2월 3일
One way to implement that detection system consists of three stages:
  1. Detecting when the signal changes signs.
  2. A counter that increases with every zero-value detection.
  3. A comparison block that compares the counter to the value "1".
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
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).
Les Beckham
Les Beckham 2023년 2월 3일
How odd. I thought I had used that approach in the past to "latch" a signal.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Subsystems에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by