Simulink - How to extract the time when the signal is on?
8 views (last 30 days)
Show older comments
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 Comments
madhan ravi
on 26 Nov 2023
Edited: madhan ravi
on 26 Nov 2023
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?
Answers (2)
Sulaymon Eshkabilov
on 26 Nov 2023
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
on 27 Nov 2023
Edited: madhan ravi
on 27 Nov 2023
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 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!