I have a dataset consisting of x and y arrays plotted as f(x)=y When I calculate the derivative of f(x), I get a noisy derivative as shown in the attached image. How can I smooth it out using python?
Asked
Active
Viewed 1,432 times
2
-
Are the pictures pictures of the function itself along with the nth derivatives of it, or just derivatives of different functions? I think the first thing I would do might be just to get rid of any data that are outliers and maybe this will smooth things out, need more details though I think. – Richard K Yu Dec 26 '21 at 21:00
1 Answers
2
It seems like they're different ways to smooth out data in general. This post looks like it has a similar question: Gradient in noisy data, python
One of the answer uses the function splev and splerp from scipy to smooth the curve. Here's that response: https://stackoverflow.com/a/19796063/13297560 Here are the lines of code that looks relevant:
from scipy.interpolate import splrep, splev
f = splrep(x, noisy_data, k=5, s=3)
plt.plot(x, splev(x,f), label="fitted")
it seems x is the range of the domain, noisy_data the output (y) and k and s are optional arguments that affect the smooth. Here's the documentation on that: https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.splrep.html