4

I have an algorithm in C++ that uses Kalman Filter. Somewhere in the code a predict a Quaternion q' and then I update the Quaternion with Kalman Filter q.

I want to plot two graphics in Matlab with the evolution of the predicted quaternion and the corrected(updated) quaternion so I am using "engine.h" library to send quaternion info to Matlab during processing (actually what I send is a 4x1 matrix).

So my question is: What is the best way to plot a quaternion in Matlab so I can visually extract information? Is it maybe better to plot the angles separately?

Jav_Rock
  • 22,059
  • 20
  • 123
  • 164
  • 2
    Your question title does not match your actual question. – David Brown Jan 11 '12 at 08:55
  • 1
    IF I am not mistaken, your question has nothing to do with "engine.h" or c++, right? – Andrey Rubshtein Jan 11 '12 at 13:09
  • Well, it has because I will send the commands from c++ code ad this can give some problems, so later it is probable that I edit the question showing the full code. But it is true that the question can be thought in terms of matlab too. – Jav_Rock Jan 11 '12 at 13:28

2 Answers2

4

I think a good option is sending the quaternion as a vector to MATLAB, using C++ MATLAB engine

[qx qy qz qw]

Then, in MATLAB environment you can use a toolbox for translating to Euler Angles, which is a common visual option.

For adding a path of a toolbox in matlab engine:

addpath(genpath('C:\Program Files (x86)\MATLAB\R2010a\toolbox\SpinCalc'));

With spincalc toolbox, converting would be something like this:

Angles=SpinCalc('QtoEA321',Quaternion,0,0);
Carlos Cachalote
  • 763
  • 3
  • 9
  • 19
4

Well, assuming that the question is "How to visualize in a nice way a 4D space", I can think of a few options:

  • Show multiple slices of the space, that is for (x,y,z,t) -> (x,y), (y,z),etc..
  • Show (x,y) as scatter plot and encode the information of z in color, t in size of dot. For that you can use the scatter command :

SCATTER(X,Y,S,C) displays colored circles at the locations specified by the vectors X and Y (which must be the same size).

If your question was "How to visualize in a nice way quarternions, check this out

Community
  • 1
  • 1
Andrey Rubshtein
  • 20,795
  • 11
  • 69
  • 104