This function is useful to align for example tracker and mocap data when they are not precisely synchronised. The two movement trajectories must be in the same coordinate system, but they can have a spatial translation, different scaling, and different sampling rate.

find_movement_latencies(
  df1,
  df2,
  col1 = c("pos_x", "pos_y", "pos_z"),
  col2 = c("pos_x", "pos_y", "pos_z"),
  scale1 = 1,
  scale2 = 1,
  sample_rate = 10,
  interval = c(-1, 1),
  start_time1 = 0
)

Arguments

df1

First movement data frame, must have a column time

df2

Second movement data frame, must have a column time

col1

(String) vector of column names for xyz position of the first data frame

col2

(String) vector of column names for xyz position of the second data frame

scale1

Scaling of the first movement trajectory (e.g. 1 for m or 10e-3 for mm)

scale2

Scaling of the second movement trajectory (e.g. 1 for m or 10e-3 for mm)

sample_rate

Sampling rate used for the comparison

interval

Two-element vector of the interval for the optimisation

Value

A list with elements and lag (estimated lag in s) and dist (residual spatial distance after mean translation subtracted from both data frames)

Details

The function uses brute force by a simple grid-search at the specified sample rate and over the specified interval.