Question: How to locally interpolate NaN over short lengths?
I have a time series ("x" data is selectively equal in time "t") that have NaN blocks. For instance:
x = [ 1 2 4 2 3 15 10 NaN NaN NaN NaN 2 4 NaN 19 25] t = [0.1 0.2 0.3 ...etc..]
I want to interpolate over NaN.
The most basic approach is to simply linearly interpolate from the leftmost data point to the rightmost data point. For instance. a string from x = 10 to x = 2 and 4 NaN values โโwill be assigned the values โโfrom the string.
The length of the time series is ~ 1.5 million with ~ 10000 NaN, so I do not want to include data (in interpolation) that are far from the places of NaN. Some of the NaNs have a length of 1000-2000.
X(isnan(X)) = interp1(find(~isnan(X)), X(~isnan(X)), find(isnan(X)), 'linear');
will linearly interpolate over NaN using the entire time series.
How would I interpolate locally? Linear should be enough. Perhaps linear interpolation includes several points to the left and to the right of NaN blocks (possibly 100-200 points). Perhaps the natural neighbor or spline algorithm (?) Is more suitable; I have to be careful not to add abnormal behavior to the time series (for example, interpolation adding dummy โpowerโ to the frequency).
UPDATE: A time series is a record of the minute temperature for a year. Linear interpolation is sufficient; I just need to fill in the blanks with a length of ~ 6-7 hours of NaN (I have data before the NaN faults and after the NaN spaces).
source share