How do I interpolate a set of data and change the timestamp to specific points in time?

19 views (last 30 days)
I have several sets of data coming from different sensors which register data at different time-intervals. I want to synchronize the time of all the data down to milliseconds, and I want to interpolate the values for the timestamps so they match the new timestamp.
Some sensors register a new value every hour, while others register for every 10th, 8th, 30th, etc, minutes.
  4 Comments
Peter Perkins
Peter Perkins on 3 Aug 2018
Anders, I think we'd have to know what;s in your times. Are there duplicates?
You may need to use retime to get rid of those before interpolating -- retime to a target time vector that's unique(tt.Time), and reconcile the multiple values using 'mean', 'max', or whatever.
Anders Teigmoen
Anders Teigmoen on 4 Aug 2018
I managed to solve the issue. There were no duplicates, but a NaN lurking in my data. Thank you for the response.

Sign in to comment.

Answers (1)

KSSV
KSSV on 12 Jul 2018
Edited: KSSV on 12 Jul 2018
Read about interp1. With this you can get all the data into same time stamps.
An example:
t1 = (0:10:100) ;
y1 = rand(size(t1)) ;
t2 = 0:5:100 ;
y2 = rand(size(t2)) ;
plot(t1,y1,'.r')
hold on
plot(t2,y2,'.b')
% interpolation
ti = 0:1:100 ;
y1i = interp1(t1,y1,ti) ;
y2i = interp1(t2,y2,ti) ;
plot(ti,y1i,'r')
plot(ti,y2i,'b') ;

Community Treasure Hunt

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

Start Hunting!