smooth noisy data with spline smoothing

32 ビュー (過去 30 日間)
Dimani4
Dimani4 2023 年 7 月 31 日
コメント済み: Dimani4 2023 年 8 月 1 日
Hi,
I have some noisy function. See attached x and y data. I want to smooth this data and then make a derrivative of that data. When I make derrivative I get in some point Inf so I need to smooth this data. I saw in Curve fitting App that smoothing spline with center and scale option does the job which fits me but I dont quite understand how I do this in the code. I need to do it automatically for every function I'll give to do smooth so I cannot use Curve Fitting Tool every time.
Thank you very much.

採用された回答

Bruno Luong
Bruno Luong 2023 年 7 月 31 日
  2 件のコメント
Bruno Luong
Bruno Luong 2023 年 7 月 31 日
編集済み: Bruno Luong 2023 年 7 月 31 日
Result with your data
x=webread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1446472/x2.txt')
y=webread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1446477/y2.txt')
x=str2num(x);
y=str2num(y);
options = struct('animation', true, 'sigma', 1e-3);
pp = BSFK(x,y,[],[],[],options); % FEX https://www.mathworks.com/matlabcentral/fileexchange/25872-free-knot-spline-approximation?s_tid=srchtitle_BSFK_1
pp1 = ppder(pp); % You might use fnder, I don't have the toolbox
% Check the spline model
close all
figure
xq = linspace(min(x),max(x),100);
plot(x,y,'.r',xq, ppval(pp,xq),'b')
xlabel('x')
ylabel('function y')
yyaxis('right')
plot(xq, ppval(pp1,xq), 'Linewidth', 2)
ylabel('derivative dy/dx')
grid on
legend('data', 'spline fitting','derivative','Location','north')
Dimani4
Dimani4 2023 年 8 月 1 日
Thank you very much Bruno.
Actually I found the way to get the same graph as I got in the picture I attach before.
[curve, goodness, output] = fit(x2u,y2u,'smoothingspline','SmoothingParam',0.998,'Normalize','on');
P this is the smoothing parameter which runs from [0 1]. and center and scale it's I do by 'Normalize', 'on'.

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by