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

조회 수: 3 (최근 30일)
Hello every one please help!
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.
anyone please help

채택된 답변

DGM
DGM 2021년 5월 10일
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
tf = t(1):0.25:t(a); % pad head
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)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by