I have multiple time series of position data (x, y, z) and orientation data expressed as Euler/Tait-Bryan angles (yaw, pitch, roll) obtained from a head tracking device. I need to obtain velocity information from this data to understand the average and maximum head speed of the users.
Since a first-order differencing amplifies high-frequency noise, as discussed in this answer, I consider applying smoothing and particularly, a Savitzky-Golay filter, to get less noisy estimates of the velocity. For the position components, e.g. $x$, I can compute the smoothed derivative easily using the Scipy's implementation:
vx = savgol_filter(x, window_length=29, polyorder=4, deriv=1, delta=dt)
where dt=0.005s is the time interval between my samples.
However, I'm not certain how I should compute the angular velocities from the Euler angles because the data contains discontinuities at the boundaries $\pm{180}$ degrees. Consider for example this portion from the yaw component:
import numpy as np
alpha = np.array([-178.06, -178.48, -178.91, -179.37, -179.83, 179.72, 179.3, 178.88, 178.46, 178.04])
As a workaround, I first computed the first-difference and set the erroneous values to 0 that are caused by the discontinuities (I didn't bother to compute the correct values for these because the effect on average/maximum velocity is negligible given that I have thousands of samples). Then I applied the SG filter to the corrected first-difference and scaled by my sampling time. See below:
alpha_diff = np.diff(alpha, 1)
alpha_diff[np.abs(alpha_diff) > 180] = 0
v_alpha = savgol_filter(alpha_diff, window_length=29, polyorder=4)
v_alpha *= 1/dt
Is this a valid approach to smooth circular/spherical data like Euler angles that continuities discontinuities at the boundaries? I'm just not sure if this workaround conceptually makes sense.