필터 지우기
필터 지우기

Timer Implementation In Simulink

조회 수: 6 (최근 30일)
Kaushik
Kaushik 2011년 10월 11일
Hi, I need to implement a timer in simulink. The timer will have a square wave signal at its input with varying pulse width. What I want is, it should save the data in workspace in a 2-D Array format, with first column showing number of pulses and second column containing the respective time duration of the pulse. How can I implement it?

채택된 답변

Fangjun Jiang
Fangjun Jiang 2011년 10월 11일
It might be easier if done in MATLAB. You want the result in MATLAB base workspace anyway. a is your input pulse, Out is the result, here time is assumed to be 1,2,3,...
a=[0 0 1 1 0 1 1 1 1 1 0 0 1 1 1 0];
df=diff([0 a 0]);
b=find(df==1);
c=find(df==-1);
e=c-b;
Out=[b;e]';
  댓글 수: 7
Fangjun Jiang
Fangjun Jiang 2011년 10월 14일
Then the code in my answer provided the solution, right? Right now, the first column is the time stamp of the rising edge. If you want the count of the pulse, change the last line to be: Out=[1:length(b);e]'
Kaushik
Kaushik 2011년 10월 15일
Yes, the code serves the purpose. I even multiplied the time period obtained by the method of '1's and '-1's by the sampling time, to get the actual time period. As my model runs on different sampling rate, i had to multiply the acquired time by the sampling time to get the actual answer...:) I'll also try ur suggestion in last comment...
Thanks again...

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

추가 답변 (0개)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by