0
$\begingroup$

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

About the signal:

  • 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()?

$\endgroup$

1 Answer 1

1
$\begingroup$

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

That sounds like the best approach. Use the initial interpolation to "straighten out" the sampling grid, i.e. you should interpolate so that the grid is uniform but has roughly the same amount of samples than the original. I would go with a cubic spline for that.

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.