Effacer les filtres
Effacer les filtres

Can I make a spline both smoothing *and* periodic?

4 vues (au cours des 30 derniers jours)
Sven
Sven le 2 Déc 2012
Hi all,
I would like to make a smoothing spline through data, and enforce point and gradient equality at either end of my spline. Here's the data:
XYpts = [...
10 5 -5 -10 -5 0 10
0 9 9 0 -9 0 0];
figure, plot(XYpts(1,:), XYpts(2,:),'bo')
axis equal, grid on, hold on
And here I can do a smoothing spline without the constraints to make it periodic (note that it smooths the original data nicely, but meets a nasty sharp turn at the end):
dt = sum((diff(XYpts,[],2).^2));
t = cumsum([0,dt.^(0.25)]);
smoothingSpline = spaps(t,XYpts,1);
fnplt(smoothingSpline,'-r.')
And here I can do an interpolating spline with the correct continuity constraints I'm looking for:
interpolatingSpline = csape(t,XYpts,'periodic')
fnplt(interpolatingSpline,'-g.')
But neither of these do both at the same time (smooth the data and enforce continuity). Can you help?
The only way I can think of so far is a bit messy: repeat the starting/ending points of my data so that the smoothed spline wraps back over itself, and then only sample it within the "original" domain. Is there a better/cleaner way?
Thanks, Sven.

Réponse acceptée

Matt J
Matt J le 2 Déc 2012
Modifié(e) : Matt J le 2 Déc 2012
This FEX file advertises all kinds of convenient options for constraining spline fits,
You need the Optimization Toolbox, though.
  1 commentaire
Sven
Sven le 3 Déc 2012
Ha, thanks Matt, I actually had this toolbox, just never thought to apply it to 2d data.
The (minor) downside is that the fit needs to be applied separately to each X,Y channel, but it certainly fits the bill.
Thanks, Sven.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by