How do I count the number of times zero is being crossed by a signal?

조회 수: 15 (최근 30일)
Hi,
I am trying to build a control system and I want to count the oscillations in a time-span of say 100 seconds.
Can I count the number of times a signal crosses zero (probably using MATLAB's zer-crossing detection algo.) to count the oscillations?
I want it to happen within Simulink - is there any other better way? I just want a count say 10, that tells me there were 10 oscillations.
Oscilltions.PNG

채택된 답변

Fangjun Jiang
Fangjun Jiang 2020년 1월 8일
If you have the DSP toolbox, there is a Zero-Crossing counter block. If not, you can compare the signal with zero, which creates a square wave signal. Use the rising and falling edge to trig an triggered subsystem, inside which adding a Counter block.
  댓글 수: 8
Fangjun Jiang
Fangjun Jiang 2020년 1월 9일
I believe continuous solver should also work. You just need to add DataTypeConversion blocks to deal with those data type mismatches.
Rajesh Siraskar
Rajesh Siraskar 2020년 1월 10일
Make sense - will try. Thanks a lot for your guidance.

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

추가 답변 (1개)

hossein
hossein 2022년 2월 2일
편집: hossein 2022년 2월 2일
You can count the number of times the product of the signal and the shifted signal becomse negative. The below formula gives the number of crossings I guess. I am not sure if this is bug free.
"Sig" is your signal data vector here.
sum(sign((Sig.*[Sig(2:end),Sig(end)]))<0)

카테고리

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

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by