Taking derivative of discrete data requires some fitting and then using the b-form of the polynomial.
How to make a 'good' fit and properly take derivative? I am confused what is the right behavior of the derivative. Things change quite rapidly with small adjustments of the fitting csaps coefficient 0.09 in the example below.
The test.txt data is attached. Test data test.txt click
Matlab code.
T = load('test.txt'); x = T(:,1); y=T(:,2)
pp22 = csaps(x,y,0.09);%attempt to create 'good' fit in b-form. ... Notworking as intended
pp22val = ppval(pp22,x);
figure(1012)
plot(x,pp22val,x,y) %quality of the fit
p_der202 = fnder(pp22,2); % second derivative
y_prime22 = ppval(p_der202,x); % values
figure(101)
plot(x,y_prime22) %second derivative
% test discrete centered derivative
for i = 4:length(x)-4
prime23(i) = (-y(i+2)+16*y(i+1)-30*y(i)+16*y(i-1)-y(i-2))/(12*((x(i+1)-x(i))^2));
end
figure(102)
plot(x(2:length(x)-3),prime23)
Data and fit
Matlab fnder
Discrete centered



Splines tend to consider that control points are not noisy, they can induce some overshoot. Since your time sampling is almost regular, I would suggest to keep the denominator constant (median oof the differences). Plus, your data looks very smooth. Resultingly, you can use a lot of standard linear filtering tools. To name a few:
Matlabundersgolayfiltandsgolay, which give you access to the derivatives quite directly.The last two options seem appropriate to me. What is important the the choice of the scale under which the derivatives are meaningful.
I did a try, adapting Matlab code. On its right end, the derivative seems blocky (piecewise constant), suggesting a close to piecewise linear signal, hence the peaks in your second derivative. You will have to play with parameters.