Search code examples
pythonnumpyscipysample-datasample-rate

Resampling data from 1280 Hz to 240 Hz in python


I have a python list of force data that was sampled at 1280 Hz, I have to get it do exactly 240 Hz in order to match it exactly with a video that was filmed at 240 Hz. I was thinking about downsampling to 160 Hz and then upsampling through interpolation to 240 Hz. Does anyone have any ideas on how to go about doing this? Exact answers not needed, just an idea of where to look to find out how.


Solution

  • Don't downsample and that upsample again; that would lead to unnecessary information loss.

    Use np.fft.rfft for a discrete Fourier transform; zero-pad in the frequency domain so that you oversample 3x to a sampling frequency of 3840 Hz. (Keep in mind that rfft will return an odd number of frequencies for an even number of input samples.) You can apply a low-pass filter in the frequency domain, making sure you block everything at or above 120 Hz (the Nyqvist frequency for 240 Hz sampling rate). Now use np.fft.irfft to transform back to a time-domain signal at 3840 Hz sampling rate. Because 240 Hz is exactly 16x lower than 3840 Hz and because the low-pass filter guarantees that there is no content above the Nyqvist frequency, you can safely take every 16th sample.