I have some experimental data and I need to do a derivative. I looked at various answers how to approach that at e.g. here. But I am not happy with them (the curve is not smooth as needed plus the process is somewhat a black box, especially the part when one filters the data). I found another way to do a derivative that for the type of data that I have works quite well. The process is as follows:
- Pick a point ($x_0$) on the curve of the experimental data and then select $\Delta n$ points before this point and $\Delta n$ points following this point.
- Fit the selected points with a straight line
- Take its slope as the derivative in the originally selected point $x_0$
- Do for all the points on the curve.
The width of the window $\Delta n$ controls the "level" of smoothing.
The implementation in Mathematica is as follows:
\[CapitalDelta]n = 100; (* this is to provide the correct range on the x-axis *) n = Range[\[CapitalDelta]n + 1, Length@data - (\[CapitalDelta]n + 1)]; (* list of ranges where we will fit the line *) nrng = Range[n - \[CapitalDelta]n, n + \[CapitalDelta]n, 1]; (* get the slope *) slope = Fit[Transpose@{data[[#, 1]], data[[#, 4]]}, {1, x}, x, "BestFitParameters"][[2]] & /@ nrng; (* construct pairs of (x, y'(x)) *) der = Transpose@{data[[n, 1]], -slope}; Is there a way to make this faster? The dataset that I am using is on Wolfram cloud:
data = CloudGet["https://www.wolframcloud.com/obj/cd96d10f-65a9-4504-8abd-\ f7dd6a2e4668"]; 


ListDresource function that implements the fitting approach to calculating numerical derivatives. You may find it interesting as well. $\endgroup$