Skip to main content

createMuscleTendonVelocity.m


% This function is part of the NMSM Pipeline, see file for full license.
%
% This function runs fmincon for MuscleTendonPersonalization with settings
% controlled by the input params.
%
% (string) -> (None)
% returns the optimized values from Muscle Tendon optimization round


function createMuscleTendonVelocity(muscleTendonLengthFileName, ...
cutoffFrequency)
storage = org.opensim.modeling.Storage(muscleTendonLengthFileName);
lengthData = storageToDoubleMatrix(storage);
time = findTimeColumn(storage);
isLongFile = length(time) > 200;

if isLongFile
numNodes = splFitWithCutoff(time(1:200), lengthData(:, 1:200), ...
cutoffFrequency, 4);
numNodes = numNodes * length(time) / 200;
else
numNodes = splFitWithCutoff(time, lengthData, cutoffFrequency, 4);
end
velocityData = calcBSplineDerivative(time, lengthData, 4, numNodes);

[filepath, name, ext] = fileparts(muscleTendonLengthFileName);
name = strrep(name, "_Length", "");
writeToSto(getStorageColumnNames(storage), time, velocityData', ...
fullfile(filepath, strcat(name, "_Velocity", ext)));

end