Curve Fitting Express VI

Owning Palette: Signal Analysis Express VIs

Requires: Full Development System

Computes the coefficients that best represent the input data based on the chosen model type.

Dialog Box Options
Block Diagram Inputs
Block Diagram Outputs
 Add to the block diagram  Find on the palette

Dialog Box Options

ParameterDescription
Model TypeDisplays the data and results according to a mathematical model type you specify. The model type can be any of the following options:
  • Linear—Finds the slope and intercept of the line that best represents the input data set in the least-squares sense.
  • Quadratic—Finds the polynomial curve of order 2 that best represents the input data set in the least-squares sense.
  • Spline—Returns the spline interpolant of length n. n contains the second derivatives of the spline interpolating function g(x) at the tabulated points , where i = 0, 1, …, n – 1.
  • Polynomial—Finds the set of polynomial fit coefficients that best represents the input data set in the least-squares sense.
    • Polynomial order—Must be greater than or equal to zero. If Polynomial order is less than zero, the Express VI returns an error. The default is 5. This option is available only when you select the Polynomial option. The value of polynomial order must observe the following relationship:

      0 m < n – 1,

      where n is the number of sample points, and m is Polynomial order.
  • General least squares linear—Finds the k-dimension linear curve values and the set of k-dimension linear fit coefficients that best represents the input data set using the least-squares solution.
    • Models—Individual functions of the independent variable. This option is available only when you select the General least squares linear option. In the following equation, the models are the functions of x, namely f0(x), f1(x), …, fn – 1(x).

      where

      a = {a0, a1, a2, …, an – 1}

  • Non-linear—Uses the Levenberg-Marquardt algorithm to determine the set of coefficients of the nonlinear model that best represents the input data set in the least-squares sense. The nonlinear model is expressed by a nonlinear function y = f(x,a), where a is the set of coefficients.
    • Independent variable—Specifies the independent variable in Non-linear model. This option is available only when you select the Non-linear option.
    • Maximum iterations—Maximum number of executing iterations. If the Express VI reaches Maximum iterations without finding a solution, the VI returns an error. You must increase Maximum iterations or adjust Initial guesses to find a solution. The default is 500. This option is available only when you select the Non-linear option.
    • Initial guesses—Initial guesses of the solution coefficients. This option is available only when you select the Non-linear option.
  • Current Model—Displays the formula for the currently selected Model Type. This display is available only when you set Model Type to Linear, Quadratic, Spline, Polynomial, or General least squares linear.
  • Non-linear model—String that describes the model equation. This option is available only when you select the Non-linear option.
resultsDisplays values generated for the parameters based on the options you select and values you enter.
Data GraphDisplays the original data and the best fit. The VI calculates best fit using the following equation.

zi = f(xi)A

where A is the best fit coefficient.
Residue GraphDisplays the difference between the original data and the best fit.
Non-linearUses the Levenberg-Marquardt algorithm to determine the set of coefficients of the nonlinear model that best represents the input data set in the least-squares sense. The nonlinear model is expressed by a nonlinear function y = f(x,a), where a is the set of coefficients.
  • Independent variable—Specifies the independent variable in Non-linear model. This option is available only when you select the Non-linear option.
  • Maximum iterations—Maximum number of executing iterations. If the Express VI reaches Maximum iterations without finding a solution, the VI returns an error. You must increase Maximum iterations or adjust Initial guesses to find a solution. The default is 500. This option is available only when you select the Non-linear option.
  • Initial guesses—Initial guesses of the solution coefficients. This option is available only when you select the Non-linear option.

Block Diagram Inputs

ParameterDescription
SignalsSpecifies the observed values of the dependent variable.
LocationsSpecifies the values of the independent variables.
error inDescribes error conditions that occur before this node runs.

Block Diagram Outputs

ParameterDescription
interceptReturns the intercept of the calculated best linear fit.
a1Returns the coefficient of the first-order term.
best fitReturns the fitted data. The VI calculates best fit using the following equation.

zi = f(xi)A

where A is the best fit coefficient.
residualReturns the difference between the original data and the best fit.
mean squared errorReturns the mean square error of the best fit.
error outContains error information. This output provides standard error out functionality.
polynomial coefficientsReturns the coefficients that describe the best polynomial fit. The total number of elements in polynomial coefficients is m + 1, where m is Polynomial order.
slopeReturns the slope of the calculated best linear fit.
a0Returns the constant term of the calculated best quadratic fit.
spline interpolantReturns the second derivative of interpolating function g(x). spline interpolant is the second derivative of interpolating function g(x) at points , i = 0, 1,…, n – 1.
non-linear coefficientsReturns the set of coefficients of the nonlinear model that best represents the input data set in the least-squares sense.
general LS coefficientsReturns the set of coefficients that best represent the input data set in the least-squares sense.
a2Returns the coefficient of the second-order term.

This Express VI operates similarly to the following VIs and functions:

Linear Fit
Polynomial Interpolation
Spline Interpolation