Fit data recorded with different internal clocks

1 view (last 30 days)
eschre
eschre on 7 May 2021
Edited: Chad Greene on 7 May 2021
I have 2 sets of data, A and B, that records a distance which fluctates ~2ft for 600 seconds. The two devices have a differing internal clocks. Data B time drifts slightly forwards and backwards compared to the time in Data A, which I'm using as the reference.
I am looking to finely match the data between the two, and ultimately create a vector to multiply the time in Data B by to bring the data to a better appoximation of Data A. Then I can apply this vector to adjust other data recorded by the device with the time drift.
I've tried peak fitting, and the part I am stuck on is producing a sequential 'best fit'.
My question is, would there a better way to produce the corrective time drift vector than peak fitting?

Accepted Answer

Chad Greene
Chad Greene on 7 May 2021
Edited: Chad Greene on 7 May 2021
This is an interesting problem. If you can identify a few peaks that occur throughout the 600 s measurement, and those peaks are present in both signals, I think it's actually easy to solve elegantly.
Say in signal A you find five peaks at times
ta_peaks = [51 90 200 306 510];
and you see those same peaks in signal B, but in signal B they appear to occur at
tb_peaks = [49 89 200 307 515];
Start by fitting a relationship between ta and tb:
plot(ta_peaks,tb_peaks,'o')
hold on
xlabel 'time a peaks'
ylabel 'time b peaks'
% Relate time b to time a:
p = polyfit(ta_peaks,tb_peaks,2); % quadratic fit
tb_fit = polyval(p,ta_peaks);
plot(ta_peaks,tb_fit)
Now with the relationship between clock A and clock B, you can use interp1 to interpolate signal B to the timing of signal A's clock.
B_interp = interp1(tb,B,polyval(p,ta));
and now the peaks and overall timing of B_interp should align with the signal A.

More Answers (0)

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!