# how to interpolate between two point of 1d time series data if the difference between any two consecutive point is greater than 25?

7 views (last 30 days)
Yared Daniel on 10 May 2021
Commented: Yared Daniel on 11 May 2021
I have atime seies data like this;
x = [5 10 36 20 17 5 51 60 40 13] and independent variables as follow
fs = 4;
t=0:1/fs:(L-1)/fs;
I want to use spline interpolation between two consecutive point of 'x' means (xi and xi+1) if the difference between two point is greater than 25. for example from the above time series x3-x2= 36-10= 26 therefore i want to interpolate between x2 and x3 with t interval of 0.05 and return all the new time series data.

DGM on 10 May 2021
Maybe something like this:
x = [5 10 36 20 17 5 51 60 40 13];
L = numel(x);
fs = 4;
t=0:1/fs:(L-1)/fs;
idx = find(abs(diff(x))>25);
% i'm just going to build a whole new t vector
tf = [];
for d = 1:numel(idx)
a = idx(d);
if d==1 && a>1
end
% refine this segment
tseg = t(a):0.05:t(a+1);
tf = [tf(1:end-1) tseg];
if d==numel(idx) && a<numel(t)
tf = [tf(1:end-1) t(a):0.25:t(end)]; % pad tail
elseif d<numel(idx) && idx(d+1)>(a+1)
tf = [tf(1:end-1) t(a+1):0.25:t(idx(d+1))]; % pad between
end
end
% interpolate the whole thing
xf = interp1(t,x,tf,'spline')
plot(t,x); hold on
plot(tf,xf)
Yared Daniel on 11 May 2021
Oh my God it worked
Thank you so much for taking time to help me with this matter, you saved my time