Skip to main content

calcEmgDataWithCommonTimeDelay.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 number for the time delay across all muscles.
% 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, number) -> (3D Array of number)
% returns new emg data after applying the same time delay to all muscles


function emg = calcEmgDataWithCommonTimeDelay(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)
interpTime = ((time(trial, end) - time(trial, 1)) * ...
timeIntervalInterp + time(trial, 1));
emg(trial, :, :) = ppval(interpTime - timeDelay, ...
emgSplines{trial})';
end
end