主要内容

低通滤波器使用四元数SL取向ERP

此示例显示了如何使用球形线性插值(SLERP)来创建四季度和低通滤波器噪声轨迹的序列。SLERP是一种常用的计算机图形技术,用于创建旋转对象的动画。

SLERP Overview

Consider a pair of quaternions$q_0$$q_1$. Spherical linear interpolation allows you to create a sequence of quaternions that vary smoothly between$q_0$$q_1$with a constant angular velocity. SLERP uses an interpolation parameterh可以在0到1之间变化,并确定输出四基因与任何一个$q_0$或者$q_1$.

The original formulation of quaternion SLERP was given by Ken Shoemake [1] as:

$$Slerp(q_0,q_1,h) = q_1(q_1^{-1} q_2)^h$$

An alternate formulation with sinusoids (used in theslerpfunction implementation) is:

$$Slerp(q_0,q_1,h) = \frac{\sin((1-h)\theta)}{\sin\theta}q_0 +
 \frac{\sin(h\theta)}{\sin\theta}q_1$$

where$ \ theta $是四个部分的点产物。注意$ \ theta = dist(q_0,q_1)/2 $.

SLERP与四元部分的线性插值

Consider the following example. Build two quaternions from Euler angles.

Q0 = Quaternion([-80 10 0],'eulerd','ZYX','frame');Q1 = Quaternion([80 70 70],'eulerd','ZYX','frame');

找到四分之一的四分之一Q0toQ1, specify theslerpparameter as 0.3.

p30 = slerp(Q0,Q1,0.3);

To view the interpolated quaternion's Euler angle representation, use theeulerdfunction.

Eulerd(P30,'ZYX','frame')
ans = -56.6792 33.2464 -9.6740

在之间创建平稳的轨迹Q0Q1, specify theslerp插值参数作为0到1之间均匀间隔数的向量。

dt = 0.01; h = (0:dt:1).'; trajSlerped = slerp(q0, q1, h);

将SLERP算法的结果与轨迹进行比较Q0Q1, using simple linear interpolation (LERP) of each quaternion part.

partslininterp = interp1([0; 1],compact([q0; q1]),h,'linear');

请注意,线性插值不会给出单位四元素,因此必须对其进行标准化。

trajLerped = normalize(quaternion(partsLinInterp));

Compute the angular velocities from each approach.

avslerp = Helperquat2av(trajslerped,dt);avlerp = Helperquat2av(trajlerped,dt);

Plot both sets of angular velocities. Notice that the angular velocity for SLERP is constant, but it varies for linear interpolation.

sp = helperslerpplotting;Sp.PlotangularVelocities(Avslerp,Avlerp);

SLERP produces a smooth rotation at a constant rate.

Lowpass Filtering with SLERP

SLERP也可以用于制作更复杂的功能。在这里,SLERP用于低通滤波器嘈杂的轨迹。

旋转噪声可以通过从嘈杂的旋转矢量形成四元组来构建。

rcurr = rng(1); sigma = 1e-1; noiserv = sigma .* ( rand(numel(h), 3) - 0.5); qnoise = quaternion(noiserv,'rotvec');rng(rcurr);

To corrupt the trajectoryTrajslerwith noise, incrementally rotate the trajectory with the noise vectorqnoise.

trajNoisy = trajSlerped .* qnoise;

You can smooth real-valued signals using a single pole filter of the form:

$$ y_k = y_ {k-1} + \ alpha(x_k-y_ {k-1})$$

该公式本质上说新的过滤状态$y_k$should be moved toward the current input$x_k$by a step size that is proportional to the distance between the current input and the current filter state$ y_ {k-1} $.

这种方法的精神告知如何低通滤波四个序列。为此,两者都slerpfunctions are used.

Thefunction returns a measurement in radians of the difference in rotation applied by two quaternions. The range of thefunction is the half-open interval [0, pi).

Theslerp功能用于将滤波器状态转向当前输入。当输入和当前滤波状态之间的差异很大时,它会更多地转向输入, and less toward the input when给出很小的价值。插值参数slerpis in the closed-interval [0,1], so the output ofmust be re-normalized to this range. However, the full range of [0,1] for the interpolation parameter gives poor performance, so it is limited to a smaller rangehrange集中在hbias.

hrange = 0.4;HBIAS = 0.4;

限制低的高的to the interval [0, 1].

低的= max(min(hbias - (hrange./2), 1), 0); high = max(min(hbias + (hrange./2), 1), 0); hrangeLimited = high - low;

Initialize the filter and preallocate outputs.

y = trajnoisy(1);% initial filter stateqout = zeros(size(y),,'like', y);% preallocate filter outputqout(1)= y;

Filter the noisy trajectory, sample-by-sample.

forii = 2:numel(trajnoisy)x = trajnoisy(ii);d = dist(y,x);%将DIST输出重归于该范围[低,高]hlpf = (d./pi).*hrangeLimited + low; y = slerp(y,x,hlpf); qout(ii) = y;endf = figure; sp.plotEulerd(f, trajNoisy,'o');sp.plotEulerd(f, trajSlerped,'K-。','LineWidth', 2); sp.plotEulerd(f, qout,“- - -”,'LineWidth', 2); sp.addAnnotations(f, hrange, hbias);

结论

SLERP can be used for creating both short trajectories between two orientations and for smoothing or lowpass filtering. It has found widespread use in a variety of industries.

参考

  1. Shoemake, Ken. "Animating Rotation with Quaternion Curves."ACMSigraphComputer图形19, no 3 (1985):245-54, doi:10.1145/325165.325242