Open alexbeattie42 opened 6 days ago
This seems to be related to this issue
Yes, your issue is likely the same one in #3287. Been meaning to fix this but it kept slipping my mind.
Just submitted a fix at https://github.com/opensim-org/opensim-core/pull/3969.
@alexbeattie42 the fix at #3969 has been merged. Let me know if that resolves this issue.
@nickbianco I have just tested the fix and it seems to have solved it. The only problem I am noticing now is that the first data point is removed from the output. So I think the trimming is chopping one too many elements off the result after filtering.
@alexbeattie42 thanks for reporting. My guess is that this issue related to how TimeSeriesTable
handles trimming. TimeSeriesTable::trim()
computes indices based on the initial and final time provided:
But getRowIndexAfterTime
or getRowIndexBeforeTime
might grab and index just after (or before) the index for the original time, e.g.,
It would be helpful to take a look at what's happening with your data. Willing to take a look? If not, I could try to give it a shot in the next day or two.
Thanks for the guidance! It looks like it is a floating point precision issue. The data that I am using starts with uniformly sampled decimal time points every 0.025 seconds.
After processing with the TabOpLowPassFilter
there are floating point precision errors in the time column. To me the expected behavior would be that the time column is unaltered since I do not want to resample the data.
I have determined the problem is that the filterLowpass
is deciding to resample the data here.
The SimTK docs say "If Real is double (the normal case) then Eps ~= 1e-16". The result of dtAvg - dtMin
is 8.20524e-15
which is larger than SimTK::Eps
(which is 2.22045e-16
on my machine).
So even though the file is already uniformly sampled, the code silently tries to resample it since the determined sampling rate error is 8.20524e-15 > 2.22045e-16
.
Manually searching for where 0 should be yields that the 0
time value is now -4.2543746303636e-12
.
Resulting data after filtering:
-4.2543746303636e-12 0.0001865179945371941 0.0003887022192010853 -0.4164435622503228 0 0.9499999999999995 0 -4.314427538659543e-05 -0.0005320962789695338 3.727403142175347e-05 -0.0001222092811723213 0.0003695697018353934 0.0001467928459787541 0 4.146433961397945e-05 0.0005071265137617322 4.021683694910552e-05 9.030277662670975e-05 -0.0003495102708057906 -0.000154909933621432 0 0 0 0
0.0249999999957371 0.001444431434548449 0.001321552278548245 -0.4167450479826717 0 0.9499999999999995 0 0.0006707204198965602 -0.002604717315420156 0.001594071484128392 -0.002647996736714108 0.001221114680527505 0.003172171719565231 0 -0.001598795396258941 0.00161591734612298 -0.006660622999522429 0.0001451134537261808 0.0009925676347088941 0.00288996565013442 0 0 0 0
0.04999999999572857 0.002297312405166353 0.001972911593669966 -0.4169484981715055 0 0.9499999999999994 0 0.00115427729936877 -0.00404274258526328 0.002673666564447302 -0.004403017216715688 0.001813219179243035 0.00526057732241384 0 -0.00273877801207574 0.002385180873038865 -0.01130663935391225 0.0001771377685193153 0.001921152994475303 0.004993938565327437 0 0 0 0
The things that I believe would be good to include are:
SimTK::SqrtEps
should be ~1e-8
if Real is double which is suitable for this caseNice job finding the root issue @alexbeattie42! I largely agree with proposed changes.
We will try to prioritize this in our development plans since this likely affects a lot of users. If you're interested in submitting a PR yourself, I'd be happy to review it.
When using the Low Pass filter
TabOpLowPassFilter
the time column is also filtered/shifted.A simple reproduction is available here in the
LowPassFilterTime
folderThis code is used in the example
When starting with the input data file that contains rows of this form:
After running the above table processor with low-pass filtering it becomes:
If you run the same code and comment out the low-pass filter step, the time remains unchanged as expected. The low-pass filter is filtering or shifting the time column which shouldn't be happening.
Disabling padding by setting this line to false seems to fix the problem. That leads me to believe the issue is caused here where the time column is padded since here (where the padding is done) prepends data (so I suppose it goes backwards in time?)