You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Synchronizing the data of 2 subdevices within 1 device.
2 views (last 30 days)
Show older comments
I am currently trying to figure out how to Sync up my IMU data. Within this IMU there is an Accelerometer and Gyroscope that get data with 200Hz and an GNSS that gets data with 10Hz. The ultimate goal is using the script(when its done) for event detection. Within the GNSS data I get is a POSIX time and a 'timestamp[us]' in the IMU data is only the 'timestamp[us]. Does anyone have an idea on how I could manage to sync these two time variables so I can view real time events within matlab eventhough they have different frequencies.
Answers (1)
Star Strider
on 16 Jun 2025
I would copy both original data records to appropriate timetable arrays, and then use the synchronize function. It might be necessary to create POSIX time vlaues for the one that has only microseconds (IMU), so create the complete timestamp, or use only the 'seconds' data from the data (GNSS) with POSIX times.
10 Comments
Niels
on 18 Jun 2025
But since the to devices have different frequencies, i have way more datapoints from one of the 2. Wouldn't that create issues?
Star Strider
on 18 Jun 2025
The synchronize function has ways to deal with those issues. You have to decide what to tell it to create the result you want.
I still suggest adding the date to the POSIX timestamps for the IMU data. That will make everything easier, and doing it is probably straightforward with the MATLAB datetime function.
Star Strider
on 20 Jun 2025
If you posted examples of your files, I might be able to post an example of how to do all of this.
Adding the date information to the IMU data should be relatively straightforward.
With respect to interpolating the GNSS data, there are several options, however the two I sould recommend would be 'previous' (all 'missing' data subsequent to the first data instance repeat until the next data), or perhaps linear' to linearly interpolate between the data. It depends on how you want those data to be interpolated to fill the 'gaps'.
Niels
on 20 Jun 2025
Hi, i created an example file. Line 1 through 500 is from the GNSS and line 501 till 1000 is from the IMU.
If you got the time and are still willing to try and help out i'd greatly appreciate that. If not, no worries.
If a differrent formate is preferred or needed, i could provide that(probably).
Star Strider
on 20 Jun 2025
I need some clarification with respect to what you want to do with these data. Breaking the original file into two files, it appears that 'GNSS' has data that 'IMU' does not, although they both have the same variable names. That raises a different question, since 'time [POSIXms]' is different for IMU and GNSS. (They seem to simply be millisecond values, not actually POSIX formatted dates and times.) Converting them using seconds does not add much information.
How do you want to deal with these?
AllData = readtable('MatlabForum.xlsx', VariableNamingRule='preserve');
IMU = AllData(1:500,:)
IMU = 500×8 table
time [POSIXms] timestamp [us] latitude [deg] longitude [deg] speedN [m/s] speedE [m/s] speedD [m/s] altitude [m]
______________ ______________ ______________ _______________ ____________ ____________ ____________ ____________
1.7468e+12 1.403e+06 1 1 0 0 0 91317
1.7468e+12 1.5392e+06 1 1 0 0 0 91317
1.7468e+12 1.6392e+06 1 1 0 0 0 91317
1.7468e+12 1.7392e+06 1 1 0 0 0 91317
1.7468e+12 1.8382e+06 1 1 0 0 0 91317
1.7468e+12 1.9388e+06 1 1 0 0 0 91317
1.7468e+12 2.039e+06 1 1 0 0 0 91317
1.7468e+12 2.1388e+06 1 1 0 0 0 91317
1.7468e+12 2.2392e+06 1 1 0 0 0 91317
1.7468e+12 2.3382e+06 1 1 0 0 0 91317
1.7468e+12 2.4395e+06 1 1 0 0 0 91317
1.7468e+12 2.5392e+06 1 1 0 0 0 91317
1.7468e+12 2.638e+06 1 1 0 0 0 91317
1.7468e+12 2.7392e+06 1 1 0 0 0 91317
1.7468e+12 2.8402e+06 1 1 0 0 0 91317
1.7468e+12 2.9392e+06 1 1 0 0 0 91317
GNSS = AllData(501:end,:)
GNSS = 499×8 table
time [POSIXms] timestamp [us] latitude [deg] longitude [deg] speedN [m/s] speedE [m/s] speedD [m/s] altitude [m]
______________ ______________ ______________ _______________ ____________ ____________ ____________ ____________
8.455e+05 -0.41187 -0.11078 -0.23766 -35.7 77.28 159.32 NaN
8.505e+05 -0.97893 -0.24986 -0.55388 26.04 0.56 11.48 NaN
8.555e+05 -0.93159 -0.19959 -0.48995 17.64 -4.06 8.82 NaN
8.605e+05 -0.91012 -0.1747 -0.46604 60.48 -28.56 67.34 NaN
8.655e+05 -0.9067 -0.17129 -0.48214 -7 16.24 -19.32 NaN
8.705e+05 -0.90329 -0.1952 -0.49386 -3.64 16.1 -18.76 NaN
8.755e+05 -0.85937 -0.18739 -0.4675 -2.8 14.56 -20.3 NaN
8.805e+05 -0.8257 -0.19959 -0.42114 -4.2 16.52 -21.98 NaN
8.855e+05 -0.77494 -0.1747 -0.3577 7.42 18.2 -10.22 NaN
8.905e+05 -0.78861 -0.21228 -0.37625 5.88 20.44 -7.14 NaN
8.955e+05 -0.80032 -0.2196 -0.38454 4.2 23.1 -4.06 NaN
9.005e+05 -0.81301 -0.2113 -0.40797 2.52 24.5 -6.58 NaN
9.055e+05 -0.79788 -0.19666 -0.42846 2.1 26.6 -13.58 NaN
9.105e+05 -0.79202 -0.26303 -0.47238 0 30.38 -16.1 NaN
9.155e+05 -0.79007 -0.31964 -0.54363 -4.48 34.02 -12.74 NaN
9.205e+05 -0.78763 -0.35819 -0.54266 -0.98 40.74 -8.54 NaN
GNSS_POSIX = seconds(GNSS{:,1});
[GNSS_start,GNSS_end] = bounds(GNSS_POSIX)
GNSS_start = duration
8.455e+05 sec
GNSS_end = duration
3.336e+06 sec
IMU_POSIX = seconds(IMU{:,1});
[IMU_start,IMU_end] = bounds(IMU_POSIX)
IMU_start = duration
1.7468e+12 sec
IMU_end = duration
1.7468e+12 sec
VNIMU = IMU.Properties.VariableNames
VNIMU = 1×8 cell array
{'time [POSIXms]'} {'timestamp [us]'} {'latitude [deg]'} {'longitude [deg]'} {'speedN [m/s]'} {'speedE [m/s]'} {'speedD [m/s]'} {'altitude [m]'}
VNGNSS = GNSS.Properties.VariableNames
VNGNSS = 1×8 cell array
{'time [POSIXms]'} {'timestamp [us]'} {'latitude [deg]'} {'longitude [deg]'} {'speedN [m/s]'} {'speedE [m/s]'} {'speedD [m/s]'} {'altitude [m]'}
VNCommon = intersect(VNIMU, VNGNSS, 'stable')
VNCommon = 1×8 cell array
{'time [POSIXms]'} {'timestamp [us]'} {'latitude [deg]'} {'longitude [deg]'} {'speedN [m/s]'} {'speedE [m/s]'} {'speedD [m/s]'} {'altitude [m]'}
.
Niels
on 20 Jun 2025
I'd assume that both the GNSS and the IMU start collecting data at the same time since they are both within the same device. So maybe you could assume that the first data point of the IMU has the same POSIX value..
Star Strider
on 20 Jun 2025
I am also a bit confused with the timestamps. If they are in the same device (and I assume using the same clock), the times should be similar. The GNSS data has negative microsecond timestamps. I am not sure how to combine the times (millisecond and microsecond) and have them resemble each other. They do not seem to overlap.
We need to resolve the inconsistencies in the time values (ms and us) in the two records in order to proceed with this, since synchronzing them is the primary issue. We can then resolve ow to combine or interpolate the longitude, latitude, altitude, velocity and any others.
I do not have access to your instrumentation or how it reports the time values. I may be able help resolve this, however I need to understand how your instrumentation reports the relevant time values for the two records.
I also assume that the latitude, longitude, velocities, altitude, and such should be the same for equivalent times for both records.
AllData = readtable('MatlabForum.xlsx', VariableNamingRule='preserve');
IMU = AllData(1:500,:)
IMU = 500×8 table
time [POSIXms] timestamp [us] latitude [deg] longitude [deg] speedN [m/s] speedE [m/s] speedD [m/s] altitude [m]
______________ ______________ ______________ _______________ ____________ ____________ ____________ ____________
1.7468e+12 1.403e+06 1 1 0 0 0 91317
1.7468e+12 1.5392e+06 1 1 0 0 0 91317
1.7468e+12 1.6392e+06 1 1 0 0 0 91317
1.7468e+12 1.7392e+06 1 1 0 0 0 91317
1.7468e+12 1.8382e+06 1 1 0 0 0 91317
1.7468e+12 1.9388e+06 1 1 0 0 0 91317
1.7468e+12 2.039e+06 1 1 0 0 0 91317
1.7468e+12 2.1388e+06 1 1 0 0 0 91317
1.7468e+12 2.2392e+06 1 1 0 0 0 91317
1.7468e+12 2.3382e+06 1 1 0 0 0 91317
1.7468e+12 2.4395e+06 1 1 0 0 0 91317
1.7468e+12 2.5392e+06 1 1 0 0 0 91317
1.7468e+12 2.638e+06 1 1 0 0 0 91317
1.7468e+12 2.7392e+06 1 1 0 0 0 91317
1.7468e+12 2.8402e+06 1 1 0 0 0 91317
1.7468e+12 2.9392e+06 1 1 0 0 0 91317
GNSS = AllData(501:end,:)
GNSS = 499×8 table
time [POSIXms] timestamp [us] latitude [deg] longitude [deg] speedN [m/s] speedE [m/s] speedD [m/s] altitude [m]
______________ ______________ ______________ _______________ ____________ ____________ ____________ ____________
8.455e+05 -0.41187 -0.11078 -0.23766 -35.7 77.28 159.32 NaN
8.505e+05 -0.97893 -0.24986 -0.55388 26.04 0.56 11.48 NaN
8.555e+05 -0.93159 -0.19959 -0.48995 17.64 -4.06 8.82 NaN
8.605e+05 -0.91012 -0.1747 -0.46604 60.48 -28.56 67.34 NaN
8.655e+05 -0.9067 -0.17129 -0.48214 -7 16.24 -19.32 NaN
8.705e+05 -0.90329 -0.1952 -0.49386 -3.64 16.1 -18.76 NaN
8.755e+05 -0.85937 -0.18739 -0.4675 -2.8 14.56 -20.3 NaN
8.805e+05 -0.8257 -0.19959 -0.42114 -4.2 16.52 -21.98 NaN
8.855e+05 -0.77494 -0.1747 -0.3577 7.42 18.2 -10.22 NaN
8.905e+05 -0.78861 -0.21228 -0.37625 5.88 20.44 -7.14 NaN
8.955e+05 -0.80032 -0.2196 -0.38454 4.2 23.1 -4.06 NaN
9.005e+05 -0.81301 -0.2113 -0.40797 2.52 24.5 -6.58 NaN
9.055e+05 -0.79788 -0.19666 -0.42846 2.1 26.6 -13.58 NaN
9.105e+05 -0.79202 -0.26303 -0.47238 0 30.38 -16.1 NaN
9.155e+05 -0.79007 -0.31964 -0.54363 -4.48 34.02 -12.74 NaN
9.205e+05 -0.78763 -0.35819 -0.54266 -0.98 40.74 -8.54 NaN
GNSS_Time = GNSS{:,1}*1E-3+GNSS{:,2}*1E-6; % Convert To 'seconds'
[GNSS_start,GNSS_end] = bounds(GNSS_Time)
GNSS_start = 845.5000
GNSS_end = 3.3360e+03
GNSS_Timespan = GNSS_end - GNSS_start
GNSS_Timespan = 2.4905e+03
IMU_Time = IMU{:,1}*1E-3+IMU{:,2}*1E-6; % Convert To 'seconds'
[IMU_start,IMU_end] = bounds(IMU_Time)
IMU_start = 1.7468e+09
IMU_end = 1.7468e+09
IMU_Timespan = IMU_end - IMU_start
IMU_Timespan = 97.5680
.
Star Strider
on 21 Jun 2025
@Niels -- Having the documentation for your instrumentation with respect to how it calculates and assigns the time data for both the IMU and GNSS records would help solve this.
Please post the relevant sections of the .pdf documentation, or the entire .pdf documentation if it is not voluminous (that is, fits the Answers file size limits).
Niels
on 23 Jun 2025
Yeah that is where my issue started, the documentation that I have says nothing about the calculation or the gathering of the data from the device itself.. I've mailed the company trying to get anything like that tho.
See Also
Categories
Find more on Logical in Help Center and File Exchange
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)