Timeseries, Timetable, timeseriescollection, Time Data Aggregation
조회 수: 19(최근 30일)
표시 이전 댓글
Jason Nicholson 2022년 10월 4일
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
Walter Roberson 2022년 10월 6일
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()
Shubham 2023년 5월 29일 7:03
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
Find more on Time Series Collections in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!