Synchronizing vectors of different lengths

4 views (last 30 days)
imaging_tech
imaging_tech on 24 Oct 2017
Commented: Jan on 24 Oct 2017
I have a set of three different vectors all with the same runtime of 39 seconds. One vector contains data from a force sensor, the other is a matrix of 11 channels recorded from two IMU units with 6 DoF and the last is from an audio sensor. I have been able to resampüle all the data to 10kHz roughly but the vector lengths are not uniform.
I would like to synchronize all data to a uniform time of 60 seconds. So far, I tried to create a time vector manually but I could not use that in the timeseries class. So what could be a way for me to make sure that all vectors are of the same length and that they correspond to a uniform time vector?
  2 Comments
Rik
Rik on 24 Oct 2017
How are you planning to pad your vectors? Should 40-60 be filled with NaN? inf?
imaging_tech
imaging_tech on 24 Oct 2017
My vectors have been padded with 0's so I guess 40-60 can also be padded with 0's.

Sign in to comment.

Answers (1)

Jan
Jan on 24 Oct 2017
If all input vectors belong to measurement of the same time range, a correct interpolation would result in arrays of the same number of elements. Then no padding is required.
Please post, how you "resample" the data and explain, if padding is really required.
  2 Comments
imaging_tech
imaging_tech on 24 Oct 2017
I imported all data as column vectors. Following this, I resampled the vectors as follows:
Fs = 92;
t = 0:1/Fs:1-(1/Fs);
x1 = "data";
[P,Q] = rat(10e3/Fs);
abs(P/Q*Fs-10000);
data_new = resample("data",P,Q);
My column vectors were of different lengths but following the re-sampling they still remained the same way and therefore I padded them with 0's.
Jan
Jan on 24 Oct 2017
If all imported vectors belong to the same time span, I'd prefer a linear interpolation:
nData = size(data, 1);
data_new = interp1(1:nData, data, linspace(1, nData, n), 'linear')
Or if this is a bottleneck of your code with the faster C-Mex: FEX: ScaleTime
data_new = ScaleTime(data, 1, nData, n)

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!