How to uniformly resample a non-uniform signal using SciPy? How to uniformly resample a non-uniform signal using SciPy? python-3.x python-3.x

How to uniformly resample a non-uniform signal using SciPy?


Please look at this rough solution:

import matplotlib.pyplot as pltfrom scipy import interpolateimport numpy as npx = np.array([0.001, 0.002, 0.005, 0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1, 2, 5, 10, 20])y = np.exp(-x/3.0)flinear = interpolate.interp1d(x, y)fcubic = interpolate.interp1d(x, y, kind='cubic')xnew = np.arange(0.001, 20, 1)ylinear = flinear(xnew)ycubic = fcubic(xnew)plt.plot(x, y, 'X', xnew, ylinear, 'x', xnew, ycubic, 'o')plt.show()

That is a bit updated example from scipy page. If you execute it, you should see something like this:enter image description here

Blue crosses are initial function, your signal with non uniform sampling distribution. And there are two results - orange x - representing linear interpolation, and green dots - cubic interpolation. Question is which option you prefer? Personally I don't like both of them, that is why I usually took 4 points and interpolate between them, then another points... to have cubic interpolation without that strange ups. That is much more work, and also I can't see doing it with scipy, so it will be slow. That is why I've asked about size of the data.