function sds = sync_datasets(dss) % load datasets len = length(dss); sds = {}; first_ts = []; last_ts = []; for i=1:len ds = read_syncdata(dss{i}); first_ts(i) = ds(1:1); last_ts(i) = ds(end,1); sds{i} = ds; end % get first and last common timestamp ts0 = max(first_ts); tsend = min(last_ts); for i=1:len ds = sds{i}; ds = ds(ds(:,1) > ts0 + (ds(2,1) - ds(1,1)) / 2 & ds(:,1) < tsend, :); % drop non-common sections ds(:,1) = ds(:,1) - ts0; % substract ts0 from each dataset's timestamp array sds{i} = ds; end % create plot figure(1) % plot samples subplot(2,1,1); marks = ['-', '-o']; PLOTRANGE = 1:100; % get beginning indices for i=1:len ds = sds{i}; ts = ds(:,1); s = size(ds); %for k = 2:s(2); for k = 2:2 %plot(ts(1:100),ds(1:100,k), marks(k-1)); plot(ts(PLOTRANGE),ds(PLOTRANGE,k), 'x'); hold on end end grid on xlabel("Time [s]"); ylabel("Sample"); xlim([ts(PLOTRANGE(1)) ts(PLOTRANGE(end))]); % plot timestamp errors subplot(2,1,2); ds_ref = sds{1}; ts_ref = ds_ref(:,1); for i = 2:len ts_err = ts(PLOTRANGE) - ts_ref(PLOTRANGE); plot(ts_ref(PLOTRANGE), ts_err * 1E+09); hold on end grid on xlabel("Time [s]"); ylabel("Time error [ns]"); xlim([ts(PLOTRANGE(1)) ts(PLOTRANGE(end))]); endfunction