Reputation: 13
I am having trouble interpolating a timeseries of temperature data I have. The time variable increases nonmonotomic due to instrument drift. For example it starts at the correct time and samples every 40seconds as it is programmed to.
YYYY MM DD HH MM SS
2013 9 29 17 0 1
2013 9 29 17 0 41
2013 9 29 17 1 21
2013 9 29 17 2 1
2013 9 29 17 2 41
2013 9 29 17 3 21
2013 9 29 17 4 1
2013 9 29 17 4 41
2013 9 29 17 5 21
2013 9 29 17 6 1
2013 9 29 17 6 41
2013 9 29 17 7 21
2013 9 29 17 8 1
Then as time passes, it slowly drifts to sample at different timings like below.
2013 11 3 19 0 45
2013 11 3 19 1 25
2013 11 3 19 2 5
2013 11 3 19 2 45
2013 11 3 19 3 25
2013 11 3 19 4 5
2013 11 3 19 4 45
2013 11 3 19 5 25
2013 11 3 19 6 5
Worst, near the battery life of the instrument, it samples at more random timings, ie.
2013 11 19 0 14 0
2013 11 19 0 15 28
2013 11 19 0 16 56
2013 11 19 0 18 24
2013 11 19 0 19 52
2013 11 19 0 21 20
2013 11 19 0 22 48
2013 11 19 0 24 16
2013 11 19 0 25 44
2013 11 19 0 27 12
2013 11 19 0 28 40
2013 11 19 0 30 8
2013 11 19 0 31 36
2013 11 19 0 33 4
I will like to use this data to interpolate to every 2 minutes because currently when I use this data for FFT and PSD analysis in Matlab, I do not get any peaks in PSD as expected due to daily temperature fluctuations.
Since my data is in datenum() of the datevectors I showed, I used the code below to get a new Yi that is every 2min (every 0.0014 datenum).
xi=(x(1,1):0.0014:x(end,1));
yi=interp1(x,y,xi);
where x is the datenum vector ie.
735506.708344907
735506.708807870
735506.709270833
735506.709733796
735506.710196759
735506.710659722
735506.711122685
735506.711585648
735506.712048611
735506.712511574
and y is temperature data each time sample comes with like so,
32.4086025192727
32.4052088117713
32.4051005865126
32.4043088697477
32.4049974142611
32.4046963702913
32.4038950877519
32.4047969012421
32.4055051003980
32.4062010783006
Could I please get your help to somehow interpolate the temperature data to a 2min interval data set? I will appreciate any help and guidance to solve this problem. Thank you so much.
Respectfully, Aya
Upvotes: 0
Views: 109
Reputation: 13
For my data, I had to clean the timeseries before I could interp1() to xi. Here are the things I needed to do... Sort through, fill in gaps (NaN), and only have one measurement per time sample.
A_sorted=sortrows(A);
A_f=fixgaps(A_sorted);
[C,ia,ic]=unique(A_f);
A_ia=A_f(ia,:)
Upvotes: 1