低通滤波器使用四元数SL取向ERP
此示例显示了如何使用球形线性插值(SLERP)来创建四季度和低通滤波器噪声轨迹的序列。SLERP是一种常用的计算机图形技术,用于创建旋转对象的动画。
SLERP Overview
Consider a pair of quaternions和. Spherical linear interpolation allows you to create a sequence of quaternions that vary smoothly between和with a constant angular velocity. SLERP uses an interpolation parameterh
可以在0到1之间变化,并确定输出四基因与任何一个或者.
The original formulation of quaternion SLERP was given by Ken Shoemake [1] as:
An alternate formulation with sinusoids (used in theslerp
function implementation) is:
where是四个部分的点产物。注意.
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');
找到四分之一的四分之一Q0
toQ1
, specify theslerp
parameter as 0.3.
p30 = slerp(Q0,Q1,0.3);
To view the interpolated quaternion's Euler angle representation, use theeulerd
function.
Eulerd(P30,'ZYX','frame')
ans = -56.6792 33.2464 -9.6740
在之间创建平稳的轨迹Q0
和Q1
, specify theslerp
插值参数作为0到1之间均匀间隔数的向量。
dt = 0.01; h = (0:dt:1).'; trajSlerped = slerp(q0, q1, h);
将SLERP算法的结果与轨迹进行比较Q0
和Q1
, 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 trajectoryTrajsler
with 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:
该公式本质上说新的过滤状态should be moved toward the current inputby a step size that is proportional to the distance between the current input and the current filter state.
这种方法的精神告知如何低通滤波四个序列。为此,两者都区
和slerp
functions are used.
The区
function returns a measurement in radians of the difference in rotation applied by two quaternions. The range of the区
function is the half-open interval [0, pi).
Theslerp
功能用于将滤波器状态转向当前输入。当输入和当前滤波状态之间的差异很大时,它会更多地转向输入区
, and less toward the input when区
给出很小的价值。插值参数slerp
is in the closed-interval [0,1], so the output of区
must 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.
参考
Shoemake, Ken. "Animating Rotation with Quaternion Curves."ACMSigraphComputer图形19, no 3 (1985):245-54, doi:10.1145/325165.325242