Fit data recorded with different internal clocks
1 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
Chad Greene
2021-5-7
编辑:Chad Greene
2021-5-7
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.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 AI for Signals 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!