Counting Consecutive Threshold Crossings in a Signal (Counting Oscillations)
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Fawad Farooq Ashraf
el 10 de Oct. de 2022
Comentada: Fawad Farooq Ashraf
el 11 de Oct. de 2022
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?
0 comentarios
Respuestas (1)
Allen
el 10 de Oct. de 2022
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)));
Ver también
Categorías
Más información sobre Sources en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!