% This function is part of the NMSM Pipeline, see file for full license.
%
% Penalize differences in EMGScales and electromechanical time delay
% differences between grouped muscles
%
% (struct, cell array, array of number, array of number, struct) -> (struct)
% calculates the cost of differences between grouped muscles
function cost = calcGroupedMusclePenalties(valuesStruct, ...
activationGroups, errorCenters, maxAllowableErrors, cost)
% Penalize violation of EMGScales similarity between grouped muscles
deviationsEMGScale = calcDifferencesInEmgGroups(findCorrectMtpValues(4, ...
valuesStruct) , activationGroups);
cost.emgScaleGroupedSimilarity = calcDeviationCostTerm( ...
deviationsEMGScale, errorCenters(9), maxAllowableErrors(9));
% Penalize violation of tdelay similarity between grouped muscles
if size(findCorrectMtpValues(1, valuesStruct), 2) > 2
deviationsTdelay = calcDifferencesInEmgGroups(findCorrectMtpValues(1, ...
valuesStruct) / 10, activationGroups);
cost.tdelayGroupedSimilarity = calcDeviationCostTerm( ...
deviationsTdelay, errorCenters(10), maxAllowableErrors(10));
else
cost.tdelayGroupedSimilarity = 0;
end
end