Code covered by the BSD License  

Highlights from
SPLINEFIT

4.44444

4.4 | 18 ratings Rate this file 220 Downloads (last 30 days) File Size: 148.79 KB File ID: #13812
image thumbnail

SPLINEFIT

by Jonas Lundgren

 

31 Jan 2007 (Updated 22 Nov 2011)

Fit a spline to noisy data.

| Watch this File

File Information
Description

Direct spline interpolation of noisy data may result in a curve with
unwanted oscillations. This is particularly bad if the slope of the
curve is important.

A better approach is to reduce the degrees of freedom for the spline
and use the method of least squares to fit the spline to the noisy data.
The deegres of freedom are connected to the number of breaks (knots),
so the smoothing effect is controlled by the selection of breaks.

SPLINEFIT:
- A curve fitting tool based on B-splines
- Splines on ppform (piecewise polynomial)
- Any spline order (cubic splines by default)
- Periodic boundary conditions
- Linear constraints on function values and derivatives
- Robust fitting scheme
- Operates on ND arrays in the same way as SPLINE
- Nonuniform distributions of breaks

M-FILES ALSO INCLUDED:
examples - Examples for splinefit
ppdiff - Differentiate piecewise polynomial
ppint - Integrate piecewise polynomial

MATLAB release MATLAB 7.10 (2010a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (33)
10 Mar 2007 Trevor Rayment

this is a useful piece of code. It does exactly what it says it does. Much appreciated.

05 Aug 2008 M C  
03 Dec 2008 David Villeneuve

Thanks, this provides a simple method to put a smooth line through noisy data. You control the tightness by the number of break points.

22 Jan 2009 P.S. Ramesh

I am trying to generate a smooth curve through noisy data that is periodic at the ends. Can I use this code or is there a version that enforces periodicty

23 Jan 2009 Jonas Lundgren

Sorry, SPFIT don't support periodicity.

06 Feb 2009 Husam Aldahiyat

Good I guess.

13 Mar 2009 Chaos

for images, it's too slow, use better steepest descent. this figure isn't 'noisy' at all. try to pluck an image out of the 'dirt' where the SN is about 12dB

17 Mar 2009 Jonas Lundgren

That's true Chaos. This code was not intended for image processing and the figure shouldn't contain any image noise. How did you do to apply the code to a noisy image?

01 Apr 2009 Amit Ailiani

A very useful code for cubic spline interpolation. Can you please give me the details of the method or any reference to read?

22 Apr 2009 Maryam Ra

A very useful code in Matlab. I am wondering if anyone knows how to call this function from VC++?

28 Apr 2009 David

Works very good to fit noisy 1D data, saved me a lot of effort, thank you!

29 Jul 2009 Steffen Huber

Thank you very much - this code saved me a lot of time. Can you please send me references to the implemented method?

02 Sep 2009 Arthur Hebert

Easy to use, does what it says, saves me a ton of work. Thanks.

12 Sep 2009 Ambrogio Manzino

If point distribution is not homogeneous, probably the software have some problem in L.S. parametres solution.
How cai I use the software in a multiresolution field data?

25 Sep 2009 Jonas Lundgren

Non-uniform distributions of breaks/knots is ok. No problem.

09 Jul 2010 Vinesh Rajpaul  
09 Jul 2010 Vinesh Rajpaul

Useful...however, support for data containing NaNs would be helpful (spline interpolation using built-in MATLAB functions works fine for data containing NaNs)

01 Sep 2010 Sami Aldalahmeh

That's a very useful code. Can you please provide some references for the robust spline fit and the periodic condition options?

02 Sep 2010 Jonas Lundgren

Sami, the robust fitting scheme uses weigthed regression where the weights are computed from previous residuals. It is close to the scheme described by John D'Errico in Optimization Tips and Tricks, section 33 (File ID: #8553).

The periodic condition forces endpoint derivatives to be equal. Example: A cubic spline with endpoints x=1 and x=4 (period length 3) satisfies the conditions y(1) = y(4), y'(1) = y'(4) and y"(1) = y"(4). This is perhaps not evident in the code where the B-splines at the endpoints are matched (pairwise) to have the same shape (and the same derivatives).

11 Nov 2010 Jonathan

Splinefit works great for 1D data, and I see ND support, but it looks like this simply facilitates batch processing several sets of 1D data. Is it possible to use this to generate 2D (an higher dimensional) splines? If so, some examples would be great!

12 Nov 2010 Jonas Lundgren

Jonathan, SPLINEFIT is a curve fitting tool and deals with mappings from R to R^N. SPLINEFIT mimics SPLINE and the ND support can of course be replaced by a for-loop, but that will be less efficient.

If you are looking for a surface fitting tool i can recommend GRIDFIT by John D'Errico or SMOOTHN by Damien Garcia.

17 Feb 2011 Gulcan

Really appreciate the work, thank you. I have a question though. Cubic spline does not go through all knots that I've selected. Is it related to some constraints that I forget to indicate?

18 Feb 2011 Jonas Lundgren

Gulcan, the smoothing spline is not intended to go through the knots/breaks. The curve fits to noisy data in the least square sense, also for knots. Use the constraint argument if you have exact data.

Example: If the curve must go through the points (0,5) and (2,3) use the constraint
con = struct('xc',[0 2],'yc',[5 3])

14 Mar 2011 Stefan

Vey nice tool! Is there also a possibility to enter non-equalities in the constraints?
eg= slope at certain points should be greater then 2

17 Mar 2011 Jonas Lundgren

Stefan, only equality constraints so far.

20 May 2011 Dani

Will it be possible in future versions to add monotonicity constrains to the spline?

23 May 2011 Jonas Lundgren

Dani, I have no plans for more extensions of splinefit. If you have the Optimization Toolbox you should try SLM.

27 Jul 2011 Naveen  
02 Aug 2011 K B  
22 Nov 2011 Fer  
03 Dec 2011 Sander Aerts

Outstanding work with the splinefit function, this is exactely what i have been looking for. Very clean code and good documentation including the published examples.
I also like the ppdiff and the ppint function, how they work seamlessly with the standard piecewise functions.

This one certainly deserves a five star rating, congrats on the job

19 Jan 2012 Moncef

good guess

01 Feb 2012 Elena

Works very well and includes excellent documentation and examples

Please login to add a comment or rating.
Updates
07 Feb 2007

Code cleanup.

21 Feb 2007

Generalization to piecewise polynomial splines of arbitrary order.

11 Dec 2007

Exact conditions added.

25 Sep 2008

Missing pre-allocation added.

17 Dec 2008

New polynomial base eliminating half the unknowns.
Short description of the numerical method added.

18 Dec 2008

Description update.

24 Feb 2009

Update of examples in help.

06 May 2009

A faster routine for cubic splines added.

15 May 2009

Bug fix for SPLINEFIT. Two utilities added.

28 Aug 2009

Description update

23 Jun 2010

New version of SPLINEFIT based on B-splines.

01 Sep 2010

Robust fitting scheme added. Support for data containing NaNs.

01 Jul 2011

Robust fitting parameter added.

22 Nov 2011

New contact info

Tag Activity for this File
Tag Applied By Date/Time
approximation Jonas Lundgren 22 Oct 2008 08:58:47
interpolation Jonas Lundgren 22 Oct 2008 08:58:47
cubic spline Jonas Lundgren 22 Oct 2008 08:58:47
ppval Jonas Lundgren 22 Oct 2008 08:58:47
spline Ned Gulley 03 Dec 2008 17:11:42
spline Jonas Lundgren 18 Dec 2008 00:54:04
noisy data Jonas Lundgren 23 Feb 2009 02:03:53
splinefit Jonas Lundgren 06 May 2009 09:21:33
ppdiff Jonas Lundgren 15 May 2009 09:42:13
ppint Jonas Lundgren 15 May 2009 09:42:13
curve fitting Jonas Lundgren 02 Sep 2010 02:07:51
splinefit abcdef 05 Jun 2011 10:49:34
splinefit miguel 01 Aug 2011 04:38:35
cubic spline Peter 17 Dec 2011 04:09:01

Contact us at files@mathworks.com