clc, clear

% Path to local datalake
datalake_path = "F:\datalake\AABBCCDD\";

% Paths to time-series data sets
gnss_speed_path = fullfile(datalake_path, "CAN2_GnssSpeed");
obd_rpm_path = fullfile(datalake_path, "CAN1_OBD2_EngineSpeed");

% Create datastore for time-series data set "GnssSpeed"
ds_gnss_speed = parquetDatastore(gnss_speed_path, "RowTimes", "t", "IncludeSubfolders", true );

% Create datastore for time-series data set "EngineSpeed"
ds_obd_rpm = parquetDatastore(obd_rpm_path, "RowTimes", "t", "IncludeSubfolders", true );

% Create tall arrays (files not loaded into memory)
gnss_speed = tall(ds_gnss_speed);
obd_rpm = tall(ds_obd_rpm);

% Create a common timebase using the timestamps from gnss_speed and linear interpolation for obd_rpm
tt_common = synchronize(gnss_speed, obd_rpm, 'first', 'linear');

% Now with a common timebase, we can do calculations accross the two time series
gear = tt_common.Speed ./ tt_common.S1_PID_0C_EngineRPM;

% Plot gear ratio calculation over time
figure(1)
plot(tt_common.t, gear)