How can I do a spline interpolation with tangent continuity
13 views (last 30 days)
Hi every one this is my first post on this forum so please don't hate me for formating etc.
I'm trying to derive data from a spline interpolation (twice). The problem I run into here is that there are always kinks in the interpolated data which leads to problems with the derivation.
My question is: Is there a way to do a spline (or other) interpolation of my data where the slope at every interpolated point stays the same (there are no kinks in the interpolated data, tangent continuity at every spline point) ?
This is so i can do a derivation twice to find linear portions of my data.
Thanks for your help in advance.
darova on 8 Aug 2021
What about this? I calculated tangent at each point and added points
dx = 0.1; % adding points distance
x = 0:5;
y = sin(x); % origial data
x1 = 0:.1:5;
y1 = spline(x,y,x1); % refine the data
dy = atan(diff(y)./diff(x)); % find tangent
a = diff(dy)/2 + dy(1:end-1); % find tangent
k = tan(a); % find tangent
x2 = zeros(1,2*numel(x)-2);
x2([1 end]) = x([1 end]); % first and last points
tmp = [x(2:end-1)-dx;x(2:end-1)+dx];% adding points
x2(2:end-1) = tmp(:); % one row
y2 = x2*0;
y2([1 end]) = y([1 end]); % first and last points
for i = 1:length(k)
y2(2*i) = y(i+1) - k(i)*dx; % left point
y2(2*i+1) = y(i+1) + k(i)*dx; % right point
x3 = x1;
y3 = spline(x2,y2,x3); % create new spline
legend('original data','original spline','added points','spline through added points')