Best method to find maximum and minimum second derivatives of function
7 次查看(过去 30 天)
显示 更早的评论
Hello,
I created this script to find the maximum and minimum second derivatives of a given array. I was wondering what possible improvements there could be. A sample image is attached for reference.
f = tracks_2(:,2);
windowWidth = 37;
polynomialOrder = 3;
f = sgolayfilt(f, polynomialOrder, windowWidth);
plot(f);
f1 = diff(f); %diff intstantly returns the derivative
plot(f1)
f1 = sgolayfilt(f1, polynomialOrder, 37);
f2 = diff(f1); %second derivative
plot(f2)
f2 = sgolayfilt(abs(f2), polynomialOrder, 15);
[pks,locs] = findpeaks(f2,'MinPeakProminence',0.05); %maximum peaks
plot(1:length(f),f,locs,f(locs),'*')
2 个评论
John D'Errico
2020-5-17
编辑:John D'Errico
2020-5-17
IF you are going to smooth your data using a Savitsky-Golay filter, then you should arguably use a similar filter to give you the estimated first and second derivatives directly.
Note that I posted a function called movingslope on the file exchange. It does exactly that, at least for the first derivative.
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!