You are on page 1of 15

Fourier Series, Fourier Transforms, and

Periodic Response to Periodic Forcing


CEE 541. Structural Dynamics
Department of Civil and Environmental Engineering
Duke University
Henri P. Gavin
Fall, 2014
This document describes methods to analyze the steady-state forced-response of single
degree of freedom (SDOF) systems to general periodic loading. The analysis is carried out
using Fourier series representation of the periodic external forcing and the resulting periodic
steady-state response.

1 Fourier Series for Real-Valued Functions


Any real-valued function, f (t), that is:
periodic, with period T ,
= f (t 2T ) = f (t T ) = f (t) = f (t + T ) = f (t + 2T ) =
square-integrable
Z T

f 2 (t)dt < .

may be represented as a series expansion of sines and cosines, in a Fourier series,

X
2qt X
2qt
1

aq cos
bq sin
+
,
f (t; a, b) = a0 +
2
T
T
q=1
q=1

(1)

where the Fourier coefficients, aq and bq are given by the Fourier integrals,
2ZT
2qt
f (t) cos
dt ,
T 0
T
2ZT
2qt
f (t) sin
dt ,
=
T 0
T

aq =

q = 1, 2, . . .

(2)

bq

q = 1, 2, . . .

(3)

The Fourier series f(t; a, b) is a least-squares fit to the function f (t). This may be shown
by first defining
the error function, e(t) = f (t) f(t; a, b), the quadratic error criterion,
RT 2
J(a, b) = 0 e (t)dt, and finding the Fourier coefficients by solving the linear equations
resulting from minimizing J(a, b) with respect to the coefficients a and b. (by setting
J(a, b)/a and J(a, b)/b equal to zero). So doing,
J(a, b) =

Z T

2

f (t) f(t; a, b)

dt

Z T
0

f 2 (t) 2f (t)f(t; a, b) + f2 (t; a, b) dt.

(4)

CEE 541. Structural Dynamics Duke University Fall 2014 H.P. Gavin

Setting J/a0 equal to zero results in


Z T

i
h 2
f (t) 2f (t)f(t; a, b) + f2 (t; a, b) dt
0 a0
Z T
Z T


f(t; a, b)
f (t; a, b)dt + 2
f (t; a, b)dt
= 2
f (t)
a0
a0
0
0

0 =

= 2

Z T
0

Z T

1
f (t) dt + 2
2

f (t)dt +

Z T
0

Z T

Z T
0

1
2qt
2qt 1
a0 +
aq cos
+
bq sin
dt
2
T
T
2
q=1
q=1

Z T
Z T

X
X
1
2qt
2qt
cos
sin
a0 dt +
aq
dt +
bq
dt
2
T
T
0
0
q=1
q=1

X
X
1
f (t)dt + a0 T +
aq 0 +
bq 0
2
q=1
q=1

From which,
2ZT
a0 =
f (t) dt.
T 0

(5)

Note here that (a0 /2) is the average value of f (t).


Proceeding with the rest of the a coefficients, setting J(a, b)/ak equal to zero results in
Z T

i
h 2
f (t) 2f (t)f(t; a, b) + f2 (t; a, b) dt
0 ak
Z T
Z T


f (t; a, b)dt + 2
f(t; a, b)
f (t; a, b)dt
= 2
f (t)
ak
ak
0
0

0 =

Z T
0

Z T

Z T
0

Z T
0

2kt
dt +
T
Z T
Z T

X
X
2qt
2qt
2kt
2qt
2kt
cos
dt +
aq
cos
cos
dt +
bq
sin
cos
dt
T
T
T
T
T
0
0
q=1
q=1

f (t) cos

a0 Z T
2

Z T

X
2kt
2qt X
2qt
2kt
a
0 +
f (t) cos
aq cos
bq sin
cos
dt +
+
dt
T
2
T
T
T
0
q=1
q=1

Z T

X
a0
2kt
2 2kt
f (t) cos
dt +
0 + ak
cos
dt +
bq 0
T
2
T
0
q=1

f (t) cos

T
2kt
dt + 0 + ak + 0
T
2

From which,
ak =

2ZT
2kt
f (t) cos
dt.
T 0
T

(6)

In a completely similar fashion, J(a, b)/bk = 0 results in


2ZT
2kt
bk =
f (t) sin
dt.
T 0
T

(7)
CC BY-NC-ND H.P. Gavin

Fourier Series and Periodic Response to Periodic Forcing

The derivation of the Fourier integrals (equations (5), (6), and (7)) make use of orthogonality
properties of sine and cosine functions.
Z T

nt
dt
sin
T
0


Z T
nt
cos2
dt
T
0




Z T
nt
mt
sin
sin
dt
T
T
0




Z T
nt
mt
cos
cos
dt
T
T
0




Z T
nt
mt
sin
cos
dt
T
T
0
2

T
,
2
T
,
=
2
=

n = 1, 2,
n = 1, 2,

= 0,

n 6= m ,

n, m = 1, 2,

= 0,

n 6= m ,

n, m = 1, 2,

= 0,

n 6= m ,

n, m = 1, 2,

1.1 The complex exponential form of Fourier series


Recall the trigonometric identities for complex exponentials, ei = cos +i sin . Defining
the complex scalar F as F = 21 (a ib), and its complex conjugate, F as F = 12 (a + ib), it
is not hard to show that
F ei + F ei = a cos + b sin .

(8)

Note that the left hand side of equation (8) is the sum of complex conjugates, and that the
right hand side is the sum of real values. So complex conjugates can be used to express the
real Fourier series given in equation (1). Substituting equation (8) into equation (1),

X
2qt
1
2qt

aq cos
a0 +
+ bq sin
f (t; a, b) =
2
T
T
q=1

X
1
1
2q
1
2q
a0 +
(aq ibq ) exp i
t + (aq + ibq ) exp i
t
2
T
2
T
q=1 2

X
X
1
2q
2q
a0 +
Fq exp i
t +
Fq exp i
t
2
T
T
q=1
q=1



1
X
X
2q
2q
1

a0 +
Fq exp i
t +
Fq
exp i
t
=
2
T
T
q=
q=1

X
2q
=
Fq exp i
t =
Fq eiq t
T
q=
q=

(9)

where the Fourier frequency q is 2q/T , F0 = 12 a0 , Fq = 12 (aq ibq ), and Fq


= Fq . The

condition Fq = Fq holds for the Fourier series of any real-valued function that is periodic

CC BY-NC-ND H.P. Gavin

CEE 541. Structural Dynamics Duke University Fall 2014 H.P. Gavin

and integrable. Going the other way,


f(t; F) =

q=+
X

Fq eiq t

q=

= F0 +

q=1
X

iq t

Fq e

q=

= F0 +

q=+
X

q=+
X
q=1

Fq eiq t +

q=+
X

q=1

= F0 +
= F0 +
= F0 +

h
X
q=1
h
X
q=1
h
X

Fq eiq t
Fq eiq t

q=1

Fq eiq t + Fq eiq t

(Fq0 + iFq00 ) (cos q t + i sin q t) + (Fq0 iFq00 ) (cos q t i sin q t)


i

2Fq0 cos q t 2Fq00 sin q t

q=1

So, the real part of Fq , Fq0 , is half of aq , the imaginary part of Fq , Fq00 , is half of bq , and

. The real Fourier coefficients, aq , are even about q = 0 and the imaginary Fourier
Fq = Fq
coefficients, bq , are odd about q = 0.
Just as the Fourier expansion may be expressed in terms of complex exponentials, the
coefficients Fq may also be written in this form.


1
2q
1ZT
2q
Fq = (aq ibq ) =
f (t) cos
t i sin
t
2
T 0
T
T


2q
1ZT
f (t) exp i
=
t dt
T 0
T

(10)

Since the integrand, f (t)eiq t , of the Fourier integral is periodic in T , the limits of integration
can be shifted arbitrarily without affecting the resulting Fourier coefficients.
Z T
0

iq t

f (t)e

dt =

iq t

f (t)e

dt +

Z T +

iq t

f (t)e

dt

Z T +

f (t)eiq t dt.

But, since the integrand is periodic in T ,


Z

iq t

f (t)e

dt =

Z T +

f (t)eiq t dt .

So, the interval of integration can be shifted arbitrarily.


Z T
0

f (t)eiq t dt =

Z T +

f (t)eiq t dt.

0+

On the other hand, shifting the function in time, affects the relative values of aq and bq
(i.e.,
the phase the the complex coefficeint Fq ), but does not affect the magnitude, |Fq | =
q
P
1
iq t
2 + b2 . If f(t) =
(t + ) = P Fq eiq (t+ ) = P (Fq eiq ) eiq t , and
a
F
e
,
then
f
q
q
q
2
|Fq | = |Fq eiq |.
CC BY-NC-ND H.P. Gavin

Fourier Series and Periodic Response to Periodic Forcing

2 Fourier Integrals in Maple


The Fourier integrals for real valued functions (equations (6) and (7)) can be evaluated
using symbolic math software, such as Maple or Mathematica.

2.1 a periodic square wave function: f (t) = sgn(t) on < t < and f (t) = f (t + n(2))
> assume (k::integer);
>
f := signum(t);
> ak := (2/(2*Pi)) * int(f*cos(2*Pi*k*t/(2*Pi)),t=-Pi..Pi);
ak := 0
>

bk := (2/(2*Pi)) * int(f*sin(2*Pi*k*t/(2*Pi)),t=-Pi..Pi);
k
2 ((-1)
- 1)
bk := - -------------Pi k

2.2 a periodic sawtooth function: f (t) = t on < t < and f (t) = f (t + n(2))
> assume (k::integer);
> f := t;
> ak := (2/(2*Pi)) * int(f*cos(2*Pi*k*t/(2*Pi)),t=-Pi..Pi);
ak := 0
> bk := (2/(2*Pi)) * int(f*sin(2*Pi*k*t/(2*Pi)),t=-Pi..Pi);
(1 + k)
2 (-1)
bk := -------------k

2.3 a periodic triangle function: f (t) = /2 t sgn(t) on < t < and f (t) = f (t + n(2))
> assume (k::integer);
> f := Pi/2 - t * signum(t);
> ak := (2/(2*Pi)) * int(f*cos(2*Pi*k*t/(2*Pi)),t=-Pi..Pi);
k
2 ((-1)
- 1)
ak := - -------------2
Pi k
>

bk := (2/(2*Pi)) * int(f*sin(2*Pi*k*t/(2*Pi)),t=-Pi..Pi);
bk := 0
CC BY-NC-ND H.P. Gavin

CEE 541. Structural Dynamics Duke University Fall 2014 H.P. Gavin

3 Fourier Transforms
Recall for periodic functions of period, T , the Fourier series expansion may be written
f (t) =

q=
X

Fq eiq t ,

(11)

q=

where the Fourier coefficients, Fq , have the same units as f (t), and are given by the Fourier
integral,
1 Z T /2
Fq =
f (t) eiq t dt ,
(12)
T T /2
in which the limits of integration have been shifted by = T /2.
Now, consider a change of variables, by defining a frequency increment, , and a scaled
amplitude, F (q ).
2
(q = q )
T
2

F (q ) = T Fq =
Fq

= 1 =

(13)
(14)

Where the scaled amplitude, F (q ), has units of f (t) t or f (t)/.


Using these new variables,
X
1 q=
f (t) =
F (q ) eiq t ,
2 q=

F (q ) =

Z T /2

f (t) eiq t dt .
P

1 Z
F () eit d ,
2 Z

F () =

(16)

T /2

Finally, taking the limit as T , implies d and


f (t) =

(15)

f (t) eit dt .

(17)
(18)

These expressions are the famous Fourier transform pair. Equation (17) is commonly called
the inverse Fourier transform and equation (18) is commonly called the forward Fourier
transform. They differ only by the sign of the exponent and the factor of 2.

CC BY-NC-ND H.P. Gavin

Fourier Series and Periodic Response to Periodic Forcing

4 Fourier Approximation
Any periodic function may be approximated as a truncated series expansion of sines and
cosines, as a Fourier series,
Q
Q
X
2qt X
2qt
1
aq cos
+
bq sin
,
f(t) = a0 +
2
T
T
q=1
q=1

(19)

where the Fourier coefficients, aq and bq may be found by solving the Fourier integrals,
aq
bq

2 Z T /2
2qt
=
f (t) cos
dt ,
T T /2
T
2 Z T /2
2qt
=
f (t) sin
dt ,
T T /2
T

q = 1, 2, . . . , Q

(20)

q = 1, 2, . . . , Q

(21)

The Fourier approximation (19) may also be represented using complex exponential notation.
f(t) =

q=Q
X

Fq eiq t =

q=Q

X
1 q=Q
F (q ) eiq t
T q=Q

(22)

where eiq t = cos q t + i sin q t, q = 2q/T , Fq = 12 (aq ibq ), Fq = Fq


, and

1 Z T /2
f (t) eiq t dt .
Fq =
T T /2

(23)

The accuracy of Fourier approximations of non-sinusoidal functions increases with the


number of terms, Q, in the series. Especially for time series that are discontinuous in time,
such as square-waves or saw-tooth waves, Fourier approximations, f(t), will contain a degree
of over-shoot at the discontinuity and will oscillate about the approximated function f (t).
This is called Gibbs phenomenon. In section 7 we illustrate this effect for square waves and
triangle waves.

5 Discrete Fourier Transform


If the function f (t) is represented by N uniformly-spaced points in time, tn = (n)(t),
(n = 0, , N 1), the N Fourier coefficients are computed by the discrete Fourier transform,


1
2qn
1 NX
,
f (tn ) exp i
Fq =
N n=0
N

q = [N/2 + 1, , 2, 1, 0, 1, , N/2]

(24)

and the N -point discrete Fourier approximation is computed by the inverse discrete Fourier
transform,


N/2
X
2qn
f (tn ) =
Fq exp i
(25)
N
q=N/2+1
With the normalization given in equations (24) and (25), N1 fn2 = |Fq |2 . By convention,
in the fast Fourier transform (FFT) the factor (1/N ) is applied to equation (25) instead of
equation (24). Also, by convention, the Fourier frequencies, q = 2q/T are sorted as follows:
q = 0, 1, , N/2, N/2 + 1, , 2, 1. The lowest positve frequency in the FFT is 1/T
Hertz, and the highest frequency is 1/(2t) Hertz, which is called the Nyquist frequency.
P

CC BY-NC-ND H.P. Gavin

CEE 541. Structural Dynamics Duke University Fall 2014 H.P. Gavin

6 Fourier Series and Periodic Responses of Dynamic Systems


The response of a system described by a frequency response function H() to arbitrary
periodic forces described by a Fourier series may be found in the frequency domain, or in the
time domain.
Complex exponential notation allows us to directly determine the steady-state periodic
response to general periodic forcing, in terms of both the magnitude of the response and the
phase of the response. Recall the relationship between the complex magnitudes X and F for
a sinusoidally-driven spring-mass-damper oscillator is
Xq = H(q ) Fq =

1
(k

mq2 )

+ i(cq )

(26)

Fq

The function H() is called the frequency response function for the dynamic system relating
the input f (t) to the output x(t).
Because the oscillator is linear, if the response to f1 (t) is x1 (t), and the response to f2 (t)
is x2 (t), then the response to c1 f1 (t) + c2 f2 (t) is c1 x1 (t) + c2 x2 (t). More generally, then,
x(t) =

q=
X
q=

H(q ) Fq e

iq t

q=
X
q= (k

1
mq2 )

+ i(cq )

Fq eiq t

(27)

where q = 2q/T .
q

Note that q is not the same symbol as n . The natural frequency, k/m, has the symbol
n . The symbol q = 2q/T is the frequency of a component of a periodic forcing function
of period T .
For this frequency response function H(), the series expansion for the response x(t)
converges with fewer terms than the Fourier series for the external forcing, because |H(q )|
decreases as 1/q2 .

CC BY-NC-ND H.P. Gavin

Fourier Series and Periodic Response to Periodic Forcing

7 Examples
In the following examples, the external forcing is periodic with a period, T , of 2 (seconds). For functions periodic in 2 seconds, the frequency increment in the Fourier series is
1 radian/second. In this case, the frequency index number, q, is also the frequency, q , in
radians per second, otherwise, q = 2q/T .
The system is a forced spring-mass-damper oscillator,
x(t) + 2n x(t)
+ n2 x(t) =

1 ext
f (t) .
m

(28)

The complex-valued frequency response function from the external force, f ext (t), to the response displacement, x(t), is given by
1/n2
H() =
,
1 2 + i 2

(29)

where is the frequency ratio, /n ,


In the following three numerical examples, n = 10 rad/s, = 0.1, m = 1 kg, and
Q = 16 terms. The three examples consider external forcing in the form of a square-wave, a
sawtooth-wave, and a triangle-wave. In each example six plots are provided.
In the (a) plots, the solid line represents the exact form of f (t), the dashed lines represent
the real-valued form of the Fourier approximation and the complex-valued form of the Fourier
approximation, and the circles represent 2Q sample points of the function f (t) for use in fast
Fourier transform (FFT) computations. The two dashed lines are exactly equal.
In the (b) plots, the impulse-lines show the values of the Fourier coefficients, Fq , found by
evaluating the Fourier integral, equation (23), and the circles represent the Fourier coefficients
returned by the FFT.
In the (c) plots, the red solid lines show the cosine terms of the Fourier series and the
blue dashed lines show the sine terms of the Fourier series.
The (d) and (f) plots show the magnitude and phase of the transfer function, H() as a
solid line, the Fourier coefficients, Fq , as the green circles, and H(q )Fq as the blue circles.
In the (e) plots, the solid line represents x(t) as computed using equation (27), the circles
represent the real part of the result of the inverse FFT calculation and the dots represent
the imaginary part of the result of the inverse FFT calculation.
The numerical details involved in the correct representation of periodic functions and
frequency indexing for FFT computations are provided in the attached Matlab code.

CC BY-NC-ND H.P. Gavin

10

CEE 541. Structural Dynamics Duke University Fall 2014 H.P. Gavin

7.1 Example 1: square wave


The external forcing is given by
f ext (t) = sgn(t) ;

< t <

(30)

The Fourier coefficients for the real-valued Fourier series are:


aq = 0 and bq = (2/(q)) (1q 1).
1.5

0
-0.1
Fourier coefficients, Fq, (N)

function, f(t), (N)

0.5

-0.5

-1

-0.2
-0.3
-0.4
-0.5
-0.6

-1.5

-0.7
-3

-2

-1

(a)

(b)

time, t, (s)

10

12

14

16

frequency, , (rad/s)
1

1.5

0.1
frequency response

cosine and sine terms

0.5

-0.5

0.01

0.001
-1

1e-04

-1.5
-3

-2

-1

(c)

(d)

time, t, (s)

10

12

14

16

12

14

16

frequency, , (rad/s)
200

0.025
0.02

150

phase lead, (degrees)

0.015
response, x, (m)

0.01
0.005
0
-0.005
-0.01

100
50
0
-50
-100

-0.015
-150

-0.02

-200

-0.025

(e)

-3

-2

-1

0
time, t, (s)

(f)

10

frequency, , (rad/s)

Figure 1. (a): = f ext (t); - - = fext (t). (b): red solid = <(Fq ); blue dashed = =(Fq );
*: Fq from FFT. (c): red solid = component cosine terms, blue dashed = component sine terms.
(d): : |H()|; *: |Fq | and |H(q )Fq |. (e): : x(t); *: x(t) from IFFT; : =(x(t)) from
IFFT. (f): : phase of H(); *: phase of Fq and H(q )Fq .

CC BY-NC-ND H.P. Gavin

11

Fourier Series and Periodic Response to Periodic Forcing

7.2 Example 2: sawtooth wave


The external forcing is given by
f ext (t) = t ;

< t <

(31)

The Fourier coefficients for the real-valued Fourier series are:


aq = 0 and bq = (2/q) (1q ).
0.6

0.4
Fourier coefficients, Fq, (N)

function, f(t), (N)

2
1
0
-1
-2
-3

0.2
0
-0.2
-0.4
-0.6
-0.8

-4

-1
-3

-2

-1

(a)

(b)

time, t, (s)

10

12

14

16

frequency, , (rad/s)
1

0.1

1
frequency response

cosine and sine terms

1.5

0.5
0
-0.5

0.01

0.001

-1
-1.5

1e-04

-2
-3

-2

-1

(c)

(d)

time, t, (s)

10

12

14

16

12

14

16

150
100
phase lead, (degrees)

0.02

response, x, (m)

frequency, , (rad/s)

0.04

-0.02

-0.04

-0.06

50
0
-50
-100
-150
-200

-0.08

(e)

-3

-2

-1

0
time, t, (s)

(f)

10

frequency, , (rad/s)

Figure 2. (a): = f ext (t); - - = fext (t). (b): red solid = <(Fq ); blue dashed = =(Fq );
*: Fq from FFT. (c): red solid = component cosine terms, blue dashed = component sine terms.
(d): : |H()|; *: |Fq | and |H(q )Fq |. (e): : x(t); *: x(t) from IFFT; : =(x(t)) from
IFFT. (f): : phase of H(); *: phase of Fq and H(q )Fq .

CC BY-NC-ND H.P. Gavin

12

CEE 541. Structural Dynamics Duke University Fall 2014 H.P. Gavin

7.3 Example 3: triangle wave


The external forcing is given by
f ext (t) = /2 t sgn(t) ;

< t <

(32)

The Fourier coefficients for the real-valued Fourier series are:


aq = (2/q 2 )(1q 1) and bq = 0.
0.7
0.6
Fourier coefficients, Fq, (N)

2
1.5

function, f(t), (N)

1
0.5
0
-0.5
-1
-1.5
-2
-2

-1

0.2
0.1

(b)

time, t, (s)

10

12

14

16

frequency, , (rad/s)
1

1.5

0.1
frequency response

cosine and sine terms

0.3

-0.1
-3

0.5

-0.5

0.01

0.001

1e-04

-1

1e-05

-1.5
-3

-2

-1

(c)

(d)

time, t, (s)
0.02

200

0.015

150

0.01

100

0.005
0
-0.005

10

12

14

16

12

14

16

frequency, , (rad/s)

phase lead, (degrees)

response, x, (m)

0.4

(a)

50
0
-50

-0.01

-100

-0.015

-150
-200

-0.02

(e)

0.5

-3

-2

-1

0
time, t, (s)

(f)

10

frequency, , (rad/s)

Figure 3. (a): = f ext (t); - - = fext (t). (b): red solid = <(Fq ); blue dashed = =(Fq );
*: Fq from FFT. (c): red solid = component cosine terms, blue dashed = component sine terms.
(d): : |H()|; *: |Fq | and |H(q )Fq |. (e): : x(t); *: x(t) from IFFT; : =(x(t)) from
IFFT. (f): : phase of H(); *: phase of Fq and H(q )Fq .

CC BY-NC-ND H.P. Gavin

13

Fourier Series and Periodic Response to Periodic Forcing

7.4 Matlab code


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

function [ Fq , wq ,x , t ] = Fourier (type ,Q , wn , z )


% [ F , w , x ] = F o u r i e r ( t y p e ,Q, wn , z )
% Compute t h e F o u r i e r s e r i e s c o e f f i c i e n t s o f a p e r i o d i c s i g n a l , f ( t ) ,
% i n two d i f f e r e n t ways :
% complex e x p o n e n t i a l e x p a n s i o n
( i . e . , s i n e and c o s i n e e x p a n s i o n )
% f a s t Fourier transform
%
% The t y p e o f p e r i o d i c s i g n a l may be
%
s q u a r e a s q u a r e wave
%
s a w t o o t h a sawt o o t h wave
%
t r i a n g l e a t r i a n g l e wave
%
% The p e r i o d o f t h e s i g n a l , f ( t ) , i s f i x e d a t 2 p i ( se c o nd ) .
%
% The number o f F o u r i e r s e r i e s c o e f f i c i e n t s i s i n p u t as Q.
% This r e s u l t s i n a 2Q F o u r i e r t r a n s f o r m c o e f f i c i e n t s .
%
% The F o u r i e r a p p r o x i m a t i o n i s t h e n used t o compute t h e s t e a d y s t a t e
% r e s p o n s e o f a s i n g l e d e g r e e o f freedom (SDOF) o s c i l l a t o r , d e s c r i b e d by
%
%
2
% x ( t ) + 2 z wn x ( t ) + wn x ( t ) = f ( t ) ,
%
% where t h e mass o f t h e sy s te m i s f i x e d a t 1 ( kg ) .
%
% s e e : h t t p : / / en . w i k i p e d i a . o r g / w i k i / F o u r i e r s e r i e s
%
h t t p : / /www. j h u . edu / s i g n a l s / f o u r i e r 2 / i n d e x . html
%

29
30
31
32
33

i f nargin < 4
help Fourier
return
end

34
35
36

T = 2* pi ;

% period of external forcing , s

37
38
39

a
b

= zeros (1 , Q );
= zeros (1 , Q );

% c o e f f i c i e n t s of cosine part of Fourier s e r i e s


% c o e f f i c i e n t s of
sine part of Fourier s e r i e s

40
41
42

q = [1: Q ];
wq = 2* pi * q / T ;

% p o s i t i v e frequency index value


% p o s i t i v e f r e q u e n c y v a l u e s , rad / sec ,

dt = T /(2* Q );
ts = [ - Q :Q -1]* dt ;

% 2Q d i s c r e t e p o i n t s i n time f o r FFT s a m p l i n g
% 2Q d i s c r e t e p o i n t s i n time f o r FFT s a m p l i n g

eq n ( 1 3 )

43
44
45
46
47
48
49
50
51
52

% s h i f t e d time . . . T/2 <= t < T/2 . . .


% t s (1)
= Q d t
= T/2
= p i
. . . f (T/2) = f (T/2) by e x t e n s i o n
% t s (Q)
= d t
= T/(2Q) = p i /Q
% t s (Q+1) =
0
. . . f (0)
= f (T)
by e x t e n s i o n
% t s (Q+2) = d t
= T/(2Q) = p i /Q
% t s (2Q) = (Q1) d t = T/2 d t = p i p i /Q

53
54
55

P = 128; % number o f p o i n t s i n t h e timer e c o r d ( f o r p l o t t i n g p u r p o s e s o n l y )


t = [ - P : P ]* T /2/ P ;
% time a x i s

56
57
58

% =======================================================================
% Fourier s e r i e s approximation of general p e r i o d i c f u n c t i o n s

59
60
61
62

% s i n ( q p i ) = 0 , c o s ( q p i ) = ( 1). q
% f t r u e i s used o n l y f o r p l o t t i n g
% f samp i s used i n FFT c o m p u t a t i o n s

63
64
65
66
67
68
69
70

i f strcmp( type , square )


% s q u a r e wave
b = - 2./( q * pi ) .* (( -1). q - 1);
f_true = sign ( t );
f_true (1) = 0; f_true (2* P +1) = 0;
f_samp = sign ( ts );
f_samp (1) = 0;
% g e t p e r i o d i c i t y r i g h t , f ( p i ) = 0

CC BY-NC-ND H.P. Gavin

14
71

CEE 541. Structural Dynamics Duke University Fall 2014 H.P. Gavin

end

72
73
74
75
76
77
78

i f strcmp( type , sawtooth )


% s a w t o o t h wave
b = -(2./ q ) .* ( -1). q ;
f_true = t ;
f_true (1) = 0; f_true (2* P +1) = 0;
f_samp = ts ;
f_samp (1) = 0;
% g e t p e r i o d i c i t y r i g h t , f ( p i ) = 0
end

79
80
81
82
83
84

i f strcmp( type , triangle )


a = -(2./( pi * q .2)) .* ( ( -1). q - 1 );
f_true = pi /2 - t .* sign ( t );
f_samp = pi /2 - ts .* sign ( ts );
end

% t r i a n g l e wave

f_approxR = a * cos (q * t ) + b * s i n (q * t );

% r e a l Fourier s e r i e s

Fq = ( a - i * b )/2;

% complex F o u r i e r c o e f f i c i e n t s

85
86
87
88
89
90
91
92

% Complex F o u r i e r s e r i e s ( p o s i t i v e and n e g a t i v e e x p o n e n t s )
f_approxC = Fq * exp( i * wq * t ) + conj ( Fq ) * exp( - i * wq * t );

93
94
95
96

% The i m a g n i a r y p a r t o f t h e complex F o u r i e r s e r i e s i s e x a c t l y z e r o !
i m a g _ o v e r _ re al _ 1 = max(abs(imag( f_approxC ))) / max(abs( r e a l ( f_approxC )))

97
98
99
100
101
102
103

%
%
%
%
%

The f a s t F o u r i e r t r a n s f o r m (FFT) method


In Matlab , t h e f o r w a r d F o u r i e r t r a n s f o r m has a n e g a t i v e e x p o n e n t .
According t o a c o n v e n t i o n o f t h e FFT method , i n d e x number 1 i s f o r time = d t
t s ( 1 ) = Q d t = T/2 ; t s (Q) = d t ; t s (Q+1)=0 ; t s (2Q) = (Q1) d t = T/2 d t
. . . s e e t h e t a b l e a t t h e end o f t h i s f i l e .

104
105

F_FFT = f f t ( [ f_samp ( Q +1:2* Q ) f_samp (1: Q ) ] ) / (2* Q );

% Fourier coeff s

106
107
108

% c o e f = [ Fq F FFT ( 2 :Q+1) ]

% d i s p l a y the Fourier c o e f f i c i e n t s

109
110

% P l o t t i n g

111
112
113
114
115
116
117
118
119
120
121
122

f i g u r e (1);
plot (t , f_true , -r , ts , f_samp , * r , t , f_approxR , -c , t , f_approxC , -b )
xlabel ( time , t , ( s ) )
ylabel ( function , f ( t ) , ( N ) )
axis (1.05*[ - pi , pi ])
legend ( true , sampled , real Fourier approx , complex Fourier approx )
plot ( wq , r e a l ( Fq ) , r , wq ,imag( Fq ) , b , ...
wq , r e a l ( F_FFT (2: Q +1)) , * r , wq ,imag( F_FFT (2: Q +1)) , * b )
ylabel ( Fourier coefficients , F ( w ) , ( N ) )
xlabel ( frequency , {/ Symbol w } , ( rad / s ) )
legend ( real ( F ) , imag ( F ) , real ( FFT ( f )) , imag ( FFT ( f )) )

123
124
125
126
127
128
129

f i g u r e (2);
plot (t ,a * ones (1 ,2* P +1).* cos (q * t ) , -r , t ,b * ones (1 ,2* P +1).* s i n (q * t ) , -b );
xlabel ( time , t , ( s ) )
ylabel ( cosine and sine terms )
axis (1.05*[ - pi , pi ])

130
131
132
133

% =======================================================================
% Steadys t a t e r e s p o n s e o f a SDOF o s c i l l a t o r t o g e n e r a l p e r i o d i c f o r c i n g .

134
135
136

% Complexv a l u e d f r e q u e n c y r e s p o n s e f u n c t i o n , H(w) , has u n i t s o f [m/N]


H = (1/ wn 2) ./ ( 1 - ( wq / wn ).2 + 2* i * z *( wq / wn ) );

137
138
139

% Complex F o u r i e r s e r i e s ( p o s i t i v e and n e g a t i v e e x p o n e n t s )
x_approxC = ( H .* Fq ) * exp( i * wq * t ) + ( conj ( H ) .* conj ( Fq )) * exp( - i * wq * t );

140
141

% In Matlab , t h e i n v e r s e F o u r i e r t r a n s f o r m has a p o s i t i v e e x p o n e n t .

CC BY-NC-ND H.P. Gavin

15

Fourier Series and Periodic Response to Periodic Forcing


142
143

%
. . . s e e t h e t a b l e a t t h e end o f t h i s f i l e f o r t h e s o r t i n g c o n v e n t i o n .
x_FFT = i f f t ( [ (1/ wn 2) , H , conj ( H (Q -1: -1:1)) ] .* F_FFT ) * (2* Q );

144
145
146
147
148
149

f i g u r e (3);
% p l o t frequency response functions
semilogy ( wq ,abs( Fq ) , * g , wq ,abs( H ) , -r , wq ,abs( H .* Fq ) , * b )
xlabel ( frequency , {/ Symbol w } , ( rad / s ) )
ylabel ( frequency response )
legend ( | F | , | H | , | H * F | )

150

plot ( wq , angle ( Fq )*180/ pi , * g , wq , angle ( H )*180/ pi , -r , wq , angle ( H .* Fq )*180/ pi , * b )


xlabel ( frequency , {/ Symbol w } , ( rad / s ) )
ylabel ( phase lead , ( degrees ) )

151
152
153
154
155
156
157
158
159
160
161

f i g u r e (4);
% p l o t time r e s p o n s e
ts = [ ts ( Q +1:2* Q ) ts (1: Q ) ];
% res o r t t h e time a x i s
plot ( t , x_approxC , -r , ts , r e a l ( x_FFT ) , * b , ts , imag( x_FFT ) , . b )
axis (1.05*[ - pi , pi ])
xlabel ( time , t , ( s ) )
ylabel ( response , x , ( m ) )
legend ( x ( t ) - complex Fourier series , real ( x ( t )) - FFT , imag ( x ( t )) - FFT )

162
163
164
165

% The i m a g i n a r y p a r t i s e x a c t l y z e r o f o r t h e complex e x p o n e n t s e r i e s method !


i m a g _ o v e r _ rea l _ 2 = max(abs(imag( x_approxC ))) / max(abs( r e a l ( x_approxC )))

166
167
168

% The i m a g i n a r y p a r t i s p r a c t i c a l l y z e r o f o r t h e FFT method !


i m a g _ o v e r _ rea l _ 3 = max(abs(imag( x_FFT ))) / max(abs( r e a l ( x_FFT )))

169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191

%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%

SORTING o f t h e FFT c o e f f i c i e n t s
number o f d a t a p o i n t s = N = 2Q
note :
f max = 1/(2 d t ) ;
d f = f max /(N/2) = 1/(N d t ) = 1/T;

index
time
frequency
=====
====
=========
1
0
0
2
dt
df
3
2 d t
2 d f
4
3 d t
3 d f
:
:
:
N/21
(N/22) d t
f max 2 d f = ( N/22) d f
N/2
(N/21) d t
f maxd f
= ( N/21) d f
N/2+1
(N/2) d t
+/ f max
= ( N/2 ) d f
N/2+2
(N/2+1) d t
f max+d f
= (N/2+1) d f
N/2+3
(N/2+2) d t
f max+2 d f = (N/2+2) d f
:
:
:
:
N2
(N3) d t
3 d f
N1
(N2) d t
2 d f
N
(N1) d t
d f

CC BY-NC-ND H.P. Gavin

You might also like