Skip to main content

calcEmgDataWithMuscleSpecificTimeDelay.m


% This function is part of the NMSM Pipeline, see file for full license.
%
% This function takes a 2D array (time) containing the time data for each
% (trial, time point), a 2D Cell Array of pp splines (spline(x,y)) of time
% and emg data, and a 1D array of number of the time delay for each muscle.
% It applies the time delay to the spline and returns the new segment of
% emg data for each unique trial and muscle combination.
%
% (2D Array of number, 2D Cell Array of pp, Array of number) ->
% (3D Array of number)
% returns new emg data after applying the muscle specific time delay


function emg = calcEmgDataWithMuscleSpecificTimeDelay(time, ...
emgSplines, timeDelay)
timeIntervalInterp = linspace(0, 1, size(time, 2))';
emg = zeros(size(emgSplines, 1), size(emgSplines, 2), size(time, 2));
for trial = 1:size(emgSplines, 1)
for muscle = 1:size(emgSplines, 2)
interpTime = ((time(trial, end) - time(trial, 1)) * ...
timeIntervalInterp + time(trial, 1));
emg(trial, muscle, :) = ppval(interpTime - timeDelay(muscle), ...
emgSplines{trial, muscle})';
end
end
end