Skip to main content

createMuscleSpecificSurrogateModel.m


% This function is part of the NMSM Pipeline, see file for full license.
%
% This function fits muscle tendon lengths and moment arms as a
% function of joint angles
%
% Inputs:
% jointAngles (numberFrames x degreesOfFreedom)
% muscleTendonLengths (numberFrames x 1)
% momentArms (numberFrames x degreesOfFreedom)
% polynomialDegree (value)
%
% (2D Number matrix, Number array, 2D Number matrix, Number) ->
% (Symbol array, 2D Symbol array, Number array)
%
% returns muscle-specific polynomial expressions with corresponding
% coefficients that best fit experimental muscle tendon lengths and
% moment arms.

% -----------------------------------------------------------------------

function [polynomialExpressionMuscleTendonLengths, ...
polynomialExpressionMuscleTendonVelocties, ...
polynomialExpressionMomentArms, coefficients] = ...
createMuscleSpecificSurrogateModel(jointAngles, ...
muscleTendonLengths, momentArms, polynomialDegree)

% Get polynomial expressions for muscle tendon length and moment arms
[polynomialExpressionMuscleTendonLengths, ...
polynomialExpressionMuscleTendonVelocties, ...
polynomialExpressionMomentArms, theta] = ...
getPolynomialExpressions(jointAngles, polynomialDegree);
% Get A matrix
matrix = getDataMatrix(polynomialExpressionMuscleTendonLengths, ...
polynomialExpressionMomentArms, jointAngles, theta);
% Create b vector
vector = cat(1, muscleTendonLengths, reshape(momentArms, [], 1));
% Calculate coefficients using linear least squares regression
coefficients = matrix \ vector;
end