You are here : matlabSignal Processingdutycycle

dutycycle() - Signal Processing

```D = dutycycle(X) returns
the ratio of pulse width to pulse period for each positive-polarity
pulse. D has length equal to the number of pulse
periods in X. The sample instants of X correspond
to the indices of X. To determine the transitions
that define each pulse, dutycycle estimates the
state levels of the input waveform by a histogram method. dutycycle identifies
all regions, which cross the upper-state boundary of the low state
and the lower-state boundary of the high state. The low-state and
high-state boundaries are expressed as the state level plus or minus
a multiple of the difference between the state levels. See State-Level Tolerances.D = dutycycle(X,FS) specifies
the sampling frequency, FS, in hertz as a positive
scalar. The first sample instant of X corresponds
to t=0.D = dutycycle(X,T)
specifies the sample instants, T, as a vector
with the same number of elements as X. D = dutycycle(TAU,PRF) returns
the ratio of pulse width to pulse period for a pulse width of TAU seconds
and a pulse repetition frequency of PRF. The
product of TAU and PRF must
be less than or equal to 1.[D,INITCROSS]
= dutycycle(X,...) returns a vector, INITCROSS,
whose elements correspond to the mid-crossings (mid-reference level
instants) of the initial transition of each pulse with a corresponding NEXTCROSS.[D,INITCROSS,FINALCROSS]
= dutycycle(X,...)  returns a vector, FINALCROSS,
whose elements correspond to the mid-crossings (mid-reference level
instants) of the final transition of each pulse with a corresponding NEXTCROSS.[D,INITCROSS,FINALCROSS,NEXTCROSS]
= dutycycle(X,...)  returns a vector, NEXTCROSS,
whose elements correspond to the mid-crossings (mid-reference level
instants) of the next detected transition for each pulse.[D,INITCROSS,FINALCROSS,NEXTCROSS,MIDLEV]
= dutycycle(X,...)   returns the mid-reference
level, MIDLEV. Because in a bilevel pulse waveform
the state levels are constant, MIDLEV is a scalar.[D,INITCROSS,FINALCROSS,NEXTCROSS]
= dutycycle(X,...,Name,Value) returns
the ratio of pulse width to pulse period with additional options specified
by one or more Name,Value pair arguments.dutycycle(X,...)
plots the waveform, X, and marks the location
of the mid-reference level instants and the associated reference levels.
The state levels and associated lower and upper state boundaries are
also plotted.```

Syntax

```D = dutycycle(X)D = dutycycle(X,FS)D = dutycycle(X,T)D = dutycycle(TAU,PRF)[D,INITCROSS]
= dutycycle(X,...)[D,INITCROSS,FINALCROSS]
= dutycycle(X,...)[D,INITCROSS,FINALCROSS,NEXTCROSS]
= dutycycle(X,...)[D,INITCROSS,FINALCROSS,NEXTCROSS,MIDLEV]
= dutycycle(X,...)[D,INITCROSS,FINALCROSS,NEXTCROSS]
= dutycycle(X,...,Name,Value)dutycycle(X,...)```

Example

```Duty Cycle of Bilevel WaveformOpen This Example
Determine the duty cycle of a bilevel waveform. Use the vector indices as the sample instants.

d = dutycycle(x)

d =

0.3001

Annotate the result on a plot of the waveform.dutycycle(x);

Duty Cycle of Bilevel Waveform with Sample RateOpen This Example
Determine the duty cycle of a bilevel waveform. The sample rate is 4 MHz.
fs = 1/(t(2)-t(1));

d = dutycycle(x,fs)

d =

0.3001

Annotate the result on a plot of the waveform.dutycycle(x,fs);

Duty Cycle of Bilevel Waveform with Three PulsesOpen This Example
Create a pulse waveform with three pulses. The sample rate is 4 MHz. Determine the initial and final mid-reference level instants. Plot the result.
fs = 4e6;

pulse = x(1:30);
wavef = [pulse;pulse;pulse];
t = (0:length(wavef)-1)/fs;

[~,initcross,finalcross,~,midlev] = dutycycle(wavef,t)

initcross =

1.0e-04 *

0.0312
0.1062

finalcross =

1.0e-04 *

0.0463
0.1213

midlev =

2.5177

Even though there are three pulses, only two pulses have corresponding subsequent transitions. Plot the result.plot(t,wavef)
hold on
plot([initcross finalcross],midlev*ones(2),'x','markersize',10)
hold off
legend('Waveform','Initial','Final','Location','best');```