Skip to main content

calcBSplineDerivative.m


% This function is part of the NMSM Pipeline, see file for full license.
%
% This function uses BSplines to calculate the derivative of
% each column and returns an array of the same shape as provided.
%
% (double array, 2D double array, integer, integer) => (2D array of double)
% Returns the derivative of each column provided


function derivative = calcBSplineDerivative(time, data, degree, numNodes)
if ~((length(time)==size(data, 2))||(length(time)==size(data, 1)))
error("time and data arrays are not of correct shape.");
end

numPts = length(time);
interval = time(2)-time(1);
[N, Np, ~] = BSplineMatrices(degree,numNodes,numPts,interval);

newData = data;
if length(time)==size(newData, 2)
newData = newData';
end

Nodes = N\newData;
derivative = Np*Nodes;

if size(data, 1)~=size(derivative, 1)
derivative = derivative';
end

end