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

2 vues (au cours des 30 derniers jours)
Yared Daniel le 10 Mai 2021
Commenté : Yared Daniel le 11 Mai 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.
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponse acceptée

DGM le 10 Mai 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)
##### 1 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
Yared Daniel le 11 Mai 2021
Oh my God it worked
Thank you so much for taking time to help me with this matter, you saved my time

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Interpolation dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by