Best method to find maximum and minimum second derivatives of function
14 views (last 30 days)
Show older comments
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 Comments
John D'Errico
on 17 May 2020
Edited: John D'Errico
on 17 May 2020
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.
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!