Tjaz Brelih Tjaz Brelih - 1 year ago 78
Python Question

Most accurate way to interpolate data and find the peak?

The data I have is always on a second degree polynomial (quadratic function). I want to find the peak of the interpolated function as accurately as possible.

Data sample points

So far I've been using

and then extract the peak value using
and a simple
loop. Although you can use a large number of newly generated samples in
you can still be more precise using the derivative of the fitted polynomial.
I haven't found a way to do that using

Now the only function I've found that returns the fitted polynomial coefficients is
, but this fitted function is quite inaccurate (most of the time the function doesn't even go through the data points).

<code>interp1d</code> and <code>polyfit</code> functions

I've tried using
and the fitted function seems to be quite accurate and it's very simple to get the derivative spline and its root.

Other polynomial fitting functions (
, ...) state that they are not computing polynomial coefficients for reasons of numerical stability.

How accurate is
and its derivatives, or are there any better options out there?

Answer Source

In the end I went with polyfit. Although the fitted function didn't go exactly through the data points the end result was still good. From the returned coefficients I got the desired x and y coordinates of the peak.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download