MATLAB Answers

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

5 ビュー (過去 30 日間)
Rajesh Siraskar
Rajesh Siraskar 2020 年 1 月 8 日
コメント済み: Rajesh Siraskar 2020 年 1 月 10 日
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

  0 件のコメント

サインイン to comment.

採用された回答

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 件のコメント

表示 5 件の古いコメント
Rajesh Siraskar
Rajesh Siraskar 2020 年 1 月 9 日
Fangjun - just a quick observation.
While this works stand-alone - do you know how to make it work in mixed signal cases?
I am actually building a Reinforcement Learning based control system and I am trying to penalize for oscillations and hence the need to count oscillations
When I put this solution into the whole scheme of things, I get an error. But thanks for the solution.
On the other hand if set the simulation as continous time then I get this error
Caused by:
Error using rl.env.SimulinkEnvWithAgent/simWrapper (line 325)
Error due to multiple causes.
Error using Simulink.SimulationInput/sim
Data type mismatch. The internal rule determines the output of
'Stiction_TF_Valve_RL_VR_V11/RL Sub-System/Compute Rewards/Gain' to be a signal of data type
'ufix32_En1000'. However, it is driving a signal of data type 'double'.
Error using Simulink.SimulationInput/sim
An error occurred while propagating data type 'uint16' from 'Stiction_TF_Valve_RL_VR_V11/RL
Sub-System/Compute Rewards/Add', output port 1.
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.

サインイン to comment.

その他の回答 (0 件)

サインイン してこの質問に回答します。

製品


リリース

R2019a

Translated by