Timer Implementation In Simulink

6 次查看(过去 30 天)
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