Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Window size for savitzky golay filter #6

Open
lexiiizhou opened this issue Jan 3, 2021 · 1 comment
Open

Window size for savitzky golay filter #6

lexiiizhou opened this issue Jan 3, 2021 · 1 comment

Comments

@lexiiizhou
Copy link

lexiiizhou commented Jan 3, 2021

What was the reasoning for using a window size of 25 when smoothing coordinates and in general for this type of data what is the best way to decide what parameters to use? Does it by any chance depend on frame rate?

Thanks!

@talmo
Copy link
Member

talmo commented Jan 4, 2021

Hi @lexiiizhou,

That was really just an example -- you can do whatever smoothing you'd like (or none at all) depending on the nature of your analysis.

A window size of 25 is pretty big; as a rule of thumb, you want the smallest window that will still eliminate the majority of artifacts that you want to eliminate. Larger window sizes will give you fewer artifacts but make it harder to retain fast motions, whereas smaller window sizes may not suffice to get rid of your artifacts and may even introduce new ones.

If the framerate of your video is low or the animal moves quickly, a large window size may get rid of real biological signal. A small window size may overfit the interpolation kernel to noise, especially if artifacts (like tracking errors) occur over multiple frames.

Ultimately it's something you'll have to experiment with yourself for the issues present in your own data. My recommendations are:

  • To get rid of sharp 1-2 frame jumps, use a median filter with a small window (5-7).
  • To get rid of small jumps, use a Savitzky Golay filter with a slightly larger window (7-15) and relatively low degree (4-8).
  • To get rid of discretization artifacts or high frequency/small magnitude errors, first try a Gaussian filter with small sigma (1-2) or moving average filter with small window size (3-7). If that doesn't work well, try the Savitzky Golay filter.

Let me know if that makes sense or if you have any other questions. Cheers!

Talmo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants