Computing average shape of curves

Keywords: python python-3.x matplotlib


I have recordings of stroke pressure traces. One stroke consists of one or more timestamps and associated pressure values. Some strokes also only contain a single pressure value. An example of 3 strokes could be the following:

stroke_id    timestamp    pressure
1            5001         143
1            5230         170
1            5360         500
1            5600         420
2            10223        1052
3            942          6523
3            1532         6000
3            1700         5500

I'm only interested in the shape of the pressure curve and not the absolute values. What I would like to compute is the average curve (the shape). For this purpose I thought about the following steps:

  1. Move every stroke to the origin
  2. Interpolate (or extrapolate) each stroke because the timestamps are not evenly spaced. Perhaps not linear but cubic interpolation.
  3. Compute the average over the strokes
  4. Plot the average stroke

I don't know if this is the correct procedure and I'm also not sure how to tackle the individual steps. Moreover, I'm unsure how to handle strokes with only one pressure value.

I would be happy if somebody could bring light into the dark.