A C-implementation for MATLAB of Woltring's GENERAL CROSS VAILIDATION SPLINE smoother To use it, place files GCVSPL.MEX, GCVSPL.M, and GCVSPL2.M in Matlab's path. Please Note: the code works fine for smoothing data, but there is an error in the differentiation code. It is in the process of being corrected. When calling the function, input vectors Y, X, and smoooth_para MUST be column vectors. If they aren't, not only will the function not return the correct value, but the MEX file can cause an internal Matlab cache error or even cause Matlab to abort. Also, it should be noted that the input values should be copies of the original variables as the GCVSPL code sometimes corrupts the input values. The GCVSPL code for resampling (which would use the following input form): [YY[, PP[, ERR]]]=gcvspl (Y, X, XX, smooth_para[]) i.e. smooth Y at X, return YY, PP at XX (resampling) does not seem to work. However, as long as one takes care to avoid these limitations, the code is completely functional. The GCVSPL MEX Code was hacked together from code found at: http://www.kin.ucalgary.ca/isb/software/ Files which should be included in this zip archive are: ------------------------------------------------------------------------------ | FILE | SIZE | AUTHOR | DESCRIPTION | ------------------------------------------------------------------------------ | CMEX.BAT | 19,139 | Mathworks | Used to compile GCVSPL.C | ------------------------------------------------------------------------------ | GCVSPL.C | 10,053 | C.X. Tian | MEX interface to GCVSPL | ------------------------------------------------------------------------------ | GCVSPL.M | 1,012 | C.X. Tian | Short description of GCVSPL.MEX | ------------------------------------------------------------------------------ | GCVSPL2.M | 10,685 | C.X. Tian | Full description of GCVSPL.MEX | ------------------------------------------------------------------------------ | GCVSPL.MEX | 29,192 | David Carta | Matlab MEX implementation of GCVSPL | ------------------------------------------------------------------------------ | NDIFF.ZIP | 3,812 | David Carta | Matlab functions for smoothing and | | | | | differentiation using Lagrangian | | | | | interpolation formulas | ------------------------------------------------------------------------------ | README.TXT | 4,690 | David Carta | This File | ------------------------------------------------------------------------------ | TWISK.C | 43,961 | Dirk Twisk | Base C implementation of GCVSPL | ------------------------------------------------------------------------------ C.X. Tian : tian@motorcortex.eas.asu.edu Dirk Twisk : twisk@iw6.wt.tno.nl The code provided by C.X. Tian for the MEX interface on the ISB Web site was incomplete. From Tian's code and Twisk's C code, I was able to construct a functioning MEX file. I also made a slight modification to Tian's code which allowed not only the smoothed data to be returned, but the nth derivative as well using an input parameter to specify the derivative. I included my CMEX.BAT file which I used to run WATCOM C compiler v10.6. If you are using another compiler and wish to recompile, you will need to modify the CMEX.BAT file, or use the one in your MATLAB directory. The CMEX.BAT file included is a slight modification of one available at : ftp://ftp.mathworks.com/pub/tech-support/library/extern/CMEX.BAT This modification was made because I do not have the Matlab Compiler. I have modified all files in this archive to some degree or another, either for functional improvement or to make the code compile correctly. However since little of the source code that this came from is mine, I provide no guarantee that it will work perfectly, but I have checked it out and it seems to work as I would expect. For taking numerical derivatives of noisy data, I have found that using a standard 5-point Lagrangian intrerpolation formula after using this GCVSPL code to smooth the data gives better results than using GCVSPL to do the differentiation directly. Your mileage may vary. -David Carta dcarta@ucsd.edu 03/05/97 The following is the output from the command-line output of CMEX.BAT The warnings do not cause any trouble with compiling. ____________________________________________________________________ C:\>cmex gcvspl.c C:\>C:\WATCOM\binnt\wcc386.exe -7 -3s -ei -DMATLAB_MEX_FILE @INCLUDE_PATH gcvspl.c WATCOM C32 Optimizing Compiler Version 10.6 Copyright by WATCOM International Corp. 1984, 1996. All rights reserved. WATCOM is a trademark of WATCOM International Corp. gcvspl.c: 267 lines, included 3231, 0 warnings, 0 errors Code size: 9542 C:\>C:\WATCOM\binnt\wlink.exe @wcmex.rsp WATCOM Linker Version 10.6 Copyright by WATCOM International Corp. 1985, 1996. All rights reserved. WATCOM is a trademark of WATCOM International Corp. loading object files searching libraries Warning(1027): file C:\WATCOM\lib386\dos\clib3s.lib(_8087386): redefinition of __8087 ignored Warning(1027): file C:\WATCOM\lib386\dos\clib3s.lib(fclose): redefinition of fclose ignored creating a Phar Lap relocatable executable C:\> ____________________________________________________________________