Counting Consecutive Threshold Crossings in a Signal (Counting Oscillations)

8 ビュー (過去 30 日間)
Fawad Farooq Ashraf
Fawad Farooq Ashraf 2022 年 10 月 10 日
コメント済み: Fawad Farooq Ashraf 2022 年 10 月 11 日
I have an oscillating signal in a SIMULINK model and I want to count the number of times it crosses a certain threshold level (positive and negative) consecutively. How can I do that? There is a built-in block for Zero-Crossings Counter but what can I use to solve my problem?

回答 (1 件)

Allen
Allen 2022 年 10 月 10 日
You can accomplish a check against a threshold using the following code or a slight variation to meet other needs.
% Generating a random signal for demonstration purposes
S = 40*rand([1,100])-20;
% Define your threshold
threshold = 0;
count = nnz(diff(sign(S-threshold)));
  1 件のコメント
Fawad Farooq Ashraf
Fawad Farooq Ashraf 2022 年 10 月 11 日
Thank you for your reply. But unfortunately, I have to do this in real-time for a moving signal (i.e., I'll just have single values of the signal at each time step) and I have to use SIMULINK blocks for the implementation.

サインインしてコメントする。

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by