Converting MVNX quaternions to .STO file

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Ali Khalilianmotamed Bonab
Posts: 47
Joined: Mon Aug 13, 2018 6:28 am

Converting MVNX quaternions to .STO file

Post by Ali Khalilianmotamed Bonab » Fri Oct 14, 2022 2:29 am

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 782 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.

Tags:

User avatar
Ali Khalilianmotamed Bonab
Posts: 47
Joined: Mon Aug 13, 2018 6:28 am

Re: Converting MVNX quaternions to .STO file

Post by Ali Khalilianmotamed Bonab » Mon Oct 17, 2022 1:33 am

As I have not received any recommendation, I am replying to request your guidance regarding this matter.
Last edited by Ali Khalilianmotamed Bonab on Mon Oct 17, 2022 9:45 am, edited 1 time in total.

User avatar
Thomas Uchida
Posts: 1792
Joined: Wed May 16, 2012 11:40 am

Re: Converting MVNX quaternions to .STO file

Post by Thomas Uchida » Mon Oct 17, 2022 7:21 am

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).

User avatar
Ali Khalilianmotamed Bonab
Posts: 47
Joined: Mon Aug 13, 2018 6:28 am

Re: Converting MVNX quaternions to .STO file

Post by Ali Khalilianmotamed Bonab » Mon Oct 17, 2022 9:43 am

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

User avatar
Thomas Uchida
Posts: 1792
Joined: Wed May 16, 2012 11:40 am

Re: Converting MVNX quaternions to .STO file

Post by Thomas Uchida » Mon Oct 17, 2022 1:31 pm

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).

User avatar
Ali Khalilianmotamed Bonab
Posts: 47
Joined: Mon Aug 13, 2018 6:28 am

Re: Converting MVNX quaternions to .STO file

Post by Ali Khalilianmotamed Bonab » Tue Oct 18, 2022 4:00 am

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);


POST REPLY