wadpac / GGIRread

Functions for reading accelerometer data files
https://CRAN.R-project.org/package=GGIRread
Apache License 2.0
5 stars 3 forks source link

resampling function receives timestamps outside expected interval in readAxivity #33

Closed vincentvanhees closed 1 year ago

vincentvanhees commented 1 year ago

Axivity cwa files can come with irregular sampling rates in the data, but it seems that sometimes the time gaps are longer than just minor fluctuations in the sampling rate. For example, we see time jumps of more than half a second.

Separately, we noticed that readAxivity output sometimes shows extreme peaks in the acceleration values. These are automatically labelled as signal clipping by GGIR and ignored in the analyses. In the last release I temporarily 'fixed' the issue by forcing the value of parameter 'u' to be within the interval [0, 1]: https://github.com/wadpac/GGIRread/blob/main/src/resample.cpp#L27-L30 https://github.com/wadpac/GGIRread/blob/main/src/resample.cpp#L41-L44 My reasoning was that this occurs rarely and therefore not a major issue.

However, I now see that the peaks are actually caused by the resample algorithm that aims to handle the irregular sampling rate and is confronted with time gaps. The observed time range in the loaded rawTime is larger when sampling rate drops than the time range of the expected timeRes. To address this a larger increment of the index last is needed.

By addressing this the resampling function will no longer receive timestamps outside timeRes and by that should no longer the somewhat ugly fix I applied in the last release. I am now working on this.