이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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)
