how do i find the extremes of an always decreasing curve?
7 views (last 30 days)
Show older comments
Pedro Vilas-Boas
on 23 Apr 2016
Commented: Pedro Vilas-Boas
on 24 Apr 2016
Hello you all,
so i have this project im working on where i have several angles measured with a robot's head.

I did the polyfit function to find a curve and see how this measurements behave with distance.

Now i want to compare this last curve with the expected curve i am suppose to get:

Of course the practical curve doesn't exactly fit the theoretical one because the measurement process has too much error but especially in the beginning of the practical curve it s possible to see some oscillations which i think are the equivalent of the steps in the theoretical one.
So i want to find some way of knowing where exactly in the practical curve those small oscillations peak.
I tried checking the first derivative but i couldn't get the points because the first derivative is almost always negative.
Another approach i tried to make is to see the variation of the first derivative, but also couldn't get anywhere.
Anyone has any idea how to solve this?

8 Comments
Star Strider
on 23 Apr 2016
It seems to me then that you need to regress the theoretical and experimental data with a linear model. Then show that the two are not significantly different. The F statistic is likely best for this. See the regress and related functions (Statistics and Machine Learning Toolbox) for details.
Accepted Answer
Image Analyst
on 24 Apr 2016
Try this:
% Create sample data.
A = 90 : -1 : 40;
% Plot it
plot(A, 'b*-');
grid on;
hold on;
% Define the values that the data SHOULD take on.
levels = [90, 85, 79, 73, 68, 64, 58, 53, 48, 42]
% Find which element of levels is closest to A and assign that to quant_A
for k = 1 : length(A)
[~, index] = min(abs(A(k)-levels));
quant_A(k) = levels(index);
end
% Plot the quantized data.
plot(quant_A, '*-', 'Color', [0,0.5,0]);

The blue is your original, noisy data. The green is how the data got rounded so that it got forced to the nearest desired/perfect level that you expect it should be.
More Answers (3)
Walter Roberson
on 23 Apr 2016
I would not recommend polyfit() for that kind of data.
As you have physical movement constraints that possibly impose some smoothness to the movement, it might be reasonable to use a spline. You can find the derivative of a spline using http://www.mathworks.com/matlabcentral/fileexchange/24996-spline-derivative
Image Analyst
on 23 Apr 2016
I don't think you did a polyfit() on the entire set of data unless you used an order that was ridiculously high, which would be insane. I think you must have done a piecewise/moving polynomial fit, which is what a Savitzky-Golay filter is, and that is done by the function sgolayfilt() in the Signal Processing Toolbox.
Anyway, it seems your smooth blue curve is supposed to actually look like that stair step green function according to what you tell us. But I don't see any substantial oscillations or peaks in the blue curve. There are in the red raw data but I thought you didn't want to use that and that's why you smoothed it to obtain the improved blue curve. So are you now trying to figure out how to change the measured and processed blue curve into the desired green stair steps?
Finally, what is the last graph that shows a single blue curve for?
4 Comments
John D'Errico
on 23 Apr 2016
Edited: John D'Errico
on 23 Apr 2016
This will be a fairly difficult problem to solve in a stable way. You are trying to fit a curve to pretty noisy data. There are some points with sufficiently high residuals that it will drag your curve around mercilessly. Do NOT however, use a high order polynomial to fit this curve. Down that path lies problems.
I'd like to actually test out some ideas on your data, but you have not posted the data itself. For example, there are some variations of smoothing spline that one might try. As well, there are robust modeling schemes to try to reduce the impact of that noise, because it appears there are some outliers. So it is a bit difficult to know what I would recommend.
No matter what you do though, finding small deviations from a noisy curve will be a difficult task to do at all well.
0 Comments
See Also
Categories
Find more on Linear and Nonlinear Regression in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!