Sum of Sines Models
About Sum of Sines Models
The sum of sines model fits periodic functions, and is given by
whereais the amplitude,bis the frequency, andcis the phase constant for each sine wave term.nis the number of terms in the series and 1 ≤n≤ 8. This equation is closely related to the Fourier series described inFourier Series. The main difference is that the sum of sines equation includes the phase constant, and does not include a constant (intercept) term.
Fit Sum of Sine Models Interactively
Open the Curve Fitter app by entering
curveFitter
at the MATLAB®command line. Alternatively, on theAppstab, in theMath, Statistics and Optimizationgroup, clickCurve Fitter.In the Curve Fitter app, select curve data. On theCurve Fittertab, in theData部分中,点击Select Data. In theSelect Fitting Datadialog box, selectX DataandY Data, or justY Dataagainst an index.
Click the arrow in theFit Typesection to open the gallery, and clickSum of Sinein theRegression Modelsgroup.
You can specify the following options inFit Optionspane:
Specify the number of terms as a positive integer in the range [1 8]. Look in theResultspane to see the model terms, values of the coefficients, and goodness-of-fit statistics.
Optionally, in theAdvanced Optionssection, specify coefficient starting values and constraint bounds, or change algorithm settings. The app calculates optimized start points forSum of Sinefits, based on the data set. You can override the start points and specify your own values in theFit Optionspane.
TheSum of Sinefit has a lower bound constraint onbiof
0
. The default lower bounds for most fits in theFit Typesection are-Inf
.
For more information on the settings, seeSpecify Fit Options and Optimized Starting Points.
Selecting a Sum of Sine Fit at the Command Line
Specify the model typesin
followed by the number of terms, e.g.,'sin1'
to'sin8'
.
For example, to load some periodic data and fit a six-term sum of sine model:
load enso; f = fit( month, pressure, 'sin6') plot(f,month,pressure)
If you want to modify fit options such as coefficient starting values and constraint bounds appropriate for your data, or change algorithm settings, see the table of additional properties withNonlinearLeastSquares
on thefitoptions
reference page.