splinefit (MathScript RT Module Function)

LabVIEW 2012 MathScript RT模块帮助

版本日期:June 2012



Owning Class: approximation

Requires: MathScript RT Module


bestfit = splinefit(x, y)

bestfit = splinefit(x, y, balance)

bestfit = splinefit(x, y, balance, weights)

Legacy Name: csaps


Returns the curve fit of data using a weighted cubic spline method with a balance parameter that allows you to trade smoothness for fit accuracy.




Name Description
x Specifies the independent values. x is a real, double-precision vector.
y Specifies the dependent values. y is a real, double-precision vector.
balance Specifies the balance between the smoothness of the cubic spline fit and the accuracy with which it fits the observations. balance must fall within the range [0, 1]. If balance is 0, the cubic spline fit is equivalent to a linear fit. If balance is 1, the cubic spline fit interpolates between the data points. If balance is out of the range [0, 1], LabVIEW calculates an appropriate value for balance automatically according to the values of x.
weights Specifies the weights for the observations (y, x). weights is an array. size(weights) must equal size(x). If you do not specify weights, LabVIEW sets all elements of weights to 1. If an element in weights is less than 0, LabVIEW uses the absolute value of the element.


Name Description
bestfit Returns the values of the fitted curve that LabVIEW evaluates at the points in x. bestfit is a real, double-precision vector.


This VI minimizes the following function to fit the observations (x, y):

p*sum{w[i]*(y[i] - f(x[i]))^2, i = 0, n-1} + (1 - p)*integral{f''(x)^2(dx), x[0], x[n-1]}

where p is the balance parameter, w[i] is the ith element of weights, y[i] is the ith element of y, x[i] is the ith element of x, integral{f''(x)^2(dx), x[0], x[n-1]} calculates a definite integral of f''(x) with a low limit of x[0] and an upper limit of x[n-1], and f''(x) is the second-order derivative of the cubic spline function, f(x).

If p equals 0, the fitted model is equivalent to a linear model. If p equals 1, the fitting is equivalent to cubic spline interpolation. To make the fitted curve both close to the observations and smooth, p must fall in the range [0, 1]. The closer p is to 0, the smoother the fitted curve. The closer p is to 1, the closer the fitted curve is to the observations.

The following table lists the support characteristics of this function.

Supported in the LabVIEW Run-Time Engine Yes
Supported on RT targets Yes
Suitable for bounded execution times on RT Not characterized


X = 0:6;
Y = [pi/2, 0, 1, 0, -1, 0, pi/2];
XX = 0:0.1:6;
YY = spline(X, Y, XX);
YY = YY + 0.2*rand(1, length(YY));

fitY1 = splinefit(XX, YY, 0.7);
fitY2 = splinefit(XX, YY, 0.98);

plot(X, Y, 'o', XX, YY, '-', XX, fitY1, '-', XX, fitY2, '-')

Related Topics