How can I do a spline interpolation with tangent continuity

12 ビュー (過去 30 日間)
Michael Schletterer
Michael Schletterer 2021 年 4 月 22 日
回答済み: darova 2021 年 8 月 8 日
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
Michael Schletterer 2021 年 4 月 22 日
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)
Boris Blagojevic
Boris Blagojevic 2021 年 8 月 6 日
In case it is still relevant: Maybe derivest might be suited to your problem?

サインインしてコメントする。

回答 (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 Center および File ExchangeSplines についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by