Align Irregular Multi-Rate Sensor Data with MATLAB Timetables
MATLAB timetables with synchronize and retime replace manual index loops for aligning multi-rate sensor data, reducing bugs and improving code readability.
16 Apr 2026, 13:04 UTC

The Indexing Nightmare
\nEngineering data rarely arrives on a uniform grid. Perhaps you're synchronizing an IMU logging at 100 Hz with a GPS receiver updating at 1 Hz, or merging temperature logs from an environmental chamber with vibration data from a structural test. The traditional approach--storing signals in parallel numeric arrays and writing nested for loops to find the closest timestamp--quickly becomes a source of off-by-one errors, confusing index arithmetic, and code that's hard to audit.
Why Timetables Matter for Time-Series Data
\nA timetable is MATLAB's specialized table variant where the first dimension is designated as time. This enables time-based indexing, automatic alignment, and resampling without manually tracking index offsets. Unlike a struct array, where you'd track time as a separate field, or a numeric matrix, where time is just another row, a timetable carries its time vector as part of the data container, making it the canonical choice for time-series workflows in MATLAB.
Aligning Multi-Rate Data with synchronize and retime
\nWhen two sensors sample at different rates, the goal is usually to bring both onto a common time grid. MATLAB provides two complementary functions:
\n- \n
- synchronize: Merges multiple timetables. Options include
'union'(all timestamps, gaps filled withNaN),'intersection'(only timestamps present in all tables), and'nearest'or'linear'(fill missing values using the closest point or linear interpolation). \n - retime: Resamples a single timetable to a new time vector or a fixed duration. This is useful when you need a uniform grid for downstream analysis, such as an FFT or a control-loop simulation. \n
Worked Example: Aligning an Accelerometer and Temperature Sensor
\nSuppose you have a high-frequency accelerometer and a low-frequency temperature sensor. The following script aligns both to a common 0.2-second grid. Run this in the MATLAB Command Window (R2016b or later).
\n% Create high-rate IMU data (10 Hz, 11 time points from 0 to 1 second)\nt_imu = datetime('now') + seconds(0:0.1:1);\naccel = randn(11, 1);\ntt_imu = timetable(t_imu', accel, 'VariableNames', {'Accel'});\n\n% Create low-rate temperature data (1 Hz, mismatched start)\nt_temp = datetime('now') + seconds(0.05:1:1.05);\ntemp = 20 + randn(2, 1);\ntt_temp = timetable(t_temp', temp, 'VariableNames', {'Temp'});\n\n% Synchronize to a union of timestamps, filling temperature gaps linearly\ntt_combined = synchronize(tt_imu, tt_temp, 'union', 'linear');\n\n% Retime to a strict 0.2-second regular grid for analysis\ntt_final = retime(tt_combined, 'regular', 'linear', 'TimeStep', seconds(0.2));\n\n% Inspect the result\ndisp(size(tt_final));\ndisp(tt_final.Time);\n\nVerification: After running, check that tt_final.Time shows exactly 0.2-second intervals. If you need to avoid synthesized values, replace 'linear' with 'nearest' or omit the fill method to leave gaps as NaN.
Trade-offs and Limitations
\n| Feature | Timetable | Numeric Matrix |
|---|---|---|
| Memory | Higher overhead due to time metadata and table structure | Minimal; raw numeric storage |
| Math speed | Slower; table indexing is not optimized by BLAS/LAPACK | Fast; leverages compiled linear algebra |
| Alignment | Declarative via synchronize/retime | Manual loop-based indexing |
For datasets with millions of rows and many variables, the memory footprint of an in-memory timetable can grow quickly. If you exceed available RAM, switch to tall arrays or a datastore workflow to process data in chunks. Additionally, the TimeZone property on a timetable is explicit; when joining timetables from different time zones, MATLAB does not automatically convert between them. You must set the TimeZone property or convert timestamps to UTC/UTC beforehand using datetime arithmetic.
Verification Checklist
\n- \n
- Run
verin MATLAB to confirm the release is R2016b or later and that the timetable package is available. \n - Run
help timetable,help retime, andhelp synchronizeto review documented syntax and options for your specific installation. \n - Create two small timetables with mismatched times and test
synchronizeandretimeto observe alignment and fill behavior. \n - Inspect
timetable.Timeclass and theTimeZoneproperty to confirm time handling matches your expectations, especially if data spans daylight-saving transitions. \n
Actionable Closing
\nIf your current MATLAB scripts rely on find or interp1 to align time-series arrays, migrate those sections to timetable. Start by converting your raw arrays using timetable(timeVector, dataArray), then replace alignment loops with synchronize. This reduces the surface area for bugs and makes your data pipeline self-documenting.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.