[Tutor] Rate transition from 60hz to 1000hz

Oscar Benjamin oscar.j.benjamin at gmail.com
Tue May 10 11:18:40 EDT 2016


On 10 May 2016 at 04:08, David Wolfe <dkwolfe at gmail.com> wrote:
> Good Evening;
>
> I'm collecting both video and force plate data, and I need to be able to
> synchronize the two, so I can make some calculations.  The video data is at
> 60hz, and the force plate data is at 1000hz.  I don't want to truncate the
> force plate data.
>
> So, how do I perform a rate transition (or interpolation, or whatever) to
> expand the data that is captured at 60hz to be able to synchronize it with
> the data that has been captured at 1000hz?
>
> Also, if I'm not using the correct terms, please let me know.  I'm new to
> Python and programing, and I'm trying to learn as fast as i can.

The normal term for this is "resampling" and scipy has a function
called resample that does exactly this. Here's a demonstration:

>>> from scipy.signal import resample
>>> plate_signal = [1, 2, 1, 3, 1, 4, 2, 3, 4, 2]
>>> video_signal = [7, 8, 4]
>>> video_resampled = list(resample(video_signal, len(plate_signal)))
>>> video_resampled
[7.0000000000000009, 8.230109890796971, 8.735715605706849,
8.3236929465402536, 7.1514205649637077, 5.666666666666667,
4.4365567758696969, 3.9309510609598171, 4.3429737201264125,
5.5152461017029593]

This resamples the signal using interpolation. Notice that the last
samples of resample are increasing away from 4 (towards 7). This is
because resample uses a DFT-based method so it implicitly assumes that
the signal is periodic. This leads to a bit of distortion at the end
of your resampled signal - often that doesn't matter but it's worth
noticing.

You can read more about resample here:

http://docs.scipy.org/doc/scipy-0.16.0/reference/generated/scipy.signal.resample.html

I've added a list call because resample returns a numpy array. Do you
know what that is?

Presumably in your application video_signal is actually a 3D array
since at each frame you would have a 2D array of pixel values.
Resamples can handle this case too but exactly how to call it depends
on what sort of array you're using to store the video data.

I'm assuming here that you want to work offline. If you actually want
to do this computation online (as the data comes in) then you'd need
something different.

--
Oscar


More information about the Tutor mailing list