Interpolate and synchronize two time series

Hello,
I'm trying to match two different timeseries to one common time-vector. The problem is, there are two matrices which I want to match. First of all I'll give an example:
matrix_A
TimeA DataA_1 DataA_2 DataA_3
0.27 63 57 12.3
0.31 65 47 11.3
0.54 69 53 11.7
0.82 71 51 11.9
0.98 70 52 12.1
1.24 69 49 12.4
--------------------------
matrix_B
TimeB DataB_1 DataB_2
0.13 113 23.7
0.54 112 25.8
0.69 110 24.4
0.85 115 23.5
1.03 113 25.9
Now i want to match this two series of data to one matrix with equal time gaps, for example 0.25.
My idea is: First interpolate both data-series to get values at 0; 0.25; 0.5; 0.75; 1.0; 1.25 ... and then safe them in one single matrix, that looks like:
matrix_finish
Time DataA_1 DataA_2 DataA_3 DataB_1 DataB_2
0 ... ... ... ... ...
0.25
0.5
0.75
1.0
1.25
...
I know, there are functions in matlab like synchronize and interp1 or something, but it looks like I am to stupid to use them correctly for my problem.
Thanks for any help.

 Accepted Answer

jonas
jonas on 16 Oct 2018
  1. Create two timetables using table2timetable (you have to converted the time to duration or datetime format)
  2. Use synchronize OR retime with a common time vector.
Easy peasy. Upload some data and I will show you how.

4 Comments

Good morning jonas,
thanks for your fast answer. Here are two examples of my data as txt-files. At the moment I safe the files manually as Excel-Files (Dataserie1.xlsx and Dataserie2.xlsx) and then I scan them in with the MATLAB-function xlsread, for example [matrixA,~,~] = xlsread('Dataserie1.xlsx'). This is necessary to switch the decimal-comma ',' to a decimal-point '.'.
Then I get two matrices with different time-stamps which I want to synchronize now and safe in one single matrix with equal time gaps of 0,250 sec as I explained in my question.
Would be nice if you show me how I have to use this timetable-function.
Thanks in advance!
Morning! Have a look at this and see if it looks alright. I parsed the text file for you directly in matlab.
% Read files
str1 = fileread('data1.txt');
str2 = fileread('data2.txt');
% Change decimal sign
str1 = regexprep(str1,',','.');
str2 = regexprep(str2,',','.');
%parse files
data1 = textscan(str1,'%{hh:mm:ss.SSS}T%f%f%f%f','headerlines',1,'delimiter',{'\t',' '},'multipledelimsasone',1);
data2 = textscan(str2,'%{hh:mm:ss.SSS}T%f%f%f','headerlines',1,'delimiter',{'\t',' '},'multipledelimsasone',1);
% Create timetables
TT1 = timetable(data1{1},data1{2:end});
TT2 = timetable(data2{1},data2{2:end});
% Common time vector
tc = (hours(8)+minutes(57)):milliseconds(250):(hours(8)+minutes(58))';
tc.Format = 'hh:mm:ss.SSS'
%synchronize using linear interpolation
TT3 = synchronize(TT1,TT2,tc,'linear')
You may want to change the interpolation method.
Hey!
Thanks for your help, now it is working.
Great! My pleasure!

Sign in to comment.

More Answers (0)

Categories

Asked:

on 16 Oct 2018

Commented:

on 17 Oct 2018

Community Treasure Hunt

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

Start Hunting!