How can I do a spline interpolation with tangent continuity

12 次查看(过去 30 天)
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.
load('test.mat');
HV4502=table2array(HV450102);
x452=linspace(0,HV4502(end,2),200);
HV4502S=spline(HV4502(1:end,2),HV4502(1:end,1),x452);
plot(x452,HV4502S,'g');
hold on;
plot(HV4502(1:end,2),HV4502(1:end,1),'r--');
hold on;
G4502=gradient(HV4502S)./gradient(x452);
GG452=gradient(G4502)./gradient(x452);
plot(x452,GG452,'b');
  3 个评论
Michael Schletterer
Thanks for the input. I also tried interp1 but my issue still persisted.
The main problem is that because when deriving the interpolated data (which has these kinks) jumps in the derivation are created. This makes the derivation unusable for me since I want to use the derivation as an input for further queries. (the 2nd derivation should be close to zero at linear poertions)

请先登录,再进行评论。

回答(1 个)

darova
darova 2021-8-8
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
end
x3 = x1;
y3 = spline(x2,y2,x3); % create new spline
plot(x,y,'r')
hold on
plot(x1,y1,'r')
plot(x2,y2,'.b')
plot(x3,y3,'b')
hold off
legend('original data','original spline','added points','spline through added points')

类别

Help CenterFile Exchange 中查找有关 Splines 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by