I am working with magnetic coils normal to each other (two or three) that a third party produces a quaternion that captures the direction and the roll around the direction. I must low pass filter the quaternions to smooth out noisy solid body orientation vibrations / movements. I am NOT asking how to filter.
After filtering (embedded code), I must reconstruct a new quaternion and send it along. However, the quaternion must behave the same as the third party.
This post uses angles to solve a problem and does not match the quaternion from the third party.
To obtain the direction of the solid body from the third party quaternion, I use $\mathbf {d'} =\mathbf {q} \mathbf { \hat{x} } \mathbf {q} ^{-1}$; I use obtain the normal for the attitude with $\mathbf {n'} =\mathbf {q} \mathbf { \hat{z} } \mathbf {q} ^{-1}$ where $\mathbf { \hat{x} }$ and $\mathbf { \hat{z} }$ are cartesian 3D basis vectors.
The quaternion has non-zero values for x, y, z, and w. There are plenty of examples of a rotation between two vectors. There appears scant information on preserving the rotation theta without using angles, as angles have gimble lock issues and or poles that are undefined. Quaternions do not have these issues. Vectors do not have these issues.
I am at a loss of how to reproduce the quaternion from these two filtered vectors: $\mathbf {d''}$ and $\mathbf {n''}$ where $\mathbf {n''}$ is normal to $\mathbf {d''}$ after filtering.
No matter how the quaternion $\mathbf {q'}$ is computed, it must have these properties: $\mathbf {d''} =\mathbf {q'} \mathbf { \hat{x} } \mathbf {q'} ^{-1}$ and $\mathbf {n''} =\mathbf {q'} \mathbf { \hat{z} } \mathbf {q'} ^{-1}$.
Given the above, how do I create $\mathbf {q'}$ from $\mathbf {d''}$ and $\mathbf {n''}$?
P.S.: I can get another norm from the quaternion and basis vector $\mathbf { \hat{y} }$, if this helps.
I am testing with this quaternion: $$ \begin{align*} q &= q_{w} + q_{x} \cdot i + q_{y} \cdot j + q_{z} \cdot k\\ q_{w} &= 3.666827976703644 \cdot 10^{-1}\\ q_{x} &= 8.160722255706787 \cdot 10^{-1}\\ q_{y} &= 3.313103318214417 \cdot 10^{-1}\\ q_{z} &= 2.996720373630524 \cdot 10^{-1}\\ \end{align*} $$