Simulink - How to extract the time when the signal is on?
8 ビュー (過去 30 日間)
古いコメントを表示
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
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?
回答 (2 件)
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
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.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!