filtering by the second derivative?
8 views (last 30 days)
Show older comments
Steve Miller
on 6 Jan 2020
Commented: Walter Roberson
on 6 Jan 2020
I have an array, and I'm trying to figure out how to mark the values where the second derivative is above a threshold. To get the second derivative I'm doing
diff(diff(array)), the problem is that creates a result of length(array)-2, and I want to created a logical array for the original array.
For example, with
arr = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34];
and a filter of x < 2, I'd like to produce:
[1,1,1,1,1,1,1,0,0,0]
since the second derivative is
[-1,1,0,1,1,2,3,5]
Hopefully that makes sense.
0 Comments
Accepted Answer
Walter Roberson
on 6 Jan 2020
gradient(gradient(arr)) < 2
Watch out for < 2 compared to <= 2
2 Comments
Walter Roberson
on 6 Jan 2020
Well, then, you are stuck. diff() will never return an array of full size equal to its input (except in the degenerate case diff([]) in which case the result is [] which is equal in size to the input.) Therefore if you define taking the derivative as using diff(), then you have boxed yourself into a corner.
Mathematically, diff() is only one way among several to numerically estimate derivative. It is not considered to be the best numeric derivative because at any one point, it is only using two adjacent points to do the estimate, instead of using points before and after to do the estimation. https://en.wikipedia.org/wiki/Finite_difference
gradient() uses central difference except at the two edges. Central difference is often considered a closer numeric approximation to derivative than what is used by diff()
More Answers (0)
See Also
Categories
Find more on Interpolation in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!