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

Lowpass Filter Improved Uniform Sampling Check #3978

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

alexbeattie42
Copy link
Contributor

@alexbeattie42 alexbeattie42 commented Nov 27, 2024

Fixes issue #3968

Brief summary of changes

Implement an isUniform method to check if the vector is uniformly sampled. The implementation loosely follows the idea of the Matlab isUniform function. The implementation calculates the tolerance in this way:

isuniform verifies that the spacing between consecutive elements in numeric vector v does not deviate from the mean spacing by more than 4*eps(max(abs(v))), provided that the mean spacing is greater than that tolerance.

This may also fix this issue but I have not tested that myself yet.

Testing I've completed

Tested locally with this example and it fixes this issue. Will add unit tests soon.

Looking for feedback on...

@nickbianco and @aymanhab

  • do you have feedback on this method for checking the uniform sampling
  • where is the correct place for the uniform sampling check function to live. Maybe Signal?

CHANGELOG.md (choose one)

  • Will update when PR is ready

This change is Reviewable

Copy link
Member

@nickbianco nickbianco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work @alexbeattie42!

My main suggestion is to expose isUniform by adding it to CommonUtilities, with some documentation about how the uniformity checks work. You could then reference that in the updated documentation for TableUtilities::filterLowpass.

Reviewed 1 of 1 files at r1, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @alexbeattie42)


OpenSim/Common/TableUtilities.cpp line 126 at r1 (raw file):

template <typename T>
std::pair<bool,T> isUniform(const std::vector<T>& x) {

I think this would be a nice addition to CommonUtilities, as it might be useful for other table manipulation tools in OpenSim.


OpenSim/Common/TableUtilities.cpp line 189 at r1 (raw file):

    // Resample if the sampling interval is not uniform.
    if (!uniformlySampled) {

Could you add some documentation in the header file describing the conditions under which a table will be resampled?

@alexbeattie42 alexbeattie42 marked this pull request as ready for review December 5, 2024 08:00
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

Successfully merging this pull request may close these issues.

[Bug] Low Pass Filtering of Time IIR filter triggers a resample even if file is uniformly sampled
2 participants