フィルターのクリア

How to generate a smooth derivative after fitting a curve to the data?

33 ビュー (過去 30 日間)
azarang asadi
azarang asadi 2022 年 8 月 1 日
コメント済み: azarang asadi 2022 年 8 月 2 日
Hi all,
I have a set of data which is attached. I used spline function to fit the data and then fnder to take the second derivative and my results ended to be very noisy. I tried fit(x,y,'smoothinhgspline') and I got a noisy derivative. I don't know how to find a smooth derivative. I'd appreciate your suggestions.
Here's my code:
load Data %Matt J added
% using cubic spline
pp = spline(x,y);
derX= fnder(pp,2);
yy = fnval(derX,x);
% using fit
fit1 = fit( x, y, 'smoothingspline' );
[d1,d2] = differentiate(fit1,x);
when I plot yy and d2, none are smooth, they are very noisy.
plot(x,yy,x,d2) %Matt J added
legend('Non-Smoothed','Smoothed'); %Matt J added
  11 件のコメント
Matt J
Matt J 2022 年 8 月 1 日
I've added some lines of code and RUN output to the original post.
Torsten
Torsten 2022 年 8 月 1 日
I get this graph for the second derivative in OCTAVE:
Sorry, it's the first derivative that I included as graphics.

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

採用された回答

Bruno Luong
Bruno Luong 2022 年 8 月 1 日
編集済み: Bruno Luong 2022 年 8 月 1 日
You have to FIT the spline, not interpolate.
For example I use my own tool BSFK avalable in FEX.
load Data.mat;
pp = BSFK(x,y); % FEX
% Check the spline model
xq = linspace(min(x),max(x),100);
pp1 = ppder(pp); pp2 = ppder(pp1); % You might use fnder, I don't have the toolbox
subplot(2,1,1)
plot(x,y,'.r',xq, ppval(pp,xq),'b')
legend('data', 'spline fitting')
subplot(2,1,2)
plot(xq,ppval(pp2,xq),'b')
ylabel('second derivative')
  5 件のコメント
Bruno Luong
Bruno Luong 2022 年 8 月 1 日
編集済み: Bruno Luong 2022 年 8 月 1 日
OK attached is the script, graphical plot and MATLAB derivative data, if you find anything incoherent with the second derivative (computed by 2 ways) please let me know.
If not you can contact the author of whatever the literature you read and ask him/her to correct.
azarang asadi
azarang asadi 2022 年 8 月 2 日
Thank you so much for all the help. appreciated

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

その他の回答 (1 件)

Matt J
Matt J 2022 年 8 月 1 日
編集済み: Matt J 2022 年 8 月 1 日
You can try some different choices of the smoothing parameter,
load Data
% using cubic spline
pp = spline(x,y);
derX= fnder(pp,2);
yy = fnval(derX,x);
plot(x,yy,'--'); hold on
for p=[0.9999,0.999,0.95]
% using fit
fit1 = fit( x, y, 'smoothingspline' ,SmoothingParam=p);
[d1,d2] = differentiate(fit1,x);
legend(string(p))
plot(x,d2);
end; hold off
legend(["Non-Smoothed","p="+string([0.9999,0.999,0.95])])
  1 件のコメント
azarang asadi
azarang asadi 2022 年 8 月 2 日
Thank you so much for all the help. appreciated

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

カテゴリ

Help Center および File ExchangeSpline Postprocessing についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by