現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
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
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 件のコメント
Kaushik
2011 年 10 月 12 日
Hi Fangjun,
Thanks for the help. It helped in understanding the method. I'll try to implement a model with this logic.
Can you suggest a block similar to 'find' in simulink. The output of compare to constant is '1' when it detects the required constant. But I need the instance at which a '1' or a '-1' is found...
Fangjun Jiang
2011 年 10 月 12 日
Simulink has a triggered subsystem block. The trigger can be rising edge or falling edge. So you can use the pulse as the trigger signal, put a counter inside the subsystem and it will count how many pulses. The pulse duration is a little tricky. You'll probably need an integrator block. The rising edge starts the integration. the falling edge re-sets the integration. That will give you a saw-tooth type of output indicating the duration of the pulse. It contains enough information about the pulse but not exactly the format you wanted. You'll still need to do post-processing.
That is the difference between MATLAB and Simulink. In MATLAB, you have all the pulse information at once, all you do is kind of post-processing. You can get the pulse count and pulse duration at once. In Simulink, the algorithm runs as the time goes, at a particular point of time, you don't know whether the pulse is going to last for 1 second or 10 second because you don't see the falling edge yet.
So think about your use case and pick the right approach.
Kaushik
2011 年 10 月 13 日
Thanks again Fangjun,
I tried the part of what you suggested previously. The suggestion to use integrator is very useful. I was not sure about if you can get the entire job done in alone Simulink, thanks to your answer that confirms I'll have to take help of MATLAB scripting, as I'm doing rt nw. Thanks again!!!
Fangjun Jiang
2011 年 10 月 13 日
There is another way to do it, using the Clock block and two triggered subsystem. Inside the subsystem triggered by the rising edge, write the clock time to a DataStoreWrite block. Inside the subsystem triggered by the falling edge, subtract the clock time with the value from a DataStoreRead block with the same tag. The output will be the pulse duration, but not in a discrete format, as the interim values are all filled with the previous duration value.
Kaushik
2011 年 10 月 14 日
yeah, dats true. I think to get the required results, i'll have to take help of MATLAB script. Because, with simulink, I'm getting the signals at its output, but not in proper format - two dimensional array, with 1st column as number of pulses and second column as the duration of each pulse.
Thanks for all the help and suggestions... :)
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
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 件)
カテゴリ
ヘルプ センター および File Exchange で Simulink についてさらに検索
製品
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
