%% Count the Rising Edges
% Note: This example runs only in R2016b or later. If you are using an earlier release, replace each call to the function with the equivalent step syntax. For example, myObject(x) becomes step(myObject,x).
% Use dsp.Counter System object™ to count at every rising edge of the input signal.

count = dsp.Counter('MaximumCount', 5, ...
    'CountOutputPort', true, ...
    'HitOutputPort', false, ...
    'ResetInputPort', false);
sgnl = [0 1 0 1 0 1 0 1 0 1 0 1 ];
cnt = zeros(1,12);
for ii = 1:length(sgnl)
    cnt(ii) = count(sgnl(ii));
end
disp(cnt);

% Copyright 2012 The MathWorks, Inc.