Performs 3 term frequency cosine curve fitting using the least squares method.
SINFIT3(series, freq, mode)
(fit, coef, rmserr) = 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 sinusoid form:
|
A series, the fitted cosine or sinusoid curve.
(fit, coef, rmserr) = SINFIT3(series) returns the fit, coefficients and RMS error.
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.
(fit, coef) = sinfit3(w1)
fit is the same as W2.
coef == {3.0012, 3.9999, 1.5708, 5.000} or similar.
(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
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.
For the default mode 1, SINFIT3 fits a cosine.
The frequency coefficient, F =
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 to fit a sine and returns the frequency coefficient in radians.
IEEE Std 1241-2010 Annex B.1 "An
algorithm for three-parameter (known frequency)