For a given IMU vector, identify temporally adjacent bursts and
merge them into a single burst. Bursts whose end time coincides with the
start time of the next burst (within gap_tol) and whose frequencies
agree (within the relative freq_tol) are considered adjacent. Bursts
with different frequencies, axes, or burst data units will not be merged.
To merge bursts with differing units, convert them to a common
unit first with set_imu_units().
Arguments
- x
An IMU vector (
acc,mag, orgyro)- ids
Vector indicating groups to which the elements in
xbelong. If provided, bursts inxwill not be merged across different values of this vector, even if their timestamps and frequencies align.- gap_tol
Absolute tolerance (in seconds) to use when determining whether two bursts are adjacent in time and can be merged. Two bursts are adjacent when the gap between the first burst's end and the second burst's start is within
gap_tol.For example, setting
gap_tol = 0.02would allow a burst that starts up to 0.02 seconds after the end of the previous burst to be merged. See details.- freq_tol
Bare numeric value representing the relative tolerance to use when determining whether two bursts share a sampling frequency. Bursts can only be merged if their frequencies are consistent, within
freq_tol. Bursts can be merged when the faster frequency is at most(1 + freq_tol)times the slower. For example,freq_tol = 0.01merges bursts whose frequencies are within 1% of each other.- drop
Logical indicating whether to drop entries that have been merged into other bursts. If
drop = FALSE(default), the output will have the same length as the inputx, withNAvalues at positions where bursts were merged into a preceding burst. This is useful for retaining index matching between the input and output vectors.
Details
A burst's end is taken as one sample period after its last sample.
A burst of n samples at frequency f therefore ends n / f seconds after
its start. The next burst is adjacent when it starts within gap_tol of
that point.
After merging, the burst's frequency is recomputed from its new
sample count and overall time span. The gap between the bursts therefore
impacts the derived output frequency of the new burst. If the gap_tol is
set to allow any timestamp noise, the gap between the two bursts may not
precisely correspond with the sampling periods of the bursts being merged.
In these cases, the recorded output frequency of the merged burst will
vary slightly from the values of its component bursts.
This approach preserves overall burst time span at the expense of preserving
a consistent burst frequency. If you instead prefer to preserve frequency,
you will need to manually adjust the frequency of the
output burst (see freqs()) or correct timestamps in the input data.
Bursts with missing frequencies (e.g. a burst with only one sample)
are not merged. To merge such bursts, you must assign them a sampling
frequency (see freqs()).
Note that because the burst duration incorporates the elapsed time of the
period after the last recorded sample, timestamp noise can make a
subsequent burst appear to start slightly "before" the previous burst
ends (a small negative time gap). This jitter will also be incorporated into
gap_tol.