I have tabular data of acceleration values over time, like this example:
time(s) acc_x acc_y
0.1 0 0
0.2 -0.98 1.66
0.3 1.42 1.72
0.4 -1.98 -0.3
0.5 -0.3 -0.79
0.6 -1.15 1.65
0.7 1.2 -0.5
0.8 1.97 0.51
0.9 -0.74 -0.39
1 -0.47 -1.06
1.1 1.77 0.87
1.2 -0.35 -0.67
1.3 1.4 0.51
1.4 1.72 1.47
1.5 -0.37 -0.83
1.6 1.65 -0.07
1.7 1.51 -0.53
1.8 -0.46 -0.8
1.9 -0.35 -0.18
2 0 0
From this, I want to calculate the position values by twofold integration to use the position coordinates as keyframed positions in blender. Because I do not always know the timebase of my input data, I want to resample it into the inter-frame time intervals.
This is what I tried so far, mainly trying to adapt this code sample: Rolling integral over pandas dataframe with time index
import pandas as pd
from scipy import integrate
cur_fps=25 #bpy.context.scene.render.fps
acc_table=pd.read_excel("C:/Temp/exampleaccelerations.xlsx",index_col=0) #read the table from disk
timedeltastrings={"interp":"%d"%(timedelta_base/100)+"us","vel":"%d"%(timedelta_base/10)+"us","pos":"%d"%(timedelta_base)+"us"}
acc_table_interp=acc_table.resample(timedeltastrings["interp"]).interpolate(method="linear")
vel_table=acc_table_interp.rolling(timedeltastrings["vel"]).apply(integrate.trapz)
vel_table_interp=vel_table.resample(timedeltastrings["vel"]).interpolate(method="linear")
pos_table=vel_table.rolling(timedeltastrings["pos"]).apply(integrate.trapz)
pos_table_interp=pos_table.resample(timedeltastrings["pos"]).interpolate(method="linear")
The code may not be especially tidy but works and gives results. However, the resulting values are way too high compared to a manual evaluation (eg. in Excel). I have absolutely no idea how even to draw a mental connection between the results and the input.
In case you wonder, the resampling is supposed to give the rolling integrator some values to work with. Without resampling and a window size of 100ms (analogous to my understanding of the answer linked above), the results of the integrations are all-zero dataframes.
Could anyone please point me in the direction of how to correctly use the scipy integrator (or any other equivalent function) so that I can get the correct results?