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 < ∞. 0 may be represented as a series expansion of sines and cosines, in a Fourier series, ∞ ∞ X 2πqt X 2πqt 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 2πqt f (t) cos dt , T 0 T 2ZT 2πqt 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 0 = Z T 0 f 2 (t) − 2f (t)fˆ(t; a, b) + fˆ2 (t; a, b) dt. (4) 2 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) + fˆ2 (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 + 0 0 = − Z T 0 Z T Z T 0 ∞ X ∞ X 1 2πqt 2πqt 1 a0 + aq cos + bq sin · dt 2 T T 2 q=1 q=1 Z T Z T ∞ ∞ X X 1 2πqt 2πqt 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) + fˆ2 (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 0 = − 0 Z T 0 = − Z T 0 2πkt dt + T Z T Z T ∞ ∞ X X 2πqt 2πqt 2πkt 2πqt 2πkt 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 2πkt 2πqt X 2πqt 2πkt 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 2πkt 2 2πkt f (t) cos dt + · 0 + ak cos dt + bq · 0 T 2 T 0 q=1 f (t) cos T 2πkt dt + 0 + ak · + 0 T 2 From which, ak = 2ZT 2πkt f (t) cos dt. T 0 T (6) In a completely similar fashion, ∂J(a, b)/∂bk = 0 results in 2ZT 2πkt bk = f (t) sin dt. T 0 T (7) CC BY-NC-ND H.P. Gavin 3 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 nπt dt sin T 0 Z T nπt cos2 dt T 0 Z T nπt mπt sin sin dt T T 0 Z T nπt mπt cos cos dt T T 0 Z T nπt mπt 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 ∗ e−iθ = 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 2πqt 1 2πqt ˆ aq cos a0 + + bq sin f (t; a, b) = 2 T T q=1 = ∞ X 1 1 2πq 1 2πq a0 + (aq − ibq ) exp i t + (aq + ibq ) exp −i t 2 T 2 T q=1 2 = ∞ ∞ X X 1 2πq 2πq a0 + Fq exp i t + Fq∗ exp −i t 2 T T q=1 q=1 ∞ −1 X X 2πq 2πq 1 ∗ a0 + Fq exp i t + F−q exp i t = 2 T T q=−∞ q=1 ∞ X ∞ X 2πq = Fq exp i t = Fq eiωq t T q=−∞ q=−∞ (9) ∗ where the Fourier frequency ωq is 2πq/T , F0 = 12 a0 , Fq = 12 (aq − ibq ), and F−q = Fq . The ∗ condition F−q = Fq holds for the Fourier series of any real-valued function that is periodic CC BY-NC-ND H.P. Gavin 4 CEE 541. Structural Dynamics – Duke University – Fall 2014 – H.P. Gavin and integrable. Going the other way, fˆ(t; F) = q=+∞ X Fq eiωq t q=−∞ = F0 + q=−1 X iωq t Fq e + q=−∞ = F0 + q=+∞ X q=+∞ X q=1 F−q e−iωq t + q=+∞ X q=1 = F0 + = F0 + = F0 + ∞ h X q=1 ∞ h X q=1 ∞ h X Fq eiωq t Fq eiωq t q=1 Fq eiωq t + F−q e−iωq t i i (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 = F−q 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 2πq 1ZT 2πq Fq = (aq − ibq ) = f (t) cos t − i sin t 2 T 0 T T 2πq 1ZT f (t) exp −i = t dt T 0 T (10) Since the integrand, f (t)e−iωq 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 −iωq t f (t)e dt = Z τ −iωq t f (t)e dt + Z T +τ −iωq t f (t)e dt − τ 0 Z T +τ f (t)e−iωq t dt. T But, since the integrand is periodic in T , Z τ −iωq t f (t)e dt = Z T +τ f (t)e−iωq t dt . T 0 So, the interval of integration can be shifted arbitrarily. Z T 0 f (t)e−iωq t dt = Z T +τ f (t)e−iωq 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 −iωq t 2 + b2 . If fˆ(t) = ˆ(t + τ ) = P Fq e−iωq (t+τ ) = P (Fq e−iωq τ ) e−iωq t , and a F e , then f q q q 2 |Fq | = |Fq e−iωq τ |. CC BY-NC-ND H.P. Gavin 5 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 6 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 eiωq 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) e−iωq 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 ) eiωq t ∆ω , 2π q=−∞ F (ωq ) = Z T /2 f (t) e−iωq t dt . P → 1 Z∞ F (ω) eiωt dω , 2π Z −∞ ∞ F (ω) = (16) −T /2 Finally, taking the limit as T → ∞, implies ∆ω → dω and f (t) = (15) f (t) e−iωt dt . R (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 7 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 2πqt X 2πqt 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 2πqt = f (t) cos dt , T −T /2 T 2 Z T /2 2πqt = 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 eiωq t = q=−Q X 1 q=Q F (ωq ) eiωq t T q=−Q (22) ∗ where eiωq t = cos ωq t + i sin ωq t, ωq = 2πq/T , Fq = 12 (aq − ibq ), Fq = F−q , and 1 Z T /2 f (t) e−iωq 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 Gibb’s 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 2πqn 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 2πqn 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 = 2πq/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/(2∆t) Hertz, which is called the Nyquist frequency. P P CC BY-NC-ND H.P. Gavin 8 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 − mωq2 ) + i(cωq ) (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 iωq t = q=∞ X q=−∞ (k − 1 mωq2 ) + i(cωq ) Fq eiωq t (27) where ωq = 2πq/T . q Note that ωq is not the same symbol as ωn . The natural frequency, k/m, has the symbol ωn . The symbol ωq = 2πq/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 9 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 = 2πq/T . The system is a forced spring-mass-damper oscillator, ẍ(t) + 2ζωn ẋ(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) 1 0.5 0 -0.5 -1 -0.2 -0.3 -0.4 -0.5 -0.6 -1.5 -0.7 -3 -2 -1 (a) 0 1 2 3 0 (b) time, t, (s) 2 4 6 8 10 12 14 16 frequency, ω, (rad/s) 1 1.5 0.1 frequency response cosine and sine terms 1 0.5 0 -0.5 0.01 0.001 -1 1e-04 -1.5 -3 -2 -1 (c) 0 1 2 0 3 (d) time, t, (s) 2 4 6 8 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) 1 2 3 (f) 0 2 4 6 8 10 frequency, ω, (rad/s) Figure 1. (a): — = f ext (t); - - = f˜ext (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 3 0.4 Fourier coefficients, Fq, (N) 4 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) 0 1 2 3 0 (b) time, t, (s) 2 4 6 8 10 12 14 16 frequency, ω, (rad/s) 1 2 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) 0 1 2 0 3 (d) time, t, (s) 6 8 10 12 14 16 12 14 16 150 100 phase lead, (degrees) 0.02 response, x, (m) 4 frequency, ω, (rad/s) 0.04 0 -0.02 -0.04 -0.06 50 0 -50 -100 -150 -200 -0.08 (e) 2 -3 -2 -1 0 time, t, (s) 1 2 3 (f) 0 2 4 6 8 10 frequency, ω, (rad/s) Figure 2. (a): — = f ext (t); - - = f˜ext (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 1 2 0.2 0.1 3 0 (b) time, t, (s) 2 4 6 8 10 12 14 16 frequency, ω, (rad/s) 1 1.5 1 0.1 frequency response cosine and sine terms 0.3 -0.1 -3 0.5 0 -0.5 0.01 0.001 1e-04 -1 1e-05 -1.5 -3 -2 -1 (c) 0 1 2 0 3 (d) time, t, (s) 0.02 200 0.015 150 0.01 100 0.005 0 -0.005 2 4 6 8 10 12 14 16 12 14 16 frequency, ω, (rad/s) phase lead, (degrees) response, x, (m) 0.4 0 (a) 50 0 -50 -0.01 -100 -0.015 -150 -200 -0.02 (e) 0.5 -3 -2 -1 0 time, t, (s) 1 2 3 (f) 0 2 4 6 8 10 frequency, ω, (rad/s) Figure 3. (a): — = f ext (t); - - = f˜ext (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 saw−t 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 2∗Q 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/(2∗Q) = −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/(2∗Q) = p i /Q % t s (2∗Q) = (Q−1)∗ 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 time−r 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 (2∗Q) = (Q−1)∗ 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 % ======================================================================= % Steady−s 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 % Complex−v 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 ) ]; % re−s 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 = 2∗Q 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/2−1 (N/2−2)∗ d t f max −2∗ d f = ( N/2−2)∗ d f N/2 (N/2−1)∗ d t f max−d f = ( N/2−1)∗ 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 : : : : N−2 (N−3)∗ d t −3∗ d f N−1 (N−2)∗ d t −2∗ d f N (N−1)∗ d t −d f −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− CC BY-NC-ND H.P. Gavin