% This function is part of the NMSM Pipeline, see file for full license.
%
% This function calculates the single support time for the specified foot
% for one gait cycle.
%
% (Array of number, Array of number) -> (Number)
%
function singleSupportTime = calcSingleSupportTime(normalForce, time)
normalForce = normalForce - 30; % Noise buffer
normalForce(normalForce<0) = 0;
slope = diff(normalForce);
heelStrikeEvent = getHeelStrikeEvent(slope);
toeOffEvent = getToeOffEvent(slope);
if isempty(heelStrikeEvent)
if normalForce(1) == 0
heelStrikeEvent = 1;
end
end
singleSupportTime = [];
if toeOffEvent < heelStrikeEvent
singleSupportTime = time(heelStrikeEvent) - time(toeOffEvent);
end
if toeOffEvent > heelStrikeEvent
singleSupportTime = (time(end) - time(toeOffEvent)) + time(heelStrikeEvent);
end
if isempty(singleSupportTime)
singleSupportTime = 0;
end
end