how to remove noise from curves and take their derivates

10 ビュー (過去 30 日間)
KIRAN noor
KIRAN noor 2023 年 1 月 16 日
コメント済み: Rena Berman 2024 年 6 月 5 日
Hello,
I have some curves which are not smooth, I have to take their derivative. therefore first requirement is remove the noise and take the derivative.
I am doing this work through curve fitting using rat35, poly9 etc. and then taking the derivative. but everytime i run the script, result changes slighty.
i am attaching the curve , their zoom version and then warnings which appeared in workspace, would you please guide me how i should handle this issue.
Regards,
Kiran

採用された回答

Bruno Luong
Bruno Luong 2023 年 1 月 16 日
編集済み: Bruno Luong 2023 年 1 月 16 日
I would chose spline fitting rather than polynomial (bad) or rational.
Look at the shape of your data, I doubt any simple analytic model can fit it well.
c=readtable('100_li_4th_discharge1.xlsx');
x=table2array(c(:,1));
y=table2array(c(:,2));
% https://fr.mathworks.com/matlabcentral/fileexchange/25872-free-knot-spline-approximation
pp=BSFK(x,y,[],[],[],struct('sigma',1e-9,'KnotRemoval','none'));
ppd=ppder(pp); % derivative
xi=linspace(min(x),max(x),1024);
figure
h1=plot(x,y,'.g',xi,ppval(pp, xi),'r');
yyaxis right
h2=plot(xi,ppval(ppd,xi),'k')
legend([h1; h2],'data','fit','derivative');
  3 件のコメント
Bruno Luong
Bruno Luong 2023 年 1 月 17 日
編集済み: Bruno Luong 2023 年 1 月 17 日
ppd is dy/dx, if you want dx/dy it is 1./ppd.
BTW in this case you could fit x vs y instead of the opposite.
c = readmatrix('https://fr.mathworks.com/matlabcentral/answers/uploaded_files/1265640/100_li_4th_discharge1.xlsx')
Q=c(:,1);
V=c(:,2);
% https://fr.mathworks.com/matlabcentral/fileexchange/25872-free-knot-spline-approximation
pp=BSFK(V,Q,[],[],[],struct('sigma',1e-9,'KnotRemoval','none'));
ppd=ppder(pp); % derivative
yi=linspace(min(V),max(V),1024);
figure
h1=plot(V,Q,'.g',yi,ppval(pp, yi),'r');
xlabel('V')
ylabel('Q')
yyaxis right
h2=plot(yi,ppval(ppd,yi),'k')
legend([h1; h2],'data','fit','derivative');
ylabel('dQ/dV)*')
Matt J
Matt J 2023 年 1 月 17 日
@IQRA KIRAN If it worked, then you should Accept-click the answer.

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

その他の回答 (2 件)

Matt J
Matt J 2023 年 1 月 16 日
編集済み: Matt J 2023 年 1 月 16 日
If you provide a StartPoint in your fit options, the warning will go away and the fit will be the same when you rerun.
However, the differences you see with each run are not meaningful. You get a slightly different result because the start point of the iterative fitting process is different each time, but in this case they all seem to be converging to essentially the same curve.
  6 件のコメント
Matt J
Matt J 2023 年 1 月 16 日
Why would you need another way?
Matt J
Matt J 2023 年 1 月 16 日
編集済み: Matt J 2023 年 1 月 16 日
Use a lower order polynomial so that the parameter estimates won't be as sensitive. Or use a non-polynomial model. Image Analyst suggested an exponential fit. A smoothing spline might also work,
Basically, you should experiment with other models to see if a stiffer model would work.

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


Image Analyst
Image Analyst 2023 年 1 月 16 日
You can use sgolayfilt, which is a sliding polynomial fit within the sliding window, however if I were going to take the derivatives of your curves, I'd fit them to an exponential decay (to get a formula with numerical coefficients), which has a known derivative. See my attached exponential decay demo which uses fitnlm. I have many other functions fit with fitnlm, so it you want them, just ask.

カテゴリ

Help Center および File ExchangeGet Started with Curve Fitting Toolbox についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by