% This function is part of the NMSM Pipeline, see file for full license.
%
% This function calculates the model normalized muscle fiber lengths and
% velocities
%
% Inputs:
% In the experimentalData struct:
% muscleTendonLength - 3d mat (numFrames, numTrials, numMuscles)
% muscleTendonVelocity - 3D mat (numFrames, numTrials, numMuscles)
% vMaxFactor - number
% pennationAngle - 3D mat (1, 1, numMuscles)
% optimalFiberLength - 3D mat (1, 1, numMuscles)
% tendonSlackLength - 3D mat (1, 1, numMuscles)
%
% Other inputs:
% optimalFiberLengthScaleFactors - 3D mat (1, 1, numMuscles)
% tendonSlackLengthScaleFactors - 3D mat (1, 1, numMuscles)
%
% Outputs:
% normalizedFiberLengths - 3D mat (numFrames, numTrials, numMuscles)
% normalizedFiberVelocities - 3D mat (numFrames, numTrials, numMuscles)
%
% (struct, num array, num array) => (3D num array, 3D num array)
% returns computed muscle fiber lengths and velocities with scale factor
function [normalizedFiberLengths, normalizedFiberVelocities] = ...
calcNormalizedMuscleFiberLengthsAndVelocities(experimentalData, ...
optimalFiberLengthScaleFactors, tendonSlackLengthScaleFactors)
scaledOptimalFiberLength = experimentalData.optimalFiberLength .* ...
optimalFiberLengthScaleFactors;
scaledTendonSlackLength = experimentalData.tendonSlackLength .* ...
tendonSlackLengthScaleFactors;
% Normalized muscle fiber length, equation 2 from Meyer 2017
if isfield(experimentalData, 'muscleTendonLength')
normalizedFiberLengths = (experimentalData.muscleTendonLength - ...
scaledTendonSlackLength) ./ (scaledOptimalFiberLength .* ...
cos(experimentalData.pennationAngle));
else
normalizedFiberLengths = [];
end
% Normalized muscle fiber velocity, equation 3 from Meyer 2017
if isfield(experimentalData, 'muscleTendonVelocity')
normalizedFiberVelocities = (experimentalData.muscleTendonVelocity) ./ ...
(experimentalData.vMaxFactor .* scaledOptimalFiberLength .* ...
cos(experimentalData.pennationAngle));
else
normalizedFiberVelocities = [];
end
end