<<

fourier.nb 1

The Transform

The Fourier transform is crucial to any discussion of analysis, and this chapter discusses the definition of the transform and begins introducing some of the ways it is useful.

We will use a Mathematica-esque notation. This includes using the symbol I for the square root of minus one. Also, what is conventionally written as sin(t) in Mathematica is Sin[t]; similarly the cosine is Cos[t]. Finally, the irrational number 2.71828... is represented by the symbol E.

The contents of this chapter are:

Fourier Series Fourier Transform Example and Interpretation Oddness and Evenness The Theorem Discrete Fourier Transforms Definitions Example Implementation Author

Ã

Recall the Fourier series, in which a f[t] is written as a sum of and cosine terms:

a ˆ ˆ f t cccccc0  a Cos nt  b Sin nt 2 n n n 1 n 1

or equivalently:# ' Å # ' Å # ' ˆ ˆ Int f t cnE cn Cos nt  I Sin nt n ˆ n ˆ

The coefficients# ' are foundÅ from the fact thatÅ the sine+ and cosine# ' terms are orthogonal,# '/ from which: fourier.nb 2

1 2 S an cccc  f t Cos nt Åt S t 0 2 S 1 Ã # ' # ' bn cccc  f t Sin nt Åt S t 0 Fourier series are used,Ã for example,# ' to# discuss' the harmonic structure of the tonic and overtones of a vibrating string.

Note that the series represents either f[t] over a limited range of 0 < t < 2S, or we assume that the function is periodic with a period equal to 2S.

Also note that, as opposed to the Taylor series, the Fourier series can represent a discontinuous func- tion:

f+t/ 1 0.8 0.6 0.4 0.2 t S S 2S 3S 1 2 Sin t Sin 3t Sin 5t f t cccc  cccc  cccccccccccccccccc  cccccccccccccccccccccc  cccccccccccccccccccccc  ... 2 S 1 3 5 # ' # ' # ' # ' - 1 Ã Fourier Transform

In the previous section we defined the series over the interval (0, 2S). Say instead we are interested in the interval (-L, L). Then the coefficients in the Fourier series are: 1 L nSt an cccc f t Cos cccccccccc Åt L L L 1 à L # ' $ nSt ( bn cccc f t Sin cccccccccc Åt L L L Thus we write the seriesà of# f as' a function$ of a dummy( variable x as: fourier.nb 3

f x ˆ 1 L 1 nSx L nSt #cccccccc'  f t Åt  cccc  Cos cccccccccc  f t Cos cccccccccc Åt  2L L L L L L n 1 È # ' Æ $ ( à # ' $ ( 1 nSx L nSt cccc  Sin cccccccccc  f t Sin cccccccccc Åt L L L L n 1 Æ $ ( à # ' $ ( The relation:

Cos T1 T2

Cos T2 T1 Cos T1 Cos T2  Sin T1 Sin T2 # ' allows us to rewrite the expansion as: # ' # ' # ' # ' # ' 1 L 1 ˆ L nS f x cccccccc  f t Åt  cccc  f t Cos ccccccc  t  x Åt 2L L L L n 1 L

Let L ‘ˆ#, ie.' let the intervalà (-L,# L) 'go to (-ˆ, ˆ). ÅWe Ãwrite:# ' $ + /( nS Z ccccccc L S 'Z cccc L The meaning of 'Z is that it is the amount that Z changes for each time in the sum that n goes to n + 1. The first term in the series is the DC component of f[t]. In the limit as L ‘ ˆ, the must be either or zero; the latter is the only reasonable choice. So we now can write the expansion as:

1 ˆ ˆ f x cccc  'Z f t Cos Z t  x Åt S ˆ n 1

Recall the# notation,' usefulŠfor multipleà # ' that:# + /'

f x, y Åx Åy Åy Åxf x, y

In the expressionà -à #for f[x],' we replace1 the sumà with Ãan integral:# ' fourier.nb 4

1 ˆ ˆ f x cccc  ÅZ Åtf t Cos Z t  x S 0 ˆ 1 ˆ ˆ # cccccccc'  ÅZà ÅÃtf t #Cos' Z #t + x /' 2S ˆ ˆ Since the sine is odd:à à # ' # + /' Sin T Sin T

we can write: # ' # ' 1 ˆ ˆ 0 I cccccccc  ÅZ Åtf t Sin Z t  x 2S ˆ ˆ L \ Adding this to the expressionM à for f[x] Ãgives: # ' # + /'] N ^ 1 ˆ ˆ f x cccccccc  ÅZ eIZx Åtf t eIZt 2S ˆ ˆ

The Fourier# transform' F1[ZÃ] of f[t] is: Ã # '

ˆ IZt F1 Z f t e Åt ˆ # ' # ' Note that it is a functionà of Z. If we interpret t as the time, then Z is the angular . Thus we have replaced a function of time with a spectrum in frequency.

The inverse Fourier transform takes F[Z] and, as we have just proved, reproduces f[t]:

ˆ 1 IZt f t cccccccc  F1 Z e ÅZ 2S ˆ # ' # ' You should be aware that thereà are other common conventions for the Fourier transform (which is why we labelled the above transforms with a subscript). For example, some texts use a different normalisa- tion:

ˆ 1 IZt F2 Z cccccccccccccc  f t e Åt 2S ˆ # ' r à # ' fourier.nb 5

ˆ 1 IZt f t cccccccccccccc  F2 Z e Åt 2S ˆ # ' r à # ' Still others reverse the transform and its inverse:

ˆ 1 IZt F3 Z cccccccccccccc  f t e Åt 2S ˆ # ' r à # ' ˆ 1 IZt f t cccccccccccccc  F3 Z e Åt 2S ˆ # ' r à # ' The only difference between the "type-2" definition and the "type-3" one is the relative signs of the real and imaginary parts of the transforms.

By default, Mathematica uses this "type-3" definition of the Fourier transform. In this class we will almost always be using the "type-1" convention.

Say we have a function of the position x: g[x]. Then the type-1 Fourier transform and inverse transform are: ˆ Ikx G1 k g x e Åx ˆ

and: # ' à # ' ˆ 1 Ikx g x cccccccc  G1 k e Åk 2S ˆ In this case# the' transform isà a function# ' of the k = 2S/O.

à Example and Interpretation

Say we have a function: fourier.nb 6

nS f t_ : Sin Z0 t ; Abs t ccccccc Z0 nS f#t_' : 0 ;# Abs'st – ccccccc# ' Z0

where Abs# is Mathematica' s 's function# 'for an . Also, the t_ means any variable, and := is the form of equal sign used in function definitions. The /; imposes the conditions under which the definition applies.

For n = 5 and Z0 = 100, this looks like:

f+t/ 1

0.5

t -0.4 -0.2 0.2 0.4 -0.5

-1

Increasing n to 10 increases the number of cycles:

f+t/ 1

0.5

t -0.4 -0.2 0.2 0.4 -0.5

-1

The Fourier transform is:

ˆ nSsZ0 IZt IZt F Z f t e Åt Sin Z0 t e Åt ˆ nSsZ0 This evaluates# ' to: à # ' à # '

2 Sin Z ZnS Z Sin Z ZnS Z I cccc cccccccccccccccccccccccccccccccc0 cccccccccccccccc0cccc  cccccccccccccccccccccccccccccccc0 cccccccccccccccc0cccc S 2 Z0 Z 2 Z0 Z  #+ / s ' #+ / s ' where of course I used$ Mathematica to actually do the integration. ( + / + /

For Z ž Z0 and Z0 large: fourier.nb 7

1 Sin Z ZnS Z IF Z cccccccc  cccccccccccccccccccccccccccccccc0 cccccccccccccccc0cccc 2S 2 Z0 Z  #+ / s ' For n = 5 and# Z'= 100, the right hand side of the above looks like: 0 + / 0.03

0.02

0.01

60 80 100 120 140 160

The zeroes in the above occur at: Z Z GZ cccccccccccccccc0 n ccccccc n ”1, ”2, ”3, ... Z0 Z0 Since the contributions outside the central maximum are small, we may take: Z GZ cccccc0 n to be a measure of the width of the peak.

For n = 10 and the same value of Z0 the plot looks like:

0.06

0.04

0.02

60 80 100 120 140 160

Clearly, the width of the curve is now decreased.

Curves such as the above will occur sufficiently often that we will give the function that generates them a name: the sinc: Sin Sx Sinc x  ccccccccccccccccccccc Sx # ' One interpretation# 'of the above Fourier transform is that F[Z] is the frequency spectrum of a sine signal f[t] which is varying in time; thus Z is the . The main frequency component fourier.nb 8

occurs at the frequency of the , Z0, but there are other frequency components that cancel out the signal for values of the time whose absolute value is greater than nS/Z0. If we think about letting n go to infinity, then the sine wave is non-zero for all values of the time from -ˆ to ˆ; in this case the

width of the Fourier transform goes to zero and become a centered at Z0.

Thus if we have an infinite sine wave but only measure it for a finite period of time, the measurement will introduce "sidebands" in the frequency spectrum.

Another interpretation of the transform is that the symbol t is the finite width of a slit; the Fourier transform of f[t] is then the of the pattern of the slit. The fact that a wider slit produces a narrower transform means that to get, say, good of the high tones from a loud- speaker requires that the speaker be small.

Yet another interpretation is that f[t] is the amplitude of an electromagnetic wave that is passing by us. The period of the sine wave itself is 2S T cccccccc Z0

and there are n cycles of the sine wave in f[t], so it takes a time: 2S 't n cccccccc Z0 for the wave to pass us.

The width in the peak of the Fourier transform is a way of saying there is an uncertainty in the "true" value of the frequency. But we know from Planck that the frequency is related to the E accord- ing to: h E cccccccc Z 2S Thus, the uncertainty in the frequency corresponds to an uncertainty in the energy: h 'E cccccccc GZ 2S

Above we estimated GZ to be Z0/n so: h Z 'E cccccccccccc0 2S n fourier.nb 9

Thus: ´h Z nS 'E 't cccccccccccccc0 2 ccccccc h 2S n Z0 This is just a form of the Heisenberg !

à Oddness and Evenness

Symmetry arguments in Fourier theory often allows us to show directly that certain integrals vanish without needing to evaluate them. Also, often symmetry considerations allows us the reduce the limits of integration, which again can symplify calculations.

An even function e[t] is one such that e[-t] = e[t]; an example is the cosine. An odd function o[t] is one such that o[-t] = -o[t]; an example is the sine. Given an arbitrary function f[t], we can extract the even and odd parts of it:

e t 1 2 f t  f t o t 1 2 f t  f t # ' s + # ' # '/ and: # ' s + # ' # '/ f t e t  o t

In general e and o are complex. # ' # ' # ' The Fourier transform of f[t] is: ˆ F Z f t eIZtÅt ˆ ˆ # ' eÃt # o' t  Cos Zt  I Sin Zt Åt ˆ ˆ ˆ à +e#t' Cos #Zt'/Å+t #I ' o t Sin# Zt'/Åt ˆ ˆ ˆ ˆ Ã2 # e' t Cos# 'Zt Åt Ã2I # 'o t #Sin' Zt Åt 0 0 Thus, for example,à if f[t]# has' an even# part' that is real andà an #odd' part that# is 'imaginary, its Fourier transform is real. fourier.nb 10

à The

I hope that after going through some of the interpretations of the Fourier transform above, you are already convinced that it is one of the "keys to the universe." Here we present one of the most impor- tant keys in the context of time series analysis.

Imagine we have a function f[t] whose Fourier transform is F[Z], and another function g[t] whose transform is G[Z]. Then the convolution is: ˆ f t g t f u g t  u Åu ˆ

We write #g[t '- u] in terms# ' of theà inverse# Fourier' # transform:' 1 ˆ g t  u cccccccc  G Z EIZ +t  u/ÅZ 2S ˆ Thus: # ' à # ' ˆ 1 ˆ f t g t f u  cccccccc  G Z EIZ +t  u/ÅZ Åu ˆ 2S ˆ 1 ˆ ˆ # cccccccc'  #G'Z EÃIZt # 'f u EÃIZu#Åu'ÅZ 2S ˆ ˆ But the right hand Ãintegral# above' is justà the Fourier# ' transform of f[u], so: 1 ˆ f t g t cccccccc  F Z G Z EIZtÅZ 2S ˆ In words: # ' # ' à # ' # '

The inverse Fourier transform of a of Fourier transforms is the convolution of the original functions.

Here is an example. The Fourier transform of a is just the rectangle function that in the Convolution chapter we gave the symbol ¾: fourier.nb 11

F#Z' ¾ f#t' Sin#Z0t's+Z0t/

t Z Z0 Z0

Thus F[Z] only passes with an absolute value less than Z0. So if we convolve a Sinc func- tion with some signal g[t], the Sinc is performing as an ideal "low pass ."

The example shows that we can consider the design of a filter in two separate domains:

1. In the we can just multiply the Fourier transform of the original time series by some desired filter, a low pass filter in the above example.

2. In the , we can convolve the time series with the inverse Fourier transform of the desired filter.

The fact that the amplitude of the Sinc function approaches zero asymptotically as t ‘ ±ˆ means that doing the full convolution would require measuring f[t] from t = -ˆ to t = +ˆ. Since this is physically impossible, we have proved that the ideal low pass filter can not be built.

à Discrete Fourier Transforms

So far in this chapter we have only considered continuous functions f[t]. Here we extend to a time series that is a sample of f[t]. This section is divided into three subsections: Definitions, Examples, and Implementation.

‚ Definitions

If f[t] is a times series of length n, then we replace the continous Fourier transform: ˆ F Z f t eIZtÅt ˆ

with a sum:# ' Ã # '

n  1 I Zj tk F Zj f tk E ' k 0 L \ M ] # ' M Å # ' ] N ^ fourier.nb 12

We wish to evaluate tk in the above. Recall that ' is the sampling interval so the time is:

tk k '

Imagine that f[t] is periodic and we have sampled over one complete period T so f0 = fn. Then: T n '

In order to evaluate Z j we will think for a about Fourier series. The term Z0 is zero and is the DC component, corresponding to the a0 term in the series. The next term: 2S Z cccccccc T corresponds to the first allowed , which for a vibrating string is the tonic and determines the note that is being played:

The next term is: 2S Z 2 cccccccc T and represents the- first harmonic1 of a vibrating string:

So in general the frequencies are: 2S Z j cccccccc j T - 1 fourier.nb 13

So now we can write the discrete Fourier transform as:

n  1 n  1 Ij+ cccccc2 S / k' I2S jks n F Zj fk E T ' fk E ' k 0 k 0 L \ L \ M ] M ] To get the# inverse' FourierM Å transform: ] M Å ] N ^ N ^ ˆ n  1 1 Z 1 Z f t cccccccc  F Z EI tÅw cccccccc  F EI j tk GZ k 2S 2S j ˆ j 0 ML ]\ # ' # ' M Å ] The value of GZ is just how Ãmuch Z changes with eachM change from j to j + 1. We] just saw that it is: j N ^ 2S 2S GZ cccccccc cccccccc T n' So the discrete inverse Fourier transform is:

n  1 1 I2S jksn 1 f tk cccc  FjE cccc n ' j ML ]\ # ' M ] Note that in both the transformM Å and its inverse, by ]making the usual choice that the sampling interval ' is one simplifies the definition.N We shall make that^ choice for the remainder of this chapter. Thus:

n  1 I2S jks n Fj fk E k 0 Å n  1 1 I2S jksn fk cccc  FjE n j 0 Å We recall that F j is a shorthand for F[Z j], where:

2S 2S Zj j cccccccc j cccccccc n' n - 1 - 1 and that fk is a shorthand for f[tk], where: fourier.nb 14

tk k' k

‚ Example

As already mentioned, the built in discrete Fourier transform routines in Mathematica use a different convention than we use by default in these notes. Earlier, we called Mathematica's choice a "type-3" definition, so we write:

n 1 I2S +j1/+k1/sn F3 j cccccccccc  f k E n k 1 ## '' ## '' Here the sign of the exponentialr Å is different than the type-1 definition. Also note that k goes from 1 through n, because that is the way the Mathematica accesses members of a list. Recall that we usually write the elements of a time series as:

timeSeries f0,f1,f2, ... , fn1

Then Mathematica's access of elements of the list is: 

timeSeries k fk1

The Mathematica function implementing this definition is called Fourier. ## '' The inverse Fourier transform in Mathematica, InverseFourier, is:

n 1 I2S +j1/+k1/sn f3 k cccccccccc  F3 j E n j 1 ## '' ## '' It is fairly simple to use Mathematicar Å 's functions to implement the "type-1" conventions that we have been using, but in this subsection we will not bother. The only real difference between the two conven- tions is the signs of the real and imaginary parts and the normalisation.

Say we have a n = 200 element time series of five cycles of a sine wave: fourier.nb 15

A sampled sine wave 1

0.5

50 100 150 200 -0.5

-1

The period is 40, so the angular frequency is 2S/40.

Then using Fourier on the time series gives us the transform, whose absolute values are:

Fourier transform 7 6 5 4 3 2 1

50 100 150 200

Note: there is a bug somewhere in the Mathematica ‘ PostScript ‘ PDF sequence that puts a superflu- ous dot on the vertical axis of the above plot. It should not be there. I am working with the vendor of Mathematica to try to find and fix the bug.

Almost all the values are close to with zero. The sixth element has a value of 7.07. In the previous sub- section we showed that the frequency values in the Fourier transform are: 2S 2S Z j cccccccc j cccccccc j T n' which here is: - 1 - 1 S Z j cccccccccc j 100 The maximum in the- transform1 occurs at the sixth element, which corresponds to j = 5. Thus: S S Z 5 cccccccccc ccccccc j 100 20 This is precisely the- frequency1 of the original sine wave.

Note that element 196 of the Fourier transform also has a value of 7.07. This is called an "alias" of the peak occuring in the sixth element. If you go through the Fourier transform definitions above you can fourier.nb 16

convince yourself that the frequency can just as well be a negative number as a positive one. The alias is a representation of the negative frequency component of the Fourier transform. Ideally we would like it to look something like:

Ideal plot of the Fourier transform

Z

Note: the above plot also shows the same bug as the previous one. There is an extra dot high on the vertical axis. Ignore it.

But since the Fourier transform is just a list of numbers, not {frequency, number} pairs, Mathematica couldn't do that. Instead it joined the negative frequency values to the end of the positive frequency ones.

We will have a lot more to say about in the next chapter.

‚ Implementation

One "brute force" way of calculating the sums of a Fourier transform is to define:

W  EI2Ssn

Then:

n  1 n  1 I2S jks n jk Fj fk E fkW k 0 k 0

We can think of Åf as a vector of length n, and WÅ as a matrix of dimension n l k. This multiplication requires n2 calculations, and evaluating the sum requires a smaller number of operations to generate the powers of W. Thus calculating the Fourier transform this way is a O(n2) process. Doubling the number of points in a time sample quadruples the time necessary to calculate the transform; tripling the number of points requires nine times as much time. fourier.nb 17

However, there is a algorithm that can give an immense improvement. The basic idea is that we split the sum into two parts:

ns2  1 ns2  1 I2S j2ks n I2S j +2k  1/s n Fj f2k E  f2k 1 E k 0 k 0

The first sum involvesÅ the even terms in f, and the secondÅ sum the odd ones.

Using the same W as before, we can write:

ns2  1 I2S jks+ns2/ Fj f2k E  k 0 nÅs2  1 k I2S jks+ns2/ e k o W  f2k 1 E Fk  W Fk k 0

Å e o We can apply the same procedure recursively to the sums represented by Fk and Fk . Eventually, if n is a power of two, we end up with no summations at all, just a product of terms.

It turns out that this procedure is O(n log2n). So, doubling the number of points in the time series only doubles the time necessary to calculate the transform using this algorithm, and tripling the number of points increases the time by about 4.75.

Many people treat this Fast Fourier Transform as "magic", and it is does seem magical in its properties. But notice that it all hinges on n being a power of two. For example, if one constructs a time series:

32700 timeSeries Ets+32700s6/ t 1

the values range from 0.999817Å to 0.00247. Mathematica's Fourier in one computing environment took 13.12 seconds to transform this series. Since the last terms in the series are so close to zero, it is quite reasonable to add zeroes to the end of the time series. We added 68 zeroes, so the total length of the series becomes 32,768 = 215. Now it took Fourier only 5.16 seconds to do the transform.

The lesson, then, is that if one is taking data in the lab and later the data will be Fourier transformed, if there is a lot of data the total number of data points should always be a factor of two. fourier.nb 18

à Author

This document is Copyright © David M. Harrison, 1999. It was prepared using Mathematica, which produced a PostScript file; Adobe Distiller was then used to prepare the PDF file. This is version 1.9 of the document, date (m/d/y) 01/28/99.