DADiSP Worksheet Functions > Function Categories > Curve Fitting > SINFIT3

 

SINFIT3

Purpose:

Performs 3 term frequency sine curve fitting using the least squares method.

Syntax:

SINFIT3(series, freq, mode)

series

-

A series, the input sinusoid.

freq

-

A real, the known frequency of the input signal. Defaults to -1, estimate the frequency.

mode

-

Optional. An integer, the sinusiod form:

0:

Returns the fitted curve and optionally the coefficients and rms error for the equation:

image\lsinfit01.gif

If the output is directed to variables:

(fit, coef, rmserr) = sinfit3(series, freq, mode)

 

mode 0 returns coefficients in the form:

coef = {A1, f, B1, C}

1:

(Default). Returns the fitted curve and optionally the coefficients and rms error for the equation:

image\lsinfit02.gif

If the output is directed to variables:

(fit, coef, rmserr) = sinfit3(series, freq, mode)

 

mode 1 returns coefficients in the form:

coef = {A, f, theta, C, RmsError}

Returns:

A series, the fitted sine curve.

 

(fit, coef) = SINFIT3(series) returns the fit and coefficients.

 

(fit, coef, rmserr) = SINFIT3(series) returns the fit, coefficients and RMS error.

Example:

W1: 5 + 3 * gsin(1000, .001, 4, pi) + gnorm(1000, .001)

W2: sinfit3(w1);overp(w1, lred)

 

Overplots the original data with the fitted sinusoid.

Example:

(fit, coef) = sinfit3(w1)

 

fit is the same as W2.

 

coef == {3.0012, 3.9999, 1.5708, 5.000} or similar.

Example:

(fit, coef, rmserr) = sinfit3(w1, 4)

 

fit contains the fitted data.

 

coef == {3.0012, 4.0000, 1.5706, 5.000} or similar.

 

rmserr == 0.0999

Remarks:

SINFIT3 uses the least squares method to fit a sinusoid to a known frequency as per the IEEE 1241 Standard.  If the input frequency is unspecified, the frequency is estimated by locating the dominant frequency of the FFT and using analytical rectangular window interpolation to determine the precise frequency. The FFT interpolation handles estimated frequencies that do not lie on a unique FFT bin.

 

The frequency coefficient, F = coef[2] is in Hertz and the phase term, theta = coef[3] is in radians.

 

SINFIT3 uses LSINFIT to perform the least squares fit as per the IEEE 1241 Standard.

 

See SINFIT4 for an implementation of the 4 term iterative sinusoid fit as outlined in the IEEE 1241 Standard.

 

See SINFIT for a similar routine that uses HANNING window interpolation and returns the frequency coefficient in radians.

See Also:

EFFBIT

FFT

LINFIT

LSINFIT

SINFIT

SINFIT4

References:

IEEE Std 1241-2010 Annex B.1 "An algorithm for three-parameter (known frequency) least-squares fit to sine-wave data"