# SINFIT

## Purpose:

Fits y(x) = A + B sin(Cx + D) using the FFT.

## Syntax:

SINFIT(series)

(fit, coef) = SINFIT(series)

 series - A series or array.

## Returns:

A series, the fitted sine curve.

(fit, coef) = sinfit(series)

returns both the fit and the coefficients as a series.

## Example:

W1: 5 + 3 * gsin(100, .01, 4, pi) + gnorm(100, .01)

W2: sinfit(w1);overp(W1, lred) overplots the original data with the calculated sine fit.

## Example:

(fit, coef) = sinfit(W1)

fit is the same series as in W2

coef == {5.0034, 3.0299, 25.0144, 3.0835}

Note: since C == coef == 2*pi*F, in this case, F = 25.0144 / (2π) = 3.9812

## Remarks:

SINFIT uses the FFT to find the dominant frequency present in the series and fits the following equation: The input series is multiplied with a HANNING window and Hanning window interpolation is performed in the frequency domain to estimate the frequency, magnitude and phase of the sine. The Hanning window interpolation scheme handles estimated frequencies that do not precisely correspond to FFT frequency bin values.

The frequency term, C == coef and phase term, D == coef, are in radians.

See SINFIT3 for a similar routine that uses rectangular window interpolation and returns the frequency coefficient in Hertz.

See SINTREND to perform a sine fit with a linear trend as per the following equation: FFT

HANNING

LINFIT

LSINFIT

SINFIT3

SINFIT4

SINTREND

TREND