0
votes

I have a MATLAB script that I would like to run in Octave. But it turns out that the timeseries and synchronize functions from MATLAB are not yet implemented in Octave. So my question is if there is a way to express or replace these functions in Octave. For understanding, I have two text files with different row lengths, which I want to synchronize into one text file with the same row length over time. The content of the text files is:

Text file 1:

1st column contains the distance

2nd column contains the time

Text file 2:

1st column contains the angle

2nd column contains the time

Here is the part of my code that I use in MATLAB to synchronize the files.

ts1 = timeseries(distance,timed);
ts2 = timeseries(angle,timea);
[ts1 ts2] = synchronize(ts1,ts2,'union');
distance = ts1.Data;
angle = ts2.Data;

Thanks in advance for your help.

edit:

Here are some example files.

input distance

input roation angle

output

1
can you put a simple example of the intended input and output? - Tasos Papastylianou
Hi, I have added some example files under my question. - Marc

1 Answers

1
votes

The synchronize function seems to create a common timeseries from two separate ones (here, specifically via their union), and then use interpolation (here 'linear') to find interpolated values for both distance and angle at the common timepoints.

An example of how to achieve this to get the same output in octave as your provided output file is as follows.

Note: I had to preprocess your input files first to replace 'decimal commas' with dots, and then 'tabs' with commas, to make them valid csv files.

Distance_t = csvread('input_distance.txt', 1, 0);         % skip header row
Rotation_t = csvread('input_rotation_angle.txt', 1, 0);   % skip header row

Common_t   = union( Distance_t(:,2), Rotation_t(:,2) );

InterpolatedDistance = interp1( Distance_t(:,2), Distance_t(:,1), Common_t );
InterpolatedRotation = interp1( Rotation_t(:,2), Rotation_t(:,1), Common_t );

Output = [ InterpolatedRotation, InterpolatedDistance ];
Output = sortrows( Output, -1 );   % sort according to column 1, in descending order
Output = Output(~isna(Output(:,2)), :);   % remove NA entries

(Note, The step involving removal of NA entries was necessary because we did not specify we wanted extrapolation during the interpolation step, and some of the resulting distance values would be outside the original timerange, which octave labels as NA).