Curve smoother that holds resulting curve a max distance from original data?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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.
0 Commenti
Risposte (2)
John D'Errico
il 3 Mar 2018
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 Commenti
Image Analyst
il 3 Mar 2018
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
il 3 Mar 2018
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.
0 Commenti
Vedere anche
Categorie
Scopri di più su Smoothing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!