4.4

4.4 | 10 ratings Rate this file 138 downloads (last 30 days) File Size: 9.86 KB File ID: #13812

Fit a spline to noisy data

by Jonas Lundgren

 

31 Jan 2007 (Updated 28 Aug 2009)

Code covered by BSD License  

Fit a spline to noisy data.

Download Now | 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 knots.

CONTENTS:

SPLINEFIT
Fits a cubic spline to noisy data. This routine is faster than PPFIT for large problems. Operates on ND arrays in the same way as SPLINE.

PPFIT
Fits a piecewise polynomial of arbitrary order and regularity to noisy data. Sharp data (boundary conditions or conditions at inner points) can also be forced onto the spline. Operates only on vectors, not ND arrays.

PPDIFF
Differentiate piecewise polynomial.

PPINT
Integrate piecewise polynomial.

In my version of SPLINEFIT the unknowns are function value and slope (y,y') for each break/knot. To get a cubic spline with continuous second derivative I add linear constraints for the continuity of y" at each inner break. So the problem solved is actually a least squares problem with equality constraints.
 

See also IMMOPTIBOX at http://www2.imm.dtu.dk/~hbn/immoptibox by Hans Bruun Nielsen. This is a toolbox for optimization and data fitting and among other useful tools there is a SPLINEFIT tool based on B-splines.

MATLAB release MATLAB 7.5 (R2007b)
Zip File Content  
Other Files license.txt,
splinefit/ppdiff.m,
splinefit/ppfit.m,
splinefit/ppint.m,
splinefit/readme.txt,
splinefit/splinefit.m
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (15)
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

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.

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

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
ppval Jonas Lundgren 22 Oct 2008 08:58:47
cubic spline 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
ppfit 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
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com