Curve smoother that holds resulting curve a max distance from original data?

1 次查看(过去 30 天)
Is there a smoothing routine (2-d data) where the max resulting distance between the smooth curve and the original data can be specified? Like max delta Y is 50.
Thank you.

回答(2 个)

John D'Errico
John D'Errico 2018-3-3
Short answer: No, there is not. at least not that I know of. There is nothing provided with MATLAB, nor have I even provided that option as part of my SLM toolbox.
Longer answer: There are many reasons why this will be difficult. A big one is "distance" implies the orthogonal distance to the curve, which becomes a moderately difficult problem to solve.
Even if you intend distance to be strictly in y, maximum distance to a list of points will take some effort to write. Were I to write code to solve this, I would probably set it up as a constrained smoothing spline of sorts. So adjust the regularizer weight so that the maximum residual becomes no larger than the given tolerance. Thus you can write a smoothing spline as the solution to a problem
arg min {lambda*(norm(y - yhat)) + (1-lambda)*int(yhat'' ^2)}
So two terms. One is the norm of the residuals. The second term is the integral of the square of the second derivative. When lambda==1, we have an interpolating spline as the result. When lambda=0, all weight goes into making the spline as smooth as possible, so you get a straight line. You could choose lambda such that the result is as smooth as possible, such that the maximum residual does not exceed the target. The code would involve a simple univariate optimization on lambda.
(The above scheme would get nasty if you tried to use orthogonal distance to a spline.)
More to the point as to why it does not exist is nobody seems to want such a tool, at least I've never seen it requested.
So, no there is no tool to do what you want, but feel free to write it. If you do a good job, then post it on the File Exchange.
  2 个评论
David Pesetsky
David Pesetsky 2018-3-3
Perhaps some kind of adjusting scalar to multiply onto a best fit that simply went to far from some raw data points, and the scalar is iterated until we like the proximity to the furthest data point. How to make a scalar (in y-only) that stretches or compresses the curve, but keeps it "centered"?
Image Analyst
Image Analyst 2018-3-3
That sort of sounds similar to sgolayfilt(), like I suggested. Did you try it. I attached my demo to my answer below. Let me know if you need any help on my demo, or if you don't like it, explain why sgolayfilt() is not meeting your needs by giving one counter example (complete with your data file attached). It can be turned into a locally adaptive version if needed.

请先登录,再进行评论。


Image Analyst
Image Analyst 2018-3-3
It may not be possible. What if your waveform is a sine wave between -1 and + 1 except that there is one outlier with a value of a million. No smoothing curve could meet your criteria.
That said, maybe you can just try sgolayfilt() and experiment around with different orders and frame widths to find one that "hugs" your data to the desired amount.

类别

Help CenterFile Exchange 中查找有关 Smoothing 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by