Effacer les filtres
Effacer les filtres

Timer Implementation In Simulink

6 vues (au cours des 30 derniers jours)
Kaushik
Kaushik le 11 Oct 2011
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?

Réponse acceptée

Fangjun Jiang
Fangjun Jiang le 11 Oct 2011
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 commentaires
Fangjun Jiang
Fangjun Jiang le 14 Oct 2011
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 le 15 Oct 2011
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...

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by