# Python: Resample without equal

I would like to resample (downsample) a signal using python in order to get an even spacing and fill gaps.

• It consists of a vector for y (amplitude) and x (timestamps)
• Very slow; $$F_s$$ is probably >100 times higher than needed (for the desired content; steps and noise are present)
• The samples aren't exactly equally spaced
• The signal has gaps with missing samples
• The signal is not periodic (FFT resampling should be fine though, I can trim off beginning and end)
• It doesn't really matter how the gaps are filled, a linear interpolation would do

In matlab could likely just use y = resample(x,tx,fs) , however, scipy.signal.resample() can take a vector for x but still doesn't work for signals with non-uniform spacing.

It is probably a bad idea to use scipy.interpolate.interp1d() for filling gaps and downsampling in one step because of aliasing. Filtering before interpolating is likely not a good idea either, since the discrete filters wouldn't work with a non-uniform spacing of the samples.

Should I first interpolate() to the approximate sample frequency and then downsample using resample()?

If you interpolate to a grid that is an integer multiple of your target sample rate, you don't need to call resample() You can just run a lowpass filter and throw away the extra samples. That lowpass filtering will also remove a lot of the noise and the interpolation artifacts. resample() does the same thing, but by doing the lowpass manually, you have much better control over the process.