how do i find the extremes of an always decreasing curve?

7 views (last 30 days)
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
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.
Pedro Vilas-Boas
Pedro Vilas-Boas on 23 Apr 2016
I think i can't use a linear model, otherwise i will never see the levels i am looking for.

Sign in to comment.

Accepted Answer

Image Analyst
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.
  1 Comment
Pedro Vilas-Boas
Pedro Vilas-Boas on 24 Apr 2016
It isn't exactly what i was looking for but this way i can compare the 2 datas, thank you very much!

Sign in to comment.

More Answers (3)

Walter Roberson
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
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
Pedro Vilas-Boas
Pedro Vilas-Boas on 23 Apr 2016
Ok but i want to get to those levels, just processing the raw data.
Pedro Vilas-Boas
Pedro Vilas-Boas on 23 Apr 2016
The thing is that in real world some of this levels are wrong by few degrees. So i want to find the levels of the practical raw data and compare to the theoretical.

Sign in to comment.


John D'Errico
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.

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!