%% Duty Cycle of Bilevel Waveform with Three Pulses
% 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.

load('pulseex.mat','x')
fs = 4e6;

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

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

%
% 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')

% Copyright 2012 The MathWorks, Inc.