Simulink - How to extract the time when the signal is on?

7 ビュー (過去 30 日間)
Davide Cannavacciuolo
Davide Cannavacciuolo 2023 年 11 月 26 日
編集済み: madhan ravi 2023 年 11 月 27 日
Hello, have the yellow signal and I am trying to extract the time as a constant only when the yellow signal is on. I have found with a subsystem block how to activate extract the time, but it obiouvsly contiues growing.
Actually I need to extract as output the red time T I drew, so the condition is when the yellow signal is on, but to output the time only when the yellow signal goes off again to zero.
In this case, that the frequency is the same, i would expect something like this. between 0 and 1, lets also say anything is good, like 0. But if the frequency of the yellow signal changes, I expect the Ti value to be different, like:
In this case there an deccelleration so the frequency, decreases and the time increases
  4 件のコメント
madhan ravi
madhan ravi 2023 年 11 月 26 日
編集済み: madhan ravi 2023 年 11 月 26 日
Still not clear , what does the green and red lines represent?
ok, i think i understood. Since the frequency of the yellow signal is constant like your first picture in the question then the time fluctuates between 0 and 1 just like the yellow signal. But if the frequency of the yellow signal changes within the simulation like from 1hz from 1/2 hz the time increases twice. is that right?
Davide Cannavacciuolo
Davide Cannavacciuolo 2023 年 11 月 26 日
Yes exactly, the red signal represents possibly the first scope shown, the green show another case in where the frequency of the square way slowly decrease so also the on state is longer and so it is the output desired time.
More simply I need the time that mean a constant as output, that is exactly the time that the square wave is on. The hard part is to output this value only when the square wave is off, otherwise say it is zero.
Maybe a solution maybe to use a switch but still not sure how to make it.

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

回答 (2 件)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023 年 11 月 26 日
If understood correctly, you want to find out time signals when the response (output) values were non-zero, right?
If so, then simply collect/import/store simulation data in MATLAB workspace and then apply logical indexing, e.g.
fs = 1e3;
t = -.5:1/fs:2;
w1 = 240e-3;
x = rectpuls(t,w1);
t2 = -300e-3;
x2 = rectpuls(t+t2,2*w1/3);
t3 = -900e-3;
x3= rectpuls(t+t3,2*w1);
X_pulse = x+x2+x3;
plot(t, X_pulse, 'DisplayName','Data', 'LineWidth', 2)
ylim([0, 1.1])
IDX = find(X_pulse==1);
Time_nnz = t(IDX);
hold on
plot(Time_nnz, X_pulse(IDX), 'r*', 'DisplayName','None-zero points')
grid on
  1 件のコメント
Davide Cannavacciuolo
Davide Cannavacciuolo 2023 年 11 月 26 日
I don't understand this solution well. I need to find the time the yellow square wave is on as output. The frequency of the square wave may be variable. But a requirement is to output this value only when the square wave goes back to zero. This can be done with a switch I guess. The overall signal should look as a discrete output just I made with paint

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


madhan ravi
madhan ravi 2023 年 11 月 27 日
編集済み: madhan ravi 2023 年 11 月 27 日
So if your goal is to output a signal when the yellow signal is off.
You could simply use a not logical operator https://de.mathworks.com/help/simulink/slref/logicaloperator.html of the yellow signal and feed it to the scope.

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by