Timeseries, Timetable, timeseriescollection, Time Data Aggregation
7 views (last 30 days)
Show older comments
When recording data in a test lab, the data channels are not always sampled at the same rate and some channels are not evenly sampled (CAN channels in Automotive Industry). MATLAB doesn't have a good construct for this other than a structure of timeseries. timetable is not better in this way. tscollection is a barely referenced and barely supported object in MATLAB that aggregates timeseries against a single time vector.
For example here is breakdown of a set of channels from a single test:
- 3 x 20Hz
- 19 x 100Hz
- 29 x 2,000Hz
- 2 x 20,000Hx
- 22 x nonuniform sample rate varying from ~2Hz to ~100Hz
What way would you recommend aggregating this data?
3 Comments
Walter Roberson
on 6 Oct 2022
What I do with samples with different timebases is either use timetable() retime(), or else I use resample() or interp1() . On occasion I might have reason to nufft() and then ifft()
Answers (1)
Shubham
on 29 May 2023
Hi Jason,
For aggregating this data with non-uniform sample rates, I would recommend using the tscollection object in MATLAB. The tscollection object can aggregate time-series data with a single time vector. Here's how you can create a tscollection object and aggregate your data:
- Create individual timeseries objects for each channel with their timestamps and values.
- Add each timeseries object to the tscollection object using the "addts" function. This will create a timeseries collection with each timeseries using an independent time vector.
- Use the "synchronize" function to create a uniform time vector across the entire tscollection.
- Interpolate the data from all the channels at the uniform time vector using the "resample" function.
Here's an example code snippet that shows how to do this:
% Create individual timeseries objects for each channel
ts1 = timeseries(data1, time1);
ts2 = timeseries(data2, time2);
ts3 = timeseries(data3, time3);
ts4 = timeseries(data4, time4);
ts5 = timeseries(data5, time5);
% Create a tscollection object and add each timeseries to it
tsCol = tscollection();
tsCol = addts(tsCol, ts1);
tsCol = addts(tsCol, ts2);
tsCol = addts(tsCol, ts3);
tsCol = addts(tsCol, ts4);
tsCol = addts(tsCol, ts5);
% Synchronize the timeseries in the tscollection
tsCol = synchronize(tsCol);
% Resample the data to create a uniform sample rate
uniformTime = tsCol.Time;
ts1Resampled = resample(ts1, uniformTime);
ts2Resampled = resample(ts2, uniformTime);
ts3Resampled = resample(ts3, uniformTime);
ts4Resampled = resample(ts4, uniformTime);
ts5Resampled = resample(ts5, uniformTime);
% Get the data values from each timeseries and store in a matrix
dataMatrix = [ts1Resampled.Data, ts2Resampled.Data, ts3Resampled.Data, ts4Resampled.Data, ts5Resampled.Data];
This code snippet will create a matrix with each row representing a specific time value and each column representing a channel's data. This matrix can then be used for further calculations and analysis.
0 Comments
See Also
Categories
Find more on Time Series in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!