How to create a best fit line for data with an aymptote?
53 ビュー (過去 30 日間)
古いコメントを表示
I am currently trying to find the point at which the data reaches its max, the asymptote. However, te data fluctuates, so I need to create a best fit line, since finding the derivative of the data as it is now would not work. How would I programatically go about creating a best fit line for this? I need to be able to acess the equation from the code. The data takes the form of the attached images.
0 件のコメント
回答 (2 件)
Image Analyst
2020 年 1 月 19 日
How about if you just fit a line to the last N points? Like N=20 or N = 10% of the total width or whatever. Or you can figure out how many final points to fit to the line by using diff() and seeing when the difference starts getting small.
N = 20; % Whatever.
coefficients = polyfit(x(end N : end), y(end - N : end), 1)
slope = coefficients(1)
offset = coefficients(2)
% Show the assymptote line over the original graph.
hold on;
xa = x(end N : end);
ya = slope * xa + offset;
plot(xa, ya, 'r-', 'LineWidth', 2);
grid on;
0 件のコメント
John D'Errico
2020 年 1 月 20 日
It partly depends on your goal. Do you just want to best estimate the constant asymptote? Or, are you looking for some function that will approximate the entire curve? The latter is of course far more difficult, since there is no reasonable model that will fit any possible such relationship, especially when it appears that your curve increases smoothly, then suddenly flattens out, with a virtual break in the slope at one point in one of the examples you show. Worse, at the bottom end, it looks like there is some garbage, SOME of the time.
If your goal is to just find the best possible constant asymptote estimate, then it is simple enough. Pick the set of points at the upper end where it appears to be essentially constant, then take the mean of y over that interval. The mean would be a good estimate of a constant function over an interval, the best estimate, in fact. You could be more sophisticated of course, in lots of ways, but that is simplest, and should be entirely adequate.
If your goal is really to get the entire curve fit smoothly, then I might recommend a smoothing spline, as most general. But a smoothing spline will not understand that the upper end of the curve approaches an asymptote. You could build that information into the spline model, but again, that will take more effort. And of course, splines have real problems with transitions from a high slope region into a constant slope region. You will always find ringing there near the transition, unless you use a spline model that includes a monotonicity constraint. Again - that will be more difficult to deal with.
Anyway, your question seems to be how to find a best estimate of the asymptote, which as I said, is not that difficult.
4 件のコメント
Image Analyst
2020 年 1 月 20 日
OK, so I think my strategy should work. Didn't it?
You might be interested in my piecewise linear fit demo. It fits lines to the left part and the right part of a signal and determines where the "kink" is in the curve by identifying the location where the slopes between the two linear fit pieces is most different.
参考
カテゴリ
Help Center および File Exchange で Get Started with Curve Fitting Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!