필터 지우기
필터 지우기

How to calculate the duty cycle of a time signal in a for loop?

조회 수: 9 (최근 30일)
Susan
Susan 2023년 3월 14일
댓글: Susan 2023년 3월 16일
Hi All,
I have multiple time signals and like to compute their duty cycles automatically within a "for loop". For example the duty cycle of the following signal is 74.29%. The signal is attached and the sample rate is 15360000.
Assume I have a bunch of these signals. How can I calculate the ratio of the pulse width (duration of the on state) to the pulse period (the total duration of an on-and-off state) for each signal in a for loop?
Thanks in advance!

채택된 답변

Walter Roberson
Walter Roberson 2023년 3월 14일
load waveform
wr = real(waveform);
wi = imag(waveform);
subplot(2,1,1); plot(wr); ylabel('real');
subplot(2,1,2); plot(wi); ylabel('imag');
mr = movmedian(wr, 5);
mi = movmedian(wi, 5);
mean(abs(mr)<0.01) * 100
ans = 74.2301
mean(abs(mi)<0.01) * 100
ans = 74.4255
  댓글 수: 9
Walter Roberson
Walter Roberson 2023년 3월 15일
We can tell from the graphs that the only part of the signal this is "repeatable" is the zeros.
You can do things like
%newer file
load waveform
wr = real(waveform(:).');
wi = imag(waveform(:).');
maskr = abs(wr) < 1e-3;
stopsr = strfind([maskr 0], [1 1 0]) + 2;
mean(~maskr(stopsr(2):stopsr(end-1)-1)) * 100
ans = 77.2091
maski = abs(wr) < 1e-3;
stopsi = strfind([maski 0], [1 1 0]) + 2;
mean(~maski(stopsi(2):stopsi(end-1)-1)) * 100
ans = 77.2091
This measures for the signal starting from end of the second stretch of zeros (so skipping the first pulse). But you can see it made little difference (gave a lower duty cycle in fact.)
To go much beyond that you would need a more explicit definition of what should be skipped.
Susan
Susan 2023년 3월 16일
@Walter Roberson I see. Thanks again for your help. Appreciate it.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Pulse and Transition Metrics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by