Sie sind auf Seite 1von 7

18/3/2014

Fourier Series - MATLAB & Simulink

Fourier Series
On this page

About Fourier Series Models


Fit Fourier Models Interactively
Fit Fourier Models Using the fit Function

About Fourier Series Models


The Fourier series is a sum of sine and cosine functions that describes a periodic signal. It is represented in either the
trigonometric form or the exponential form. The toolbox provides this trigonometric Fourier series form

w here a0 models a constant (intercept) term in the data and is associated w ith the i = 0 cosine term, w is the fundamental
frequency of the signal, n is the number of terms (harmonics) in the series, and 1 n 8.
For more information about the Fourier series, refer to Fourier Analysis and Filtering.

Fit Fourier Models Interactively


1. Open the Curve Fitting app by entering cftool. Alternatively, click Curve Fitting on the Apps tab.
2. In the Curve Fitting app, select curve data (X data and Y data, or just Y data against index).
Curve Fitting app creates the default curve fit, Polynomial.
3. Change the model type from Polynomialto Fourier.

You can specify the follow ing options:


Choose the number of terms: 1to 8.
Look in the Results pane to see the model terms, the values of the coefficients, and the goodness-of-fit statistics.
(Optional) Click Fit Options to specify coefficient starting values and constraint bounds, or change algorithm settings.
The toolbox calculates optimized start points for Fourier series models, based on the current data set. You can override
the start points and specify your ow n values in the Fit Options dialog box.
For more information on the settings, see Specifying Fit Options and Optimized Starting Points.
For an example comparing the library Fourier fit w ith custom equations, see Custom Nonlinear ENSO Data Analysis.

Fit Fourier Models Using the fit Function


This example show s how to use the fitfunction to fit a Fourier model to data.
The Fourier library model is an input argument to the fitand fittypefunctions. Specify the model type fourierfollow ed
by the number of terms, e.g., 'fourier1'to 'fourier8'.
This example fits the El NinoSouthern Oscillation (ENSO) data. The ENSO data consists of monthly averaged atmospheric
pressure differences betw een Easter Island and Darw in, Australia. This difference drives the trade w inds in the southern
hemisphere.
The ENSO data is clearly periodic, w hich suggests it can be described by a Fourier series. Use Fourier series models to look
for periodicity.
Fit a Tw o-Term Fourier Model
http://www.mathworks.com/help/curvefit/fourier.html

1/7

18/3/2014

Fourier Series - MATLAB & Simulink

Measure Period
Fit an Eight-Term Fourier Model
Measure Period
Examine Terms
Set Start Points
Find Fourier Fit Options
Fit a Tw o-Term Fourier Model
Load some data and fit an tw o-term Fourier model.
load enso;
f = fit(month,pressure,'fourier2')
plot(f,month,pressure)
f=
General model Fourier2:
f(x) = a0 + a1*cos(x*w) + b1*sin(x*w) +
a2*cos(2*x*w) + b2*sin(2*x*w)
Coefficients (with 95% confidence bounds):
a0 =
10.63 (10.23, 11.03)
a1 =
2.923 (2.27, 3.576)
b1 =
1.059 (0.01593, 2.101)
a2 =
-0.5052 (-1.086, 0.07532)
b2 =
0.2187 (-0.4202, 0.8576)
w=
0.5258 (0.5222, 0.5294)

The confidence bounds on a2and b2cross zero. For linear terms, you cannot be sure that these coefficients differ from
zero, so they are not helping w ith the fit. This means that this tw o term model is probably no better than a one term model.
Measure Period
The wterm is a measure of period. 2*pi/wconverts to the period in months, because the period of sin()and cos()is
2*pi.
http://www.mathworks.com/help/curvefit/fourier.html

2/7

18/3/2014

Fourier Series - MATLAB & Simulink

w = f.w
2*pi/w
w=
0.5258

ans =
11.9497

wis very close to 12 months, indicating a yearly period. Observe this looks correct on the plot, w ith peaks approximately 12
months apart.
Fit an Eight-Term Fourier Model
f2 = fit(month,pressure,'fourier8')
plot(f2,month,pressure)
f2 =
General model Fourier8:
f2(x) =
a0 + a1*cos(x*w) + b1*sin(x*w) +
a2*cos(2*x*w) + b2*sin(2*x*w) + a3*cos(3*x*w) + b3*sin(3*x*w) +
a4*cos(4*x*w) + b4*sin(4*x*w) + a5*cos(5*x*w) + b5*sin(5*x*w) +
a6*cos(6*x*w) + b6*sin(6*x*w) + a7*cos(7*x*w) + b7*sin(7*x*w) +
a8*cos(8*x*w) + b8*sin(8*x*w)
Coefficients (with 95% confidence bounds):
a0 =
10.63 (10.28, 10.97)
a1 =
0.5668 (0.07981, 1.054)
b1 =
0.1969 (-0.2929, 0.6867)
a2 =
-1.203 (-1.69, -0.7161)
b2 =
-0.8087 (-1.311, -0.3065)
a3 =
0.9321 (0.4277, 1.436)
b3 =
0.7602 (0.2587, 1.262)
a4 =
-0.6653 (-1.152, -0.1788)
b4 =
-0.2038 (-0.703, 0.2954)
a5 =
-0.02919 (-0.5158, 0.4575)
b5 =
-0.3701 (-0.8594, 0.1192)
a6 =
-0.04856 (-0.5482, 0.4511)
b6 =
-0.1368 (-0.6317, 0.3581)
a7 =
2.811 (2.174, 3.449)
b7 =
1.334 (0.3686, 2.3)
a8 =
0.07979 (-0.4329, 0.5925)
b8 =
-0.1076 (-0.6037, 0.3885)
w=
0.07527 (0.07476, 0.07578)

http://www.mathworks.com/help/curvefit/fourier.html

3/7

18/3/2014

Fourier Series - MATLAB & Simulink

Measure Period
w = f2.w
(2*pi)/w
w=
0.0753

ans =
83.4736

With the f2model, the period wis approximately 7 years.


Exam ine Term s
Look for the coefficients w ith the largest magnitude to find the most important terms.
a7and b7are the largest. Look at the a7term in the model equation: a7*cos(7*x*w). 7*w== 7/7 = 1 year cycle. a7
and b7indicate the annual cycle is the strongest.
Similarly, a1and b1terms give 7/1, indicating a seven year cycle.
a2and b2terms are a 3.5 year cycle (7/2). This is stronger than the 7 year cycle because the a2and b2coefficients
have larger magnitude than a1 and b1.
a3and b3are quite strong terms indicating a 7/3 or 2.3 year cycle.
Smaller terms are less important for the fit, such as a6, b6, a5, and b5.
Typically, the El Nino w arming happens at irregular intervals of tw o to seven years, and lasts nine months to tw o years. The
average period length is five years. The model results reflect some of these periods.
Set Start Points
The toolbox calculates optimized start points for Fourier fits, based on the current data set. Fourier series models are
particularly sensitive to starting points, and the optimized values might be accurate for only a few terms in the associated
http://www.mathworks.com/help/curvefit/fourier.html

4/7

18/3/2014

Fourier Series - MATLAB & Simulink

equations. You can override the start points and specify your ow n values.
After examining the terms and plots, it looks like a 4 year cycle might be present. Try to confirm this by setting w. Get a value
for w, w here 8 years = 96 months.
w = (2*pi)/96
w=
0.0654

Find the order of the entries for coefficients in the model ('f2') by using the coeffnamesfunction.
coeffnames(f2)
ans =
'a0'
'a1'
'b1'
'a2'
'b2'
'a3'
'b3'
'a4'
'b4'
'a5'
'b5'
'a6'
'b6'
'a7'
'b7'
'a8'
'b8'
'w'

Get the current coefficient values.


coeffs = coeffvalues(f2)
coeffs =
Columns 1 through 7
10.6261

0.5668

0.1969

-1.2031

-0.8087

0.9321

0.7602

-0.0292

-0.3701

-0.0486

-0.1368

2.8112

Columns 8 through 14
-0.6653

-0.2038

Columns 15 through 18
1.3344

0.0798

-0.1076

0.0753

Set the last ceofficient, w, to 0.065.


coeffs(:,18) = w
coeffs =

http://www.mathworks.com/help/curvefit/fourier.html

5/7

18/3/2014

Fourier Series - MATLAB & Simulink

Columns 1 through 7
10.6261

0.5668

0.1969

-1.2031

-0.8087

0.9321

0.7602

-0.0292

-0.3701

-0.0486

-0.1368

2.8112

Columns 8 through 14
-0.6653

-0.2038

Columns 15 through 18
1.3344

0.0798

-0.1076

0.0654

Set the start points for coefficients using the new value for w.
f3 = fit(month,pressure,'fourier8', 'StartPoint', coeffs);
Plot both fits to see that the new value for win f3does not produce a better fit than f2.
plot(f3,month,pressure)
hold on
plot(f2, 'b')
hold off
legend( 'Data', 'f3', 'f2')

Find Fourier Fit Options


Find available fit options using fitoptions( modelname ).
fitoptions('Fourier8')

ans =

http://www.mathworks.com/help/curvefit/fourier.html

6/7

18/3/2014

Fourier Series - MATLAB & Simulink

Normalize: 'off'
Exclude: []
Weights: []
Method: 'NonlinearLeastSquares'
Robust: 'Off'
StartPoint: [1x0 double]
Lower: [1x0 double]
Upper: [1x0 double]
Algorithm: 'Trust-Region'
DiffMinChange: 1.0000e-08
DiffMaxChange: 0.1000
Display: 'Notify'
MaxFunEvals: 600
MaxIter: 400
TolFun: 1.0000e-06
TolX: 1.0000e-06

If you w ant to modify fit options such as coefficient starting values and constraint bounds appropriate for your data, or change
algorithm settings, see the options for NonlinearLeastSquares on the fitoptionsreference page.

See Also
fit| fitoptions| fittype

Related Examples
Custom Nonlinear ENSO Data Analysis
Specifying Fit Options and Optimized Starting Points

http://www.mathworks.com/help/curvefit/fourier.html

7/7

Das könnte Ihnen auch gefallen