Last Modified: December 18, 2017

Finds the line that best represents an input signal or input data set using a specific fitting method.

Dependent values representing the *y*-values of the data set.

This input accepts a double-precision, floating-point number or a 1D array of double-precision, floating-point numbers.

This input changes to **signal** when the data type is a waveform or a 1D array of waveforms.

Independent values representing the *x*-values of the data set.

This input accepts a double-precision, floating-point number or a 1D array of double-precision, floating-point numbers.

This input is available only if you wire a double-precision, floating-point number or a 1D array of double-precision, floating-point numbers to **y** or **signal**.

Value that determines when to stop the iterative adjustment of the slope and intercept when you use the Least Absolute Residual or Bisquare methods.

If **tolerance** is less than or equal to 0, this node sets **tolerance** to 0.0001.

This input is available only if you wire one of the following data types to **signal** or **y**.

How tolerance Affects the Outputs with Different Fitting Methods

For the Least Absolute Residual method, if the relative difference between **residue** in two successive iterations is less than **tolerance**, this node returns the resulting **residue**. For the Bisquare method, if any relative difference between **slope** and **intercept** in two successive iterations is less than **tolerance**, this node returns the resulting **slope** and **intercept**.

**Default: **0.0001

Length of each set of data. The node performs computation for each set of data.

When you set **block size** to zero, the node calculates a cumulative solution for the input data from the time that you called or initialized the node. When **block size** is greater than zero, the node calculates the solution for only the newest set of input data.

This input is available only if you wire a double-precision, floating-point number to **signal** or **y**.

**Default: **100

Error conditions that occur before this node runs.

The node responds to this input according to standard error behavior.

Standard Error Behavior

Many nodes provide an **error in** input and an **error out** output so that the node can respond to and communicate errors that occur while code is running. The value of **error in** specifies whether an error occurred before the node runs. Most nodes respond to values of **error in** in a standard, predictable way.

**Default: **No error

Upper and lower constraints for the slope and intercept of the calculated best linear fit.

This input is available only if you wire one of the following data types to **signal** or **y**:

Lower bound for the slope.

**Default: **-Infinity

Upper bound for the slope.

**Default: **Infinity

Lower bound for the intercept.

**Default: **-Infinity

Upper bound for the intercept.

**Default: **Infinity

Method of fitting data to a line.

This input is available only if you wire one of the following data types to **signal** or **y**:

Name | Value | Description |
---|---|---|

Least Square | 0 | Uses the least square method. |

Least Absolute Residual | 1 | Uses the least absolute residual method. |

Bisquare | 2 | Uses the bisquare method. |

Algorithm for the Least Square Method

The least square method of fitting finds the slope and intercept of the linear model by minimizing residue according to the following equation:

$\frac{1}{N}\underset{i=0}{\overset{N-1}{\sum}}{w}_{i}{({f}_{i}-{y}_{i})}^{2}$

where

*N*is the length of**y**or the number of data values in a waveform*w*_{i}is the*i*^{th}element of**weight***f*_{i}is the*i*^{th}element of**best linear fit***y*_{i}is the*i*^{th}element of**y**or the*i*^{th}data value in a waveform

Algorithm for the Least Absolute Residual Method

The least absolute residual method finds the slope and intercept of the linear model by minimizing residue according to the following equation:

$\frac{1}{N}\underset{i=0}{\overset{N-1}{\sum}}{w}_{i}|{f}_{i}-{y}_{i}|$

where

*N*is the length of**y**or the number of data values in a waveform*w*_{i}is the*i*^{th}element of**weight***f*_{i}is the*i*^{th}element of**best linear fit***y*_{i}is the*i*^{th}element of**y**or the*i*^{th}data value in a waveform

Algorithm for the Bisquare Method

The bisquare method of fitting finds the slope and intercept using an iterative process, as shown in the following illustration.

The node calculates residue according to the following equation:

$\frac{1}{N}\underset{i=0}{\overset{N-1}{\sum}}{w}_{i}{({f}_{i}-{y}_{i})}^{2}$

where

*N*is the length of**y**or the number of data values in a waveform*w*_{i}is the*i*^{th}element of**weight***f*_{i}is the*i*^{th}element of**best linear fit***y*_{i}is the*i*^{th}element of**y**or the*i*^{th}data value in a waveform.

**Default: **Least Square

Slope of the calculated best linear fit.

This output can return a double-precision, floating-point number or a 1D array of double-precision, floating-point numbers.

Intercept of the calculated best linear fit.

This output can return a double-precision, floating-point number or a 1D array of double-precision, floating-point numbers.

Error information.

The node produces this output according to standard error behavior.

Standard Error Behavior

**error in** input and an **error out** output so that the node can respond to and communicate errors that occur while code is running. The value of **error in** specifies whether an error occurred before the node runs. Most nodes respond to values of **error in** in a standard, predictable way.

Weighted mean error of the fitted model.

This output can return a double-precision, floating-point number or a 1D array of double-precision, floating-point numbers.

Algorithm for Calculating **residue** When the Input Signal is a Double-Precision, Floating-Point Number

When the input signal is a double-precision, floating-point number, this node calculates **residue** according to the following equation:

$\mathrm{residue}=\text{\hspace{0.17em}}\frac{1}{N}\underset{i=0}{\overset{N-1}{\sum}}{({f}_{i}-{y}_{i})}^{2}$

where

*N*is the number of elements in the data set*f*_{i}is the*i*^{th}element of**best linear fit***y*_{i}is the**y**component of the*i*^{th}input data point

This node uses the general least squares method to fit the data points in an input signal to a straight line of the general form described by the following equation:

$f=ax+b$

where *x* is an input sequence, *a* is the slope of **best linear fit**, and *b* is the intercept of **best linear fit**.

This node finds the values of *a* and *b* that best fit the observations (X, Y). When the input signal is a double-precision, floating-point number or an array of double-precision, floating-point numbers, X is the **x** component of the input signal and Y is **y** component of the input signal. When the input signal is a waveform or an array of waveforms, X is the input sequence calculated from the start time of the waveform and Y is the data values in the waveform.

The following equation describes the linear curve resulting from the linear fit algorithm:

$y[i]=ax[i]+b$

**Where This Node Can Run: **

Desktop OS: Windows

FPGA: This product does not support FPGA devices

Web Server: Not supported in VIs that run in a web application