%% Width, Period, and Duty Cycle
% Note: If you are using R2016a or an earlier release, replace each call to the object with the equivalent step syntax. For example, obj(x) becomes step(obj,x).
% Determine the width, period, and duty cycle of a 5 V pulse sampled at 4 MHz.

 load('pulseex.mat','x','t');

%
% Construct the dsp.PulseMetrics object. Set the TimeInputPort property to true to specify the sampling instants as an input. Set the CycleOutputPort property to true to obtain metrics for each pulse. Because the input is a 5 V pulse, set the StateLevels property to [0 5].

 pm = dsp.PulseMetrics('TimeInputPort',true, ...
                            'CycleOutputPort', true, ...
                            'StateLevels',[0 5])

%
% Call the object to compute the cycle metrics and plot the result.

 [pulse,cycle] = pm(x,t);   
 plot(pm) 
 text(t(2),-0.5,['Duty Cycle: ',num2str(cycle.DutyCycle)]);

% Copyright 2012 The MathWorks, Inc.