% FIVEPOINTDERIVATIVE - take the 5 point derivative of the data
% function [vel,accel] = fivepointderivative(height,dt)

function [vel,accel] = fivepointderivative(height,dt)

    x_minus_2h = [height(1);height(1);height(1:end-2)];
    x_minus_h  = [height(1);height(1:end-1)];
    x = height;
    x_plus_h   = [height(2:end);height(end)];
    x_plus_2h =  [height(3:end);height(end);height(end)];

    vel = (-x_plus_2h + 8*x_plus_h - 8*x_minus_h + x_minus_2h) / (12*(dt));
    if nargout>1
        accel = (-x_plus_2h + 16*x_plus_h - 30*x + 16*x_minus_h - x_minus_2h) / (12*(dt)^2);
    end
end
