Simulink - How to extract the time when the signal is on?
9 次查看(过去 30 天)
显示 更早的评论
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1552517/image.png)
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. ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1552522/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1552522/image.png)
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1552557/image.png)
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1552562/image.png)
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!