frequency mesurement of a square wave
조회 수: 14 (최근 30일)
이전 댓글 표시
hi I want to to measure the frequency of a square wave with simulink , do anybody know how to do this? thanks
댓글 수: 0
채택된 답변
Image Analyst
2015년 2월 22일
편집: Image Analyst
2015년 2월 22일
I don't have Simulink but I think you can use a MATLAB block in it where you run MATLAB code. If so, then just threshold the signal and use find()
signal = [0 0 6 6 6 0 0 6 6 6 0 0 6 6 6 0 0]
halfMaxValue = 0.5 * (min(signal) + max(signal)) % Halfway between 0 and 6.
highSignals = signal > halfMaxValue
diffSignal = [0 diff(highSignals)]
diffSignalIndexes = find(diffSignal == 1)
period = diffSignalIndexes(2) - diffSignalIndexes(1) % Distance between first two pulses.
In the command window:
halfMaxValue =
3
highSignals =
0 0 1 1 1 0 0 1 1 1 0 0 1 1 1 0 0
diffSignal =
0 0 1 0 0 -1 0 1 0 0 -1 0 1 0 0 -1 0
diffSignalIndexes =
3 8 13
period =
5
댓글 수: 9
Image Analyst
2015년 2월 24일
Your signal doesn't quite look right. The plot seems to show it going high around element 43 or 44 but your signal variable shows it going up around element 42.
추가 답변 (1개)
MoeIsKing
2018년 6월 24일
편집: Image Analyst
2018년 6월 24일
If i run:
highSignals = signal > halfMaxValue
over my signal i get:
"Error using horzcat
Dimensions of arrays being concatenated are not consistent."
What did i wrong? My "highSignals" type is "2002x1 logical" after I run:
highSignals = volts > halfMaxValue ;
halfMaxValue is 12 and volts comes from a scope (light bar) and is imported as csv into "2002x1 double"
댓글 수: 1
Image Analyst
2018년 6월 24일
It looks OK to me. What I don't understand is how you could execute the line to create highSignals successfully as a 2002 by 1 vector, and yet still have an error thrown? In my experience if an error is thrown, you will not get the result put into the output variable. Can you explain that? Exactly what line of code are you executing when the error is thrown?
참고 항목
카테고리
Help Center 및 File Exchange에서 Sources에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!