Fill the big gaps in data series

10 views (last 30 days)
Good day!
I have a data series with two big gaps:
For short gaps I usualy used the hermite spline (pchip) or regression (polyfit) but here its not suitable:
Tell me please where can I find a more suitable solution, something like ...
Thanks a lot
  3 Comments

Sign in to comment.

Accepted Answer

John D'Errico
John D'Errico on 9 Aug 2023
Edited: John D'Errico on 9 Aug 2023
The big probem is, your series has little information content in it. :( And of course, you don't give us any data. So I'll make some up. And since I'll be using a few of my own tools that live on the FEX, I'll do it offline.
x = (0:500)';
y = sin(x/300) + randn(size(x))/20;
holes = [200:300,400:450];
unholes = setdiff(1:500,holes);
plot(x(unholes),y(unholes),'b-')
Now, the problem is, if I just connect the first and last points that surround each hole, we get an unwanted effect, in that if those points were high or low, we will get a strange looking curve. It looks instead as if you want a curve that passes through the middle of that noise cloud, following the general trend. That means you need some sort of curve fit, not just an interpolant that looks at the points bounding the holes.
For example, I might have just suggested you use my inpaint_nans tool from the FEX, using the springs option. And it would give you basically that result. You would be unhappy.
Perhas better might be a smoothing spline.
mdl = fit(xuh,yuh,'smoothingspline','smooth',0.0001);
plot(mdl,xuh,yuh)
And that is not at all terrible, but it did depend on my semi-intelligent choice of a smoothing parameter. We could use that function to now fill in the holes, with no problem though.
Another option is my own SLM toolbox. It lives on the File Exchange for free download.
mdl = slmengine(xuh,yuh,'knots',5,'plot','on');
Again, a reasonable curve that will fill in the holes. It needs little in the way of information provided, really only a number of knots to use. Since this is a simple curve, 5 will be entirely reasonable. You really don't care where they fall.
Find SLM here:
Which is better for your specific probem? Probably either could work well enough. There is a strange tweak in your curve at the top end, so I might start with the smoothing spline.

More Answers (0)

Categories

Find more on Polynomials in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!