Question

I've looked into smoothing of a signal and found the Cookbook page http://wiki.scipy.org/Cookbook/SignalSmooth which works fine for an array with only one dimension. Now I would really need a function that does the same thing but on an (TxNx3) array along the N axis.

The context is, that I have a trajectory of N particles and T frames each with x,y,z and now I would like to implement some sort of low pass filter on their movements in time to make the wiggle less in a movie.

So to illustarte the problem:

import numpy as np
from MY_Cookbook_copy import smooth
T = np.random.random((30,30,3)) # this is the trajectory
imshow( T[:,:,0], interpolation='nearest' ) 

original trajectory

# this works but is too slow and only for the x data
for i in range( T.shape[1] ):
    T[:,i,0] = smooth( T[:,i,0], 5 )
imshow( T[:,:,1], interpolation='nearest' )

this gives smoothed trajectory

so dimensions of my problem are on the order of something like 1000 particles over 5000 time frames

Was it helpful?

Solution

You could try a multi-dimensional Gaussian filter - http://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.filters.gaussian_filter.html

Applying a Gaussian filter would smooth the signal and you can apply it to in multiple dimensions through setting the sigma as a tuple so you can have different amount of smoothing in each axis. I guess you only want to smooth the x, y, z values over time, so you can try using a sigma of (2, 0, 0) perhaps, although I'm not entirely clear on your data setup. The sigma controls the width of the Gaussian filter, so if you want to smooth very locally, then use a small sigma. You may need to experiment a little to find the level of smoothing that you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top