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

조회 수: 5 (최근 30일)
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이전 댓글 2개 표시이전 댓글 2개 숨기기
편집: 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 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 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이전 댓글 -1개 표시이전 댓글 -1개 숨기기
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 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.

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Signal Generation에 대해 자세히 알아보기

R2023b

### Community Treasure Hunt

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

Start Hunting!

Translated by