Page 1 of 1

Converting MVNX quaternions to .STO file

Posted: Fri Oct 14, 2022 2:29 am
by alik
Dear OpenSim Community,
I am using the MVN link and MVN analyzer system to record the motion data. This system directly provides the orientation of sensors as a .XLSX file.

My problem is with converting the data to the format required by OpenSim .STO:

- MVN Analyzer provides all data in MVNX format containing all data in a tree structure.

- The required data is extracted into a Matlab Table, as shown in the figure below:
opensim.PNG
opensim.PNG (112.5 KiB) Viewed 544 times

- I currently cannot manage to export the Matlab table in the OpenSim STO required format in which all four elements of quaternions are concatenated with a comma separator in a single column.

It would be great if you could provide some code or guidelines on how to convert either the Matlab table or, directly, MVN data into an STO file.

Thanks in advance for your help,
Ali.

Re: Converting MVNX quaternions to .STO file

Posted: Mon Oct 17, 2022 1:33 am
by alik
As I have not received any recommendation, I am replying to request your guidance regarding this matter.

Re: Converting MVNX quaternions to .STO file

Posted: Mon Oct 17, 2022 7:21 am
by tkuchida
Please see the "IMUDataConversion.m" script here: https://github.com/opensim-org/opensim- ... nversion.m. Some additional example files can be found in the same directory (https://github.com/opensim-org/opensim- ... nseExample). These files will appear in your local "Resources" directory under "Resources\Code\Matlab\OpenSenseExample". If you don't have a local "Resources" directory, you can run "installResources()" in the ScriptingShell.

If that doesn't work, you could write a script (Matlab, Python, etc.) to do the conversion yourself. A description of the STO file format can be found on the "Storage (.sto) Files" page in the documentation (https://simtk-confluence.stanford.edu:8 ... o%29+Files).

Re: Converting MVNX quaternions to .STO file

Posted: Mon Oct 17, 2022 9:43 am
by alik
Thank you so much for your reply.

I have already checked the example file. I am using MVN instead of the MT system, which already gives the sensors' orientation as quaternions instead of raw sensors' orientation/acceleration data. Therefore, "IMUDataConversion.m" does not work for my system.

My question is mainly about how to write code to convert Matlab Table to STO format ( I can convert the MVNX to Matlab Table):

The problem with converting Matlab Table to an STO file is that the STO file requires the imu dataset to be "4*1 separated doubles by a comma with a single header", which I have not been able to write such a file with this format from Matlab.

I managed to get my data from Matlab and paste them into an existing STO file. As this is an ad-hoc method, it would be efficient to be used in a large number of datasets.

Many thanks in advance for your time in answering my question

Re: Converting MVNX quaternions to .STO file

Posted: Mon Oct 17, 2022 1:31 pm
by tkuchida
A straightforward way of doing this would be to write the file line-by-line as text (see, for example, the sprintf command in Matlab: https://www.mathworks.com/help/matlab/ref/sprintf.html).

Re: Converting MVNX quaternions to .STO file

Posted: Tue Oct 18, 2022 4:00 am
by alik
Thank you so much for your help. It resolved my issue and I am sharing the code below in case someone needs it:

Code: Select all


fid = fopen('../Experimental_Data/OpenSim_IMU_Dataset.sto','w+');
fprintf(fid,'DataRate=240.000000\nDataType=Quaternion\nversion=3\nOpenSimVersion=4.3\nendheader\n');
fprintf(fid,'time\t%s\t%s\t%s\t%s\t%s\n',FieldNames{:});
for i = 1:1:size(OsimTable,1)
fprintf(fid,'%1.3f\t%f,%f,%f,%f\t%f,%f,%f,%f\t%f,%f,%f,%f\t%f,%f,%f,%f\t%f,%f,%f,%f\n',table2array(OsimTable(i,:)));
end
fclose(fid);