anders e. zonst-understanding the fft-citrus press (1997)

Upload: akoca23

Post on 14-Apr-2018

212 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    1/186

    Understandingthe

    FFTA Tutorial on

    the A lgorithm &Software for Laymen,Stud ents, Technicians& Working Engineers

    Anders E. Zonst

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    2/186

    To Shirley

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    3/186

    iv Und erstanding the FFT

    ACKNOWLEDGEMENTS

    A special thanks to Renee, Heather and Maureen. Withouttheir he lp you w ould have had to suffer countless instances of badgrammar, awkward syntax and incorrect spelling. Of much moreimportance, from my point of view, they have nice personalitiesand are fun to be around.

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    4/186

    CONTENTSPrologue viiIntroduction ix

    1 Starting at the Bottom 12 Fourier Series and the D FT 273 The DF T Algorithm 534 The Inverse Transform 71

    Part II - The FFT5 Four Fundam ental Theorems 816 Speeding-Up the DFT 1037 The FFT 1158 Anatom y of the FFT Program 135Appendix 1 BASIC Programm ing Language 155Ap pend ix 5.1 DFT5.1 (Core Program Listing) 159Ap pend ix 5.2 DFT5.2 (Theorem Routines Listing) 162Ap pend ix 5.3 Proof of the Theorem s 166Ap pend ix 6.1 DFT6.01 (Program Listing) 171

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    5/186

    vi Und erstanding the FFT

    Appendix 6.2Appendix 6.3Appendix 7.1

    Modification to DFT6.01Modification to DFT6.01Vector RotationBibliographyIndex

    173173174177179

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    6/186

    PROLOGUE

    "Considering how many fools can calculate, it is surprisingthat it should be thought either a difficult or a tedious task for anyother fool to learn how to master the same tricks.Some calculus-tricks are quite easy. Some are enormouslydifficult. The fools who write the text books of advanced mathem aticsand they are mostly clever foolsseldom take the trouble toshow you how easy the easy calculations are. On the contrary, theyseem to desire to impress you with their tremendous cleverness bygoing about it in the most difficult way.Being myself a remarkably stupid fellow, I have had tounteach myself the difficulties, and now beg to present to my fellowfools the parts that are not hard. Master these thoroughly, and the restwill follow. What one fool can do, another can." (Prologue toCalculus Made Easy by Silvanus P. Thompson, F.R.S., 1910)Even though a great many years had passed since I firstobtained a copy of Thompson's magical little book (twenty-eighthprinting of the second edition, Macmillan Publishing Company,1959), I nonetheless recognized this prologue when a part of itappeared recently on the front page of a book. The reader shouldunderstand that Professor Thompson wasn't simply being sarcastic.His intention was, beyond question, to throw a lifeline to flounderingstudents. His goal was to provide an introduction to that powerfultool known as The Calculus; to provide a bridge for those who hadbeen victimized by their teachers and texts. Lest anyone mistake histrue feelings, he adds the following in the epilogue: "...One otherthing will the professed mathematicians say about this thoroughly badand vicious book: that the reason why it is 50 easy is because theauthor has left out all the things that are really difficult. And theghastly fact about this accusation is that it is true! That is, indeed,

    why the book has been writtenwritten for the legion of innocentswho have hitherto been deterred from acquiring the elements of thecalculus by the stupid way in which its teaching is almost alwayspresented. Any subject can be made repulsive by presenting it

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    7/186

    V11I Understanding the FFT

    plicities, and to grasp its powerful methods of problem solving,without being compelled to toil through the intricate out-of-the-way(and mostly irrelevant) mathematical gymnastics so dear to theunpractical mathematician..." (From the Epilogue and Apology ofCalculus Made Easy by Silvanus P. Thom pson, 1910. Apparentlysome things never change.)

    I cannot be sure that the coincidence of Thompson's prologue, printed boldly on the front page of an exemplary treatise onFourier Analysis, was the sole motivation for this bookI had alreadyconsidered just such an essay. Still, if Thom pson's ghost hadappeared and spoken to me directly, my task would not have beenclearer Allow me to explain: This book is intended to help thosewho would like to understand the Fast Fourier Transform (FFT), butfind the available literature too burdensom e. It is born of my ownfrustration with the papers and texts available on the FFT, and theperplexing way in which this subject is usually presented. Only afteran unnecessarily long struggle did I find that the FFT was actuallysimple incredibly simple. You do not need to understand advancedcalculus to understand the FFT you certainly do not need deliberately obscure notation and symbols that might be more appropriate to thestudy of archeology. The simple truth is that the FFT could easily beunderstood by any high school student with a grasp of trigonometry.Understand, then, that I hold heart-felt sympathy with Thompson'siconoclasm. In fact, if you swap "FFT" for "Calculus," Thom pson'sstrong words express my own feelings better than I am capable ofexpressing them myself.But there is another, perhaps better, reason for this book.Today, systems using the FFT aboundreal systemssolving realproblems. The programm ers, engineers and technicians who develop,use, and maintain these systems need to understand the FFT. Manyof these people have long since been "excommunicated" from thespecialized groups who discuss and write about this subject. It maybe acceptable for professional scholars to communicate via abstrusehieroglyphics, but working engineers and technicians need a moredirect route to their tools. This book aim s to provide a direct route tothe FFT.

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    8/186

    INTRODUCTION

    This book is written in two partsan introduction to (orreview of) the DFT, and an exposition of the FFT. It is a littlebook that can be read in a few evenings at most. Recognizing this,I recommend that you start from the beginning and read it alleach chapter builds on all that has preceded . If you are alreadyfamiliar with the DFT the first four chapters should read comfortably in a single evening.I have gone as far as I can to make this subject accessibleto the widest possible audience, including an appendix 1.1 whichprov ides a "refresher" on the BA SIC language. After that, theprogram s in Part I start out very simply with detailed explana tionsof each line of code in the text.My reason for including these features is that, some yearsago (before the advent of the personal computer), there was aperiod of several years in my life when I was "computer-less."

    When I once again obtained access to a computer I was shocked tofind that I had forgotten the comm ands and rules for program ming(even in BASIC ). To my great relief a few hours at a keyboard(with a BASIC programming manual in hand) brought backenough to get me up and running. Appendix 1.1, and the program sof part 1, are designed to accomplish the same thing with muchless pain.In addition to these comments, I should point out that theprograms presented in this book are intended to be typed into acom puter and run they actually work. If you don 't like to type,a disk with all the program listings can be furnished for $5.00(which includes postage and handling).Very well then, the first topic we will consider is: "What,actually, is the Digital Fourier Transform?"

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    9/186

    C H A P T E R ISTARTING AT TH E BO TTO M

    It has been said that a good definition first throw s the thin gto be defined into a very large pool (i.e. a very broad catego ry) andthen pulls it out again (i.e. describes the uniqu e characteristics th atdifferentiate it from the other mem bers of that category). That isthe approach we w ill use in tackling the question; "W hat, exactly,is the Fourier series?"

    1 .01 APPROXIMATION BY SERIES

    When we first encoun ter mathematical functions they aredefined in simp le, direct terms. The common trigonom etric functions, for exam ple, are defined with respect to a right triang le:

    X

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    10/186

    2 Und erstanding the FFT

    Sin(0) - Y/H (1.1)0 = angle 0Y = heightH = hypotenuse

    Cos(0) = X/H (1.2)X = base

    Tan(0) = Y/X (1.3)

    Shortly thereafter we learn that these functions may alsobe expressed as a series of terms:

    Sin(x) = x - x3/3! + x5/5! - x7/7! +... (1.4)x = angle in radians

    3!, 5!, etc. = 3 factorial, 5 factorial, etc.

    Cos(x) = 1 - x2/2! + x4/4! - x6/6! +... (1.5)

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    11/186

    FFT/01 3

    These power series are known as Maclauren/Taylor seriesand may be derived for all the commonly used trigonometric andtranscendental functions.

    1.02 TH E FOU RIER SERIES

    The Fourier series is a trigonometric series. Specifically,it is a series of sinusoids (plus a constant term), whose am plitudesmay be determined by a certain process (to be described in thefollowing chapters). Equation (1.6) states the Fourier seriesexplicitly; unfortunately, this compact notation cannot reveal the

    F(x) = A0 + A ,Cos(x) + A 2Cos(2x) + A 3Cos(3x) + ...+ B,Sin(x) + B 2Sin(2x) + B 3Sin(3x) +... (1.6)

    incredible mathematical subtlety contained within. The Fou rierseries, like the Taylor/Maclauren series shown earlier, approximates functions, but it has a different derivation and a differentpurpose . Rather than being a means of evaluating sines, cosine s,etc., at a single point, it serves as a "transformation" for the wholeof a given, arbitrary, function.

    This, then, is the general pool that we have thrown ourFourier Transform into, but we are at risk here of m aking the pool

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    12/186

    4 Understanding the FFT

    so obscure it will require m ore definition than our definition itself.The newcomer may well ask; "What is this transformation youspeak of?" Apparently we are going to transform the originalfunction into another, different, function but what is the newfunction and why do we bother? Does the transformed functionhave some special mathematical properties? Can we still obtainthe same information provided by the original function? Theanswer is yes to both of these questions but we w ill come to all ofthat later; for now we may say that the transform we are referringto, in its digital form, provides a mathematical tool of such powerand scope that it can hardly be exceeded by any other developmentof applied mathematics in the twentieth century.

    Now we move to the second part of our definitionwemust pull the defined topic out of the pond again. This part of thedefinition requires that we speak carefully and use our termsprecisely, for now we hope to reveal the specific nature of theFourier Transform. We will begin with a couple of definitions thatwill be used throughout the remainder of this book.

    1.03 FUNCTIONS

    The term function (or single valued function) is, in a sense,a "loose" term (i.e. it describes a very simple notion that can befulfilled m any different ways ). It only implies a set of orderedpairs of num bers (x,y), where the second number (y, the dependentvariable) is a unique value which corresponds to the first number

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    13/186

    FFT/01 5

    (x , the independent variable). Now, obviously, the equationsencountered in engineering and physics can provide sets ofnum bers w hich fulfill this definition, but so will any simple list ofnumbers. It is not necessary to know the equation that relates thedependent to the independent variable, nor even that the twonum bers be related by an equation at all! Th is "looseness" isessential if the term "function" is to cover the practical work thatis done with a Digital Fourier Transform (DFT), for it is seldomthat the information obtained by digitizing a signal can be described by an equation.

    1.03.1 Discontinuous Functions

    There are functions, encountered frequently in technicalwork (and especially in Fourier Analysis), that are difficult todescribe in a few words. For exam ple, the "Unit Square Wave",must be defined in some manner such as the following:

    f(x) = 1 [for 0 < x < x,] (1.7 )

    and:f(x) = -1 [for x, < x < 2x ,] (1.8)

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    14/186

    Understanding the FFT

    We make no statement about this function outside the interval of0 < x < 2x ,. Th is interval is referred to as the "domain of definition" or simply the "dom ain" of the function. We will have moreto say about the dom ain of a function and its transform shortly, butfor now le t's continue to investigate discontinuo us functions. Werequire two separate equations to describe this Square Wavefunction, but we also need some explanation: At the point x = x,the first equation ends and the second equation begins-there is no"connection" between them. The function is discontinuous at thepoint where it jum ps from +1 to - 1 . It is sometimes suggested thatthese two equations be connected by a straight, vertical line of"infinite slope", but this "connection" cannot be allowed. A connecting line of infinite slope would have more than one value (infact, an infinite number of values) at the "point" of transition . Thedefinition of a single valued function requires a single "unique"value of the dependent variable for any value of the independentvariable.

    f ( x ) = 1

    x = 0

    f ( x ) = - 1

    f(x) = Unit Square Wave

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    15/186

    FFT/01 7

    Mathematically, functions such as the unit square wavemust remain discontinuous; but, physically, such discontinuitiesare not realizable. All voltage square waves measured in alaboratory, for example, will have finite rise and fall times.

    1.04 TH E FOUR IER SERIES

    Our original question was; "What, exactly, is a Fourierseries?" We stated back on page 3 that it is a series of sin uso ids,and as an aid to the intuition, it is frequently shown that a squarewave may be approximated with a series of sine waves. Now,these sinuso ids are, in general, referred to as the "harm onics" of thewave shape, except that a sine wave which ju st fits into the dom ainof definition (i.e. one cycle fits exactly into the waveform dom ain)is called th e fundamental (see fig. 1.1A). If two cycles fit into thisinterval they are called the second harmonic (note that there is nofirst harmonic that would correspond to the fundamental). Ifthree cycles of sine wave fit into the interval they are called thethird harmonic, etc., etc. A square wav e, as described in thepreceding section, consists of, in addition to the fundam ental, onlythe "odd" numbered harm onics (i.e. 3rd, 5th, 7th, etc., etc.), all ofwhose amplitudes are inversely proportional to their harmonicnumber. Caveat: To represent a square wave perfectly by Fourierseries, an infinite number of harmonic components would berequired. That is to say, the Fourier series can never perfectlyreproduce such functions; however, it can reproduce them to anydesired degree of accuracy, jus t as the Taylor series shown in eqn s.

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    16/186

    8 Und erstanding the FFT

    (1.4) and (1.5) will converge to any desired accuracy (anothercaveat: convergence of the Fourier series is not a simple subjectbut that discussion diverges from our immediate purpose).In figure 1.1 w e show ho w a summation of odd harm onicsbegins to form a square wave. Even though we only sum in thefirst four components, it is apparent that a square wave is beginning to form.

    A . - Fundam ental & 3rd Harm onic lst + 3rd

    B . - l s t + 3 r d & 5 t h lst+3rd+5th

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    17/186

    FFT/01 9

    l s t+3rd+5 th&7th lst+3rd+5th+7thFigure 1.1 - Construction of a Square Wave.

    In figure 1.2 below, we show the results of sum ming in 11com ponents and 101 com ponents. We note that with 101 com ponents the approximation is very good although not perfect. Thebasic idea illustrated here, however, of approximating the wave-

    Summ ation of 11 components 101 componentsFigure 1.2

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    18/186

    10 Un derstanding the FFT

    form of a function by summing harmonically related sinusoids, isthe fundamental idea underlying the Fourier series. The implication is that any function may be approximated by summingharmonic components (is this true?)

    1.05 DIS C RE TE DATA

    Let's take the time now to point out a distinct characteristic of the above "curves." In this book the graphs will usuallyshow what actually happens in digital systems they will displaymathematical "points" plotted at regular intervals. W hile the UnitSquare Wave of section 1.03.1 is discontinuous at the transitionpoint, the functions of figs. 1.1 and 1.2 are discontinuous at everypoint. Th is is not a trivial phenomenon a series of discrete datapoints is not the same thing as a continuous curve. We suppose the"continuous curves," from which we extract discrete data points,are still somehow represented; but, this supposition may not bejustified. Th is characteristic of sampled data systems, and ofdigital systems in general, creates idiosyncracies in the DFT thatare not present in the continuous F ourier series (e.g. the subtletiesof convergence, which were hinted at above, are obviated by the

    finite series of the DFT ). Put simply, our situation is this: If wetreat discrete functions carefully, we may think of them asrepresen ting underlying linear functions. If, on the other hand , weare careless, the relationship of the discrete function to what wesuppose to be the underlying linear function may be completelyunfounded (perhaps w e can discuss such things in another book).

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    19/186

    FFT701

    1.06.1 COMPUTER PROGRAMS

    It is anticipated that most readers w ill have som e familiarity with computer programming; but, if not, don't be intimidated.We will start with very simple examples and explain everything weare doing . Generic BASIC is pretty simple, and the examples willgradually increase in difficulty so that you should have no troublefollowing what we are doing . Understand, however, that theseprograms are not just exercisesthey are the book in the sameway that this text is the book. This is what you are trying to learn.Type these programs into a computer and run themexperimentwith them (but be careful, th is stuff can be addictive). If youhave no familiarity with BASIC at all, or if you have not usedBA SIC in years, you might w ant to read Appendix 1.1 at this time .

    1.06.2 PROGRAM DESCRIPTION

    The "square wave" illustration of Figures 1.1 and 1.2 is ourfirst programming exam ple. DFT 1.0 (next page) is essen tially theroutine used to generate those figures, and its operation is completely illustrated by those figures.

    BASIC ignores remarks following REM statements (seeline 10). Line 12 asks how many terms we want to sum toge therand assigns this value to N . Line 20 defines the value of PI. Inline 30 we set up a loop that steps the independent variable th rough

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    20/186

    12 Understanding the FFT

    10 REM *** DFT 1.0 - GENERATE SQUARE WAVE ***12 INPUT "NUMBER OF TERMS";N20 PI = 3.14159265358*30 FOR I = 0 TO 2*PI STEP PI/832 Y=040 FOR J=l TO N STEP 2: Y=Y+SIN(J*I) /J: NEXT J50 PRINT Y60 NEXT I70 END

    Fig. 1.3-DFT 1.0

    2*PI radians (i.e. a full cycle of the fundamental) in increments ofPI/8 (if you do not understand the loop structure set up betweenlines 30 and 60 read appendix 1.1 no w). The "loop counter" forthis loop is the variable I, which we also use as the independentvariable for the equation in line 40 . The loop counter I steps inincrements of PI/8, yielding 16 data po ints. Line 32 clears thevariable Y which will be used to "accumulate" (i.e. sura together)the values calculated in the "one line loop" at line 40. Mathematically, line 40 solves the following equation:

    Y = SIN(I*J)/J (for all odd J) (1.9)J = harmonic numberI = argument of the fundamental

    Note that division by the harmonic number (J) yields valuesinversely proportional to the harmonic number. Line 40 is theheart of the prog ram. It is a loop which counts the variable J "up"

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    21/186

    FFT/01 13

    from 1 to the num ber of harmonic terms we requested at line 12(i.e. "N "). It should be apparent that we are com puting thecontribution of each harmonic to the waveshape at a given point onthe x axis (refer to fig. 1.1 if this is not clear). Each time w e passthrough the loop, J is incremented by two, so that it takes on onlyodd harm onic values. Each tim e through the loop we will sum thefollowing into the variable Y:

    1) The value it already has (which is zero the first timethrough the loop), plus...2) SIN(I*J)/J.

    Since I is the value of the argument (in radians) of thefundamental, it will be apparent that I*J represents the "d istance"we have progressed through the Jth harmonic component.W hen all of the harmonic terms have been summ ed in (i.e.J = N ), we move down to line 50 and print the result. At line 60we encounter the NEXT I statement, jum p back to line 30, increasethe variable I by PI/8 radians, and compute all of the harmonicterms for the next position along the x axis.

    1 .07 EXPERIMENTATION/PRACTICE

    The reader should type the above program into a com puterand run it. Once you have it working, try variations sum uphundreds (or even thousands) of harmonic componentsm odifythe mathematical function itself. A simple modification willproduce a "ramp" or "sawtooth" function (as opposed to thesquarew ave). Simply allow the loop counter in line 40 (i.e. J) to

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    22/186

    14 Und erstanding the FF T

    step through all of the harmonic numbers (i.e. remove the optional"STE P 2 " statement in line 40).

    Figures 1.4.x ( where "x" indicates "don't care") showsome of the waveshapes that m ay be obtained along w ith the variations required to the equation in line 40. These curves illustrate theeffect obtained by simple modifications of the "spectrum" (i.e. theam plitudes and phases of the harmonic com ponents). Afterplaying with this program, and generating a sufficiently largenumber of functions, we might suspect that any of the commonwaveshapes encounter in engineering could be produced byselecting the correct spectrum. There are an infinite number of

    Fig. 1.4.1 - Y=Y+Sin(J*I)/J for all terms.

    Fig. 1.4.2 - Y=Y-Cos(J*I)/(J*J) for odd terms.

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    23/186

    FFT/01 15

    Fig. 1.4.3 - Y=Y+Sin(I*J)/(J*J) for odd terms.

    Fig. 1.4.4 - Y=Y+Sin(I*J)/(J*J) for all terms.

    Fig. 1.4.5 - Y=Y+Cos(I*J)/J for odd terms.

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    24/186

    16 Und erstanding the FF T

    Fig. 1.4.6 - Y=Y-(-l)AJ*Cos(J*I)/(4*J*J-l) for all terms.Initialize Y to Y = 0.5

    combinations of amplitudes and phases for the harmonic components, which correspond to an infinite number of time domainwaveshapes; unfortunately, this falls short of proving that artywaveshape can be produced by this means.In any case the above illustration has the cart before thehorse. We are almost always provided w ith a tim e domain wave

    shape for which we must find the equivalent frequency domainspectrum . It is apparent here that one of the underlying assumptions of generalized Fourier Analysis is that time domain signalsmust, in fact, have frequency domain equivalents.

    1.07.1 FREQUENCY DOMAIN

    Figure 1.5 plots the amplitudes of the harmonic components against the harmonic num ber of the component, displaying

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    25/186

    FFT/01 17

    the "spectrum" of a square wave. Now, in accordance with o urearlier definition of a function, we recognize that this spectrum isitself a function. The harm onic number (or more com monly theequivalent frequency) represents the independent variable of thisfunction, and the amplitude of the harmon ic componen t represen ts

    Amplitude

    FrequencyFigure 1.5 - Square Wave Spectrum

    the dependent variab le. The total interval of the frequenciesrepresents the domain of this new function; consequently, we referto this function as the frequency domain function. It is thisfrequency domain function that we seek to obtain with FourierAnalysis (i.e. the transformation from the time domain to thefrequency domain).It should be apparent that the frequency domain functiondescribes the same entity as the time dom ain function. In the timedomain all of the sinusoid components are summed together intothe resultant. In the frequency dom ain, however, we separate out

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    26/186

    18 Un derstanding the FF T

    the components and plot the amplitudes (and phases) of the individual sinu soids . It should be absolutely clear, then, that we arelooking at the same thing here.

    1.07.2 REA LITY OF THE FREQUENC Y DO MAIN

    When first presented with the proposition that all timedomain waveshapes are composed of sinusoids, we tend toquestion the physical reality of the com ponen ts. We "know" thatthe time domain signal is the "real" signal and the frequencycom pon ents are "just another way of analyzing things." Seasonedveterans, however, have no difficulty accepting the sinusoids ascom pletely real. Let us stop here and ask, once and for all, are thesinusoids real? Or are they only mathematical gimm icks? Or isthis, in fact, a moot question?The education of electrical engineers, for example, isgrounded in the frequency d om ain. They are taught to think interms of the frequency dom ain. They are taught to test theircircuits by driving the input with a sinusoid while observing theoutput. By repeating this test for a range of frequencies theydetermine the frequency response of their circu its. As a specificexam ple, they rarely think about audio in the time dom ain musicis an ever changing kaleidoscope of fundamentals and harmonics.Elsewhere, they learn that modifying the frequency response of acircuit in certain w ays will achieve predictable modifications to thetime response, e.g. low pass filtering will reduce the higherfrequency com ponen ts thereby reducing noise, slowing rise times,etc. This sort of experience, coupled with the knowledge thatwaveforms can be viewed as summations of sinusoids, leads thestudent into aparad igm that actually prefers the frequency dom ain.Engineers can always arrive at completely logical and self-consistent conclusions in the frequency domain, and frequently

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    27/186

    FFT/01 19

    with much less work than in the time domain. After working inthe field for a few years the notion of frequency domain takes ona sense of reality for engineers and technicians that others may notshare.

    10 UOLTS

    ( 5 0 0 < 1 E 1

    y 2 E - 7 2 E - 71 E 1 < 5 0 0 5 E - 1 0H h

    2N2222R (5E 3

    5E3

    ~V-( 2 . 7 E 32N2222A

    2N2222R

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    28/186

    20 Und erstanding the FFT

    2 009 .6 07 204 802 400 .0 0

    H U L T I U I B 1 . N E T

    1.60 3 .2 0 4 .8 0Ti f t * In nS(8 .0000> 6 .40 8 . 0 0

    Fig. 1.7 - Output Waveform of Astable Multivibratorthe astable multivibrator produced a square wave (allowing thatour generators produced harm onics that extended beyond the bandwidth of the testing circuitry). If we took som e instrum ent (suchas a wave analyzer or spectrum analyzer) that was capable ofmeasuring the harmonic comp onents of our synthesized wave, w ewould expect to find each of the sine wave components just

    NO TE : Each generator is asine wave signal source. Thefrequencies are odd m ultiplesof the "fundamental" Vl(t)generator and the amplitudesare inversely proportional totheir frequency.

    Fig. 1.8 - Square Wave Synthesizer

    http://localhost/var/www/apps/conversion/tmp/scratch_9/HULTIUIB1.NEThttp://localhost/var/www/apps/conversion/tmp/scratch_9/HULTIUIB1.NET
  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    29/186

    FFT/01 21

    summ ed into that wave shape. But the time domain wave shape ofthe synthesizer is the same as the output of our multivibrator. Ifwe use our wave analyzer on the multivibrator output, we willsurely find the same components that we found in the synthesizedwave, because the two time domain wave shapes are the same.The two are equivalent. A sum mation of sinusoids is the samething as the time domain representation of the signal. That is whatthe examples of Fig. 1.4.x illustrate. A multivibrator may bethought o f as a clever device for simultaneously generating a greatmany sinusoids. The only difference is in our percep tion ourunderstanding.

    i i i i i ' i " i4 - - * - - H - , - - i - ' + f - t - - i - - i -i ; 1 ; ! 1 ; ; !| i ; i ; ij j i ;; T ; + j T t ?

    i ; i i ; i ; i-*- - f - -- - f - - - -*- Hk- - f - f-i ; i ; i ; i | ii | it | i | | i i+- -{- -M -}- +- -H + - f '*i l j l jj % ) J l1 , ' 1 ! ' ; l > ! 'i | i t i : l i ! ittil rftlrrtj - - f - - i _ - 4 _ - j _ _ t - - J _ - ) _ - I _ _ | _ _ j _ - ) _ _ | _ _ ( _ - l _ . - | _ _ j _ _ ) _

    ! i ; i j i ! i ; i i i | i i i- i - - u - i - - i - - t . - ( - - i _ - l _ _ i - - i _ _ i _ - | _ j - _ H - i _ - ) _ _ i _ _ i _i i ' i ' i ' i ' i i i i ; i

    " t""+" ! 1- f - + - -! '- f - + -! i

    1 i"t" + "; i- i - -i- -

    1 i

    Fig. 1.9 - Synthesizer Waveform

    1.08 W HAT IS THE DFT?

    The DFT is a procedure, or process, that can analyze thedata points of a "digitized" time domain function to determine aseries of sinusoids which, when summed together, reproduce thedata po ints of the original function. The resulting Digital Fourierseries is a valid expression of the original function, just as theTaylor series examples given in section 1.01 are valid expressionsof sines, cosines, etc. It is apparent, how ever, that the Digital

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    30/186

    22 Un derstanding the FFT

    Fourier Transform is different from the Taylor series, although theexact nature of the difference may still be less than completelyobv ious. Let's take a mom ent and focus precisely on some of thedifferences: the Taylor series, as illustrated in equations (1.4) and(1.5), evaluate a specific function at a given argument. Th ecoefficients for any specific series are determined once, andthereafter nev er change. Th e Taylor series is used in calculatorsand com puters to evaluate a sin, cosine, exponential, etc., etc. fora given argument, and when we use the Taylor series, only theargument changes. No w the DF T is a process used to determinethe coefficients of a trigonometric series for a given function (i.e.we analyze an arbitrary function to determine the am plitudes (thecoefficients) for a series of sinusoids). In contrast to the Taylorseries, the arguments of a DFT function are fixed and usuallyremain unchanged; when operating in the frequency domain it isgenerally the coefficients of the transformed function that wemodify. Obviously, the Fourie r series and the Taylor series havecompletely different purposes.W hat, then, is the purpose of the D FT ? A great manyprocedures, techniques and theorem s have been developed to w orkwith functions in the frequency dom ain. As it turns out, in thefrequency dom ain we m ay easily perform relatively difficultmathematical techniques like differentiation, integration, orconvolution via simple multiplication and division (in som e casesthis is the only way we can perform these operations). At a higherlevel of problem solving, we can perform m inor miracles. Wemay, of course, examine the frequency spectra of time domainwaveshapes, and taking the next obvious step, perform digitalfiltering. From here it is only a small step to enhance photographicimages bringing blurry pictures into sharp focus, but we maycontinue along this line of development to remove image distortions due to aberrations in the optical system (re: the Hubbletelescope). We can do other things that m ay not be so obvioussuch as speed up the playback of recorded messages withoutchanging pitch, or convert a television format from 50 frames/sec

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    31/186

    FFT/01 23

    to 60 frames/sec without speeding up the action. Working in thefrequency dom ain we can perform still more amazing things thanthese, bu t the best is certainly yet to come as a new generation ofscientists and engineers continue to explore and develop the fieldof Digital Signal Processing (DSP).

    There is a difference between the Taylor and Fourier se riesthat we still may not have m ade apparent. The terms of the Taylorseries are sum med to evaluate the function at a single point (i.e atsome specific argum ent). The transformation and inverse transformation of the DFT, on the other hand, involves all of the valuesof the function within the dom ain of definition. That is, wetransform the whole function. When we speak of a functionproper, we are not talking about the value of the function at anyspecific point, but rather, we are talking of the values of all of itspoints. It is one of the little marvels of the DFT that it cantransform all of the points of a function, as it were, simultaneously,from the tim e domain to the frequency dom ain and then back tothe time domain again via the inverse transform.

    1.09 W HAT IS TH E FFT ?

    What the FFT is, of course, is the question we will spendmost of this book answ ering. For the m om ent though it will beworthwhile to present an analogy which shows clearly what wehope to accom plish. In calculators and com puters the approxim ation of functions such as SIN(X), COS (X), ATN (X), EX P(X ), etc.,etc., may be obtained by the Taylor series (as we explainedpreviously); but, there is a problem in applying these seriesdirectly they are too slow! They take too long to converge to theaccuracy required for most practical work. Use of the Taylorseries would be severely limited had not our friends, the mathem aticians, figured out the following way to m ake it run faster:

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    32/186

    24 Und erstanding the FF T

    We observe, as a practical matter, that all of the differentseries required are of the polynom ial form:

    F(x) = A 0 + A,x + A 2x2 + A 3x3 + A 4x4 + ... (1.10)

    where the A n terms m ust be substituted into the polynom ial for thespecific function being evaluated (see eqns 1.4 and 1.5 for exam ples). The "Horner Schem e" takes advantage of this generalization by solving the polynomial in the following form:

    F(x) = A 0 + x(A, + x(A 2+x(A 3+..+(xA n)..))) - (1.11)

    where we have repeatedly factored x out of the series at eachsucceeding term. Now, at the machine language level of operation, num bers are raised to an integer power by repeated m ultiplication, and an examination of (1.10) and (1.11) above will showthat for an Nth order polynomial this scheme reduces the nu m berof multiplications required from (N 2+N)/2 to N . When one considers that N ranges upwards of 30 (for double precision functions), where the Horner Scheme yields execution times an orderof mag nitude faster, the power of this algorithm becom es apparent.

    Th e above is particularly p rophetic in our case. The DFT,although one of the most powerful weapons in the digital signalprocessing arsenal, suffers from the same malady as the Taylorseries described abovewhen applied to practical problems ittends to bog dow n it takes too long to execute. The FFT, in away that is quite analogous to the Horner Scheme just described,is an algorithm that greatly reduces the number of mathematical

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    33/186

    FFT/01 25

    operations required to perform a DFT. Unfortunately the FFT isnot as easy to explain as the Horner Schem e; although, as we shallsee, it is not as difficult as the literature u sua lly makes it out to beeither.

    1.10 CON CLU SION/ HISTORICAL NO TE

    Throughout this chapter we have repeated the propositionthat physicallyrealizable wav eshapes can always be represented asa summation of sine and cosine wav es. We have also discussedthings such as the nature of "functions", etc., but the sum mation ofsinusoids has obviously been our central theme. This propositionis the foundation of Fourier Analysis. The prim ary purpose of thischapter has been to convey this fundamental idea.The widespread use of Fourier Analysis implies thisproposition is valid; still, when we are presented with a conceptwhose logical foundations are not readily apparent, our naturalcuriosity m akes us wond er how it came about. W ho was the firstto discover it, and how did they figure it out? W hat made som eonesuspect that all functions could be represented as a series ofsinusoids? Early on we saw that the summ ation of sinusoids couldproduce com plex looking waveshapes. A perceptive soul,recognizing this fact, might well move on to investigate how farthis process could be extended, w hat classes of functions could beevaluated by this method, and how the terms of each such seriescould be determined.

    F(x) = A 0 + A,Cos(x) + A 2Cos(2x) + A 3Cos(3x)+...+ B,Sin(x) + B 2Sin(2*x) + B 3Sin(3x)+.. (1.11)

    Daniel Bernoulli, in the 18th century, recognized that

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    34/186

    26 Unders tanding th e F F T

    functions could be approximated by a trigonometric series, andmany mathem aticians worked with the notion afterward, but it wa sJean Baptiste Joseph Fourier, in the 19th century, who demonstrated the pow er of this technique as a practical, problem solvingtool. We might note that this did not bring Fourier imm ediatepraise and fame, but rather, harsh criticism and professionalfrustration. His use of this technique w as strongly opposed by noless a mathem atician than Lagrange (and others). Lagrange wasalready familiar with trigonometric series, of course, but he alsorecognized th e peculiarities of their behavior. Th at trigonom etricseries were universally applicable was not at all obvious at thattime. The point here is that Fourier did not completely understand the too l he used, nor did he invent it. He had no proof th attrigonom etric series could provide universally valid expressions forall functions. The picture we see here is of brilliant men strugglingwith mathematical concepts they cannot quite grasp, and we beginto realize that the question, "Who invented Fourier Analysis?" issomewhat naive. There was no single great flash of insight; therewere only m any good men w orking tirelessly to gain understanding. Today no one question s the application of Fourier Analysisbut, in fact, Lagrange was correct: there are functions that cannotbe transformed by Fo ur ier 's method. Fortunately, these functionsinvolve infinities in ways that never occur in physically realizablesystems, and so, Fourier is also vindicated.

    Books on Fourier Analysis typically have a short historical noteon the role of J.B.J. Fourier in the development of trigonometric series.Apparently there is a need to deal with how a thing of such marveloussubtlety could be comprehended by the human mindhow we coulddiscover such a thing. While the standard reference is J. Herivel, JosephFourier, The Man and the Physicist, Clarendon Press, one o f the bettersummations is given by R.N. Bracewell in chapter 24 of his text TheFourier Transform and its Applications, McGraw Hill. He also shedslight on the matter in the section on Fourier series in chapter 10.

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    35/186

    CHAPTER IIFOURIER SERIES AND TH E DFT

    2.0 INTRODUCTION

    It is assumed that most readers will already be familiarwith the Fourier series, but a short review is nonetheless in orderto re-establish the "m echanics" of the procedure. This material isimportant since it is the foundation for the rest of this book. In thefollowing, considerations discussed in the previous chapter areassumed as given.

    2.1 ME CHA NICS OF THE FOURIER SERIES

    You may skip section 2.1 with no loss of continuity. It isthe only section in this book that employs Calculus. The Fourierseries is a trigonom etric series F(f) by which we m ay approx imatesom e arbitrary function f(t). Specifically, F(f) is the series:

    F(f) = A0 + A,Cos(t)+B,Sin(t) + A2Cos(2t)+B2Sin(2t) +......+ ACos(nt)+ BSin(nt) (2 .1)

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    36/186

    28 Understanding the FFT

    and, in the limit, as n (i.e. the number of terms) approachesinfinity:

    F(f) = f(t) (2.2)

    The problem we face in Fourier A nalysis, of course, is tofind the coefficients of the frequency domain sinusoids (i.e. thevalues of A 0, A^.-.A,,, and B l v . .B n) which make eqn. (2.2) true.

    Finding A0 is easyif we integrate F(f) (i.e. eqn. 2.1)from 0 to 2n, all sinusoid terms yield zero so that only the A0 termis left:

    F(f)dt = A027i (2.3)J o

    From eqn.(2.2) and the following condition:

    ftJ o

    1/2TI f(t) dt = mean value (2.4)

    it follows that:

    1/2712 *f(t) dt = mean value (2.5)

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    37/186

    FFT/02 29

    Next, if we multiply both sides of eqn.(2.1) by cos(t) andintegrate from 0 to 2K , the only non-zero term will be:

    2 *F(f)cos(t) dt r 2 ,A,Cos2(t)dt = 7 t A [ (2.6)

    This results from the fact that:

    2*Cos(rx)Cos(qx) dx = 02%Cos(rx)Sin(px) dx = 0

    Sin(rx)Sin(qx) dx = 0

    (2.7.1)

    (2.7.2)

    (2.7.3)W here: r, q, and p are integers and r + q

    From eqns.(2.2) and (2.6) then we m ay evaluate A ,:

    A , = 1/TI f(t)Co s(t)dtJ o (2.8)From the same argument, if we multiply eqn.(2.1) by

    Sin(t) and integrate from 0 to 2n, the only non-zero term will be:

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    38/186

    30 Understanding the FFT

    B,Sin 2(t)d t = 7tB, (2.9)

    We may therefore evaluate B,:

    B , = 1/TI f(t)Sin(t) dt (2.10)

    If we continue through the other terms of eqn. (2.1) we will findthat the procedure for determining the A and B coefficients may besummarized by the following:

    A = 1/2TI f(t) dt (2.11 A)

    A k = 1/71 f(t)cos(kt) dt (2.11B)

    B k = 1/TI f(t)sin(kt) dtWith: k = 1, 2, 3, , n

    (2.11C)

    n = numb er of terms included in the series.

    As n approaches infinity, we must necessarily include all possiblesinusoidal (by sinusoidal we imply both sine and cosine) components, and F(f) converges to f(t).

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    39/186

    FFT/02 31

    COMMENTARY

    We should take the time to point out a few things about theabove derivation. Our starting equations (2.1) and (2.2) simp lymake the statement that a given arbitrary function f(t) may beconsidered to be a summation of sinusoids as explained in theprevious chapter. It is well known that functions ex ist for w hichthis condition is untrue; fortunately, it is true for all physicallyrealizable systems.

    Equations (2.8) and (2.10) express the mathematicaloperation that is the heart of the Fourier series; the individualsinusoids of a composite wave can be "detected" by multiplyingthrough with unit sinusoids and finding the mean value of theresultant. This process is all that the DFT (and FFT) does.

    The reader should understand that the relationshipsexpressed in equations (2.7.1) through (2.7.3) (i.e. the orthogonality relationships) are imperative to the proper operation of thisalgorithm; furthermore, these equations are true only whenevaluated ov er an integer num ber of cyc les. In practice the Fourierseries, DFT, and FFT force this condition for any time domain T 0by restricting the argum ents of the sinusoids to integer multiples of27rAt/T0 (where N is an integer).

    In addition to these comm ents, the DFT deals with arraysof discrete, digital data. There are no linear, continu ous curves ina computer. We will spend the rest of this chapter delving intohow w e apply the mathematical process described so neatly aboveto the digitized data we process inside a computer.

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    40/186

    32 Und erstanding the FFT

    2.2.0 M ECH ANICS OF THE DFT

    The DFT is an application of Fourier Analysis to discrete(i.e. digital) data. Our ob jective in this chapter is to find out whatmakes the DFT work and why. At considerable risk to personalreputation, we will employ only simple, direct illustrations. Itwould be safer to brandish the standard confusion and abstrusemathematics; but then, there are plenty of books already on themarket to fulfill that requirement. We will start from the conceptscovered in the previous chapter and develop our own process forextracting harmonic components from arbitrary waveforms.

    2.2.1 TH E OB JECTIVE OF THE DFT PRO CESS

    We saw in chapter 1 that sinusoids could be sum medtogether to create common waveforms. Here we consider thereverse of that process. Tha t is, given some arbitrary wav eshape,we try to break it down into its component sinusoids.

    Let's talk about this for a moment. W hen we are presentedwith a composite waveshape, all of the sinusoids are "mixedtogether," sort of like the ingredients of a cakeour question is,"how does one go about separating them ?" We already know, ofcourse, that it is possible to separate them (not the ingredients ofcakesthe components of composite waveforms), but let's forgetfor a m om ent that we know about Fourier Analysis...

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    41/186

    FFT/02 33

    2.2.2 REQU IREMENTS FOR A DFT PROCEDU RE

    There are two, perhaps three, requirements for a methodto "separate out" the com ponents of a composite wave:

    1) First, we require a process that can isolate, or "detect",any single harmonic component w ithin a complex wa veshape.

    2) To be useful quantitatively, it will have to be capable ofmeasuring the am plitude and phase of each harmonic com ponent.These, of course, are the primary requirements for ourprocedure; but, there is another requirement that is implied bythese first tw o:

    3) We must show that, while measuring any harmoniccomponent of a composite wave, our process ignores all of theother harmonic com ponents (i.e. it must not include any part of theother harmonics). In other wo rds, our procedure must measure thecorrect amplitude and phase of the individual harmonics. Verywell then, let's see how w ell the D FT fulfills these requirem ents.

    2.2.3 THE M E C H A N I S M O F THE DFT

    Le t's begin w ith a typical digitized sine wav e as shown inFigure 2.1 below. The X axis represents time; the Y axis represents volts (which, in turn, may represent light intensity, orpressure, or etc.) It has a peak amplitude of 2.0 volts, but itsaverage value is obviously zero. The digitized num bers (i.e. ourfunction) are stored in a nice, neat, "array" within the computer

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    42/186

    34 Un derstanding the FFT

    (see Table 2.1). The interval from the beginning to end of thisarray is the dom ain (see first co lumn Table 2.1).

    1.0

    1.0

    Figure 2.1 - Digitized Sinusoid

    Now, according to Fourier, the way to detect and measurea sine wave com ponent w ithin a complex waveshape is to m ultiplythrough by a unit amplitude sine wave (of the identical frequency),and then find the average value of the resultant. This is thefundamental concept behind Fourier Analysis and consequently wewill review it in detail. First, we create a unit amplitude sine wave(see Fig . 2.2) . To multiply our digitized waveform by a unit sinewave we multiply each point of the given function by the correspond ing po int from the unit sinusoid function (apparently the two

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    43/186

    FFT/02 35

    2.0

    unit sinusoid

    i

    product of sinusoids

    digitized sinusoid (2 volts peak) . . .

    Figure 2.2 - Fourier Mechanism

    functions must have the same num ber of data points, corresponding dom ains, etc.) This process (and the result) is shown in F igure2.2 and Table 2.1 . The reason this works, of course, is that bothsine waves are positive at the same time (yielding positiveproducts), and both are negative at the same time (still yieldingpositive products), so that the products of these tw o functions willhave a positive average value. Since the average value of asinusoid is normally zero, this process has "rectified" o r "detected"the original digitized sine wave of Fig. 2.1. The sum of all of theproducts is 16 (see Table 2.1 below), and since there are 16 datapoints in the array, the average value is 1.0.

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    44/186

    36 Understanding the FFT

    T0.000000.062500.125000.187500.250000.312500.375000.437500.500000.562500.625000.687500.750000.812500.875000.93750

    Sin (X)

    0.000000.382680.707110.923881.000000.923880.707110.382680.00000-0.38268-0.70711-0.92388-1.00000-0.92388-0.70711-0.38268

    * (2*Sin(X))

    0.000000.765371.414211.847762.000001.847761.414210.765370.00000-0.76537-1.41421-1.84776-2.00000-1.84776-1.41421-0.76537

    = 2*Sin2(X)

    0.000000.292891.000001.707112.000001.707111.000000.292890.000000.292891.000001.707112.000001.707111.000000.29289

    Totals = 0.00000 0.00000 16.00000Average Value - 16.0/16 = 1.00000

    Table 2.1

    Note that the average amplitude of the right hand columnis only half of the peak amplitude of the input function (3rdcolumn). We may show that the average value obtained by theabove procedure will always be half of the original input amplitudeas follows:

    The input function is generated from the equation shownon the following page:

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    45/186

    FFT/02 37

    F,(T ) = A sin(27rt) (2.12 )W here: t = TimeA = Peak amplitudeNO TE: A frequency (or period) of unity is implied here

    We simplify by replacing the argument (27rt) with X:F(X) = A Sin(X) (2.13)

    Multiplying through by a sine wave of unit amplitude:F(X )S in(X ) = A Sin(X)Sin(X) (2.14)= ASin 2(X) (2.14A)

    However, from the trigonometric identity:Sin 2(X) = 1/2 - Cos(2X)/2 (2.15 )

    which we substitute into (2.14A):F(X) Sin(X) = A (1/2 - Cos(2X )/2)= A/2 - AC os(2X)/2 - (2.16)

    The second term of (2.16) (i.e. A C os(2X)/2) describes a sinusoidso that its average value will be zero over any number of fullcycles; it follows that the average value of eqn. 2.16 (over anyinteger multiple of 2n radians) will be A/2 (see figure 2.3).This result is more or less obvious from an inspection ofFigs. 2.2 and 2.3. It is apparent that the maxim um value will occurat the peak s of the two sinusoids , where the unit sinusoid has an

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    46/186

    38 Understanding the FFT

    peak am plitude = A average amplitude = A/2

    Figure 2.3 - A Sin 2 Wave

    am plitude of 1.0 and the product of the two functions is A. Theminimum value will occur when the sinusoids are passing throughzero. From the symm etry of F ig. 2.3 it is apparent that the averagevalue must be A/2.This process of detecting or rectifying sinusoids, then, hasthe characteristic of yielding only half the amplitude of the actual

    com ponen t. This presents no major problem though, as we cansimply multiply all of the results by two, or use some othertechnique to correct for this phenomenon.

    2.2.4 THE COSINE COMPONENT

    It is obvious that this scheme will work for any harmoniccomponent; we need only change the frequency of the unit

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    47/186

    FFT/02 39

    amplitude sine wave to match the frequency of the harmoniccom ponent being detected. This same scheme will work for thecosine components if we replace the unit sine function with a unitcosine function.

    The component we want to detect is given by:F2(T) = A COS(27tt) = A CO S(X) - (2.17)W here: All terms are as in (2.12) and (2.13) above.

    Multiplying through by a cosine wave of unit amplitude:

    F(X )CO S(X ) = A COS(X) COS(X) -- (2.18)= A COS2(X) (2.18A)

    From the identity:COS2(X) - 1/2 + Cos(2x)/2 (2.19)

    which we substitute into (2.18A):F(X)CO S(X) = A ( l / 2 + Cos(2X)/2)= A/2 + A Cos(2X)/2 (2.20)

    Again, the second term will have a zero average valuewhile the first term is one half the input am plitude. No te carefullyin the above developm ents that, to produce a workable schem e, wemust design our system such that we always average over fullcycles of the sinusoids.

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    48/186

    40 Un derstanding the FFT

    2.2.5 HA RM ON ICS W ITHIN CO MPO SITE WAVEFORMS

    Next question: "What about the other harmonics incom posite waveforms? The scheme described above undoubtedlywo rks when we are dealing with a single sinusoid, but when we aredealing with a composite of many harmonics, how do we knowthat all of the other harmonics are completely ignored? You willrecall that our third requirement for a method to extract sinusoidalcom ponents from a com posite wave was that the process ignore allbut the sinusoid being analyzed. Technically, this condition isknown as orthogonality.

    2.2.6 ORTHOGONALITY1

    W hat, exactly, does the term orthogonality im ply? Twostraight lines are said to be orthogonal if they intersect at rightang les; two curved lines are orthogonal if their tangents form rightangles at the point of intersection. Con sider this: the "scalerproduct", or "dot product" between two vectors is defined asfollows:

    A B = | A | | B | Cos (0) (2.21)| A | = magnitude of vector A, etc.

    As the angle 0 between the two vectors approaches + 90 degrees,Co s 0 approaches zero, and the dot product approaches zero. It isapparent, then, that a zero dot product between any two finitevectors im plies orthogonality. It is apparent that zero magnitude

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    49/186

    FFT/02 41

    A B = AB Cos 0Projection ofA onto B

    Figure 2.4 - Dot Product

    vectors will always yield a zero dot product regardless of the angle(in fact, the notion of angle begs for definition here). In practicewe effectively define vectors of zero magnitude as orthogonal toall other vectors, and may therefore use a zero resultant fromequation (2.21) as the operative definition for orthogonality.

    DEFINITION 1:If A B = 0 then A and B are orthogonal.

    Note that, by this definition, zero magn itude vectors are orthogonalto all other vectors.The definition of orthogonality between whole functionsderives from an argument not completely dissimilar to the abov e.To illustrate, we will first use equation (2.21) to generate afunction F(

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    50/186

    42 Und erstanding the FFT

    a unit vector lying along the X axis and B is a unit vector in thedirection of (b (where

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    51/186

    FFT/02 43

    Let 's talk about these tw o functions, F(

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    52/186

    44 Understanding the F F T

    F(0) = AB Cos 0

    G(0) = AB Cos 0+K/2

    Fig. 2.5 - Orthogonal Functions F() and G(

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    53/186

    FFT/02 45

    NQ E F ( 0 ) iG ( 0 ) i = 00T T / 8T T / 4

    3 T T / 8T T / 2

    5 T T / 83 i r / 47 T T / 8TT

    8 . 0 0 07 . 3 9 15 . 6 5 73 . 0 6 10 . 0 0 0- 3 . 0 6 1- 5 . 6 5 7- 7 . 3 9 1- 8 . 0 0 0

    Table 2.4 - Orthogonality Test

    So then, this process does indeed detect "orthogonality"between our functions. It is not necessary to prove this relationship for all cases, for at this point we simply adopt this procedureas our operative definition for orthogonality between functions. Ifwe compute products between all of the points of the functions,and the sum mation o f these products is zero, then the functions areorthogonal. New comers som etimes find this remarkable, for bythis definition, we no longer care how the functions were generated. No r do we ask that the functions be traceable to geom etricallyorthogonal origins in any sense. The only requirement is that thesummation of the products of corresponding points between thetwo functions be zero.

    DEFINITION 2:NIf FCctOjGCM = 0 th en F() an d G((|>) ar e o rt h ogo na li=0

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    54/186

    46 Und erstanding the FFT

    Orthogona lity then is a condition which applies directly tothe process we use as the Fourier m echanism. Som e functions willbe orthogonal (i.e. they will always give a zero resultant when w eperform the process described above) and others will not.Obviously the example of section 2.2.3 (i.e. two sine waves ofidentical frequency) does not illustrate orthogonal functions.The question here, however, is whether two sinusoids ofdifferent, integer multiple frequencies represent orthogonalfunctions. Th is, of course, is an imperative cond ition. If they areorthogonal, components that are not being analyzed will con tributezero to the resultantif they are not orthogonal we have BIGproblem s. Le t's see how this works out.As before, w e start with a digitized sine wave but this timewe multiply through with a sine wave of twice the frequency (Fig.2.6 below). By sym metry it is more or less apparent that thisyields an average value of zero. Apparently we have orthogonalfunctions here, but we need a demonstration for the general caseof any integer multiple frequency.1.0 _

    1.0 -

    1.0 -

    1.0 -

    m m

    . . . . . . . . /S in (x ) _ . _ Sin(2x)

    product Sin(x)Sin(2x)

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    55/186

    FFT/02 47

    Starting w ith the identity:

    Sin(A)Sin(B) = Cos(A-B ) - Cos(A+ B) (2.24)2

    if we let A and B represent arguments of:A = 27it and B = NA = 2N7tt

    N = 1,2,3,4,... (i.e. N takes on integer values)

    eqn. (2.24) becomes:

    Sin(A)Sin(NA) = Cos(Ad-NV) - Cos(A(l+NY) (2.25)2It is interesting to note when N = l, the term C o s( A (l- l)) yields avalue of 1 regardless of the value of A (i.e. all values of 27iT), andeqn.(2.25) reduces to:

    Sin(A)Sin(A) = 1 - Cos(2A ) (2.26)2which is the same equation as (2.15) above. The term Cos(2A )generates a sinusoid as A varies from 0 to 2% and must thereforehave a zero average value.If we consider all other positive values of N in eqn.(2.25 )we will always obtain a non-zero value for the argument of bothterms. Consequently, both terms on the right in eqn.(2.25) willgenerate sinusoids, which guarantees an average value of zero forthe function (averaged over any number of full cycles).

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    56/186

    48 Und erstanding the FFT

    The second case we m ust examine is for two cosine wavesof different frequencies. As before we start with an examinationof the trigonometric identity:Cos(A)Cos(B) = Cos(A+B ) + Cos(A-B)2 (2.27)

    When B = NA then (2.27) becom es:= Cos(A(l+NV) - Cos(Ad-N V) - (2.27A)2

    which show s that these functions are also orthogonal except whenN=l and the arguments (i.e. the frequencies) are identical.

    1.0 -

    1.0 -

    1.0 -

    1.0 -

    Cos(x) Cos(3x)

    t * *

    | # # . a

    \product Cos(x)Cos(3x)

    Figure 2.7 - Cos(x)Cos(3x)Finally, we must examine the relationship between thecosine and sine functions for orthogonality. This can be shown by

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    57/186

    FFT/02 49

    the following identity:Sin(A)Cos(B) = SinfA+B) + Sin(A-B) (2.28)

    2and when B = N A:

    = Sin(A(l+NV ) + Sin(A(l-NY) (2.28A )2In this case it makes no difference whether the N = 1 or not; if theargum ent is zero the value of the sine function is likewise zero ; ifthe argum ent is multiplied by an integer the function will trace outan integer number of cycles as A varies from 0 to 2n. In no casewill the average value of these functions be other than zero theyare always orthogonal.

    1.0 -

    1.0 -1.0 -

    1.0 -

    1

    Sin

    . * * '

    (x) Cos(x)

    \ . ' *

    * *

    product Cos(x)Sin(x)

    Figure 2.8 - Cos(x)Sin(x)

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    58/186

    50 Und erstanding the FFT

    2.2.6 TH E DFT/FOURIER M ECHAN ISM

    Finally, we must consider all of this together. We knowthat the com posite waveform is generated by summ ing in harmoniccomponents:

    F(f) = A0 + A,Cos(t)+B,Sin(t) + A2Cos(2t)+B2Sin(2t) + ...+ AnCos(nt)+BnSin(nt) (2.29)

    If we multiply this com posite function by Sin(K t) (or, alternatively, Co s(K t)), where K is an integer, we will create the followingterms on the right hand side of the equation:

    A0Sin(K t)+ A,Sin(t)Sin(K t)+ B,Cos(t)Sin(K t)+...+A^in2(Kt) + BkCos(K t)Sin(K t) + ...+A nSin(nt)Sin(K t)+BnCos(nt)Sin(K t) (2.30)

    Treating each of these terms as individual functions, if theargument (K t) equals the argument of the sinusoid it multiplies,that componen t will be "rectified." Otherw ise, the componen t willnot be rectified. From w hat we have shown above, two sinusoidsof + n/2 phase relationship (i.e. Sine/Cosine), or integer multiplefrequency, represent orthogonal functions. As such, when summ edover all values within the domain of definition, they will all yielda zero resultant (regardless of whether they are handled asindividual terms or com bined into a com posite waveform). That,of course, is precisely w hat we dem anded of a procedure to isolatethe harm onic components of an arbitrary waveform. The examplesof the next chapter will illustrate the practical reality of theserelationships. Since a com puter can do little more than simplearithmetic on the input data, computer examples have a way ofremoving any reasonable question about the validity of theoreticaldevelopments.

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    59/186

    CHAPTER IIITHE DIGITAL FOURIER TRANSFORM ALGO RITHM

    3.0 INTRODUCTION

    The DFT is a simple algorithm . It consists of steppingthrough the digitized data points of the input function, m ultiplyingeach point by sine and cosine functions as you go along, andsum ming the resulting products into accumulators (one for the sinecom ponen t and another for the cosine). When we have processedevery data point in this manner, we divide the accumulators (i.e.the sum-totals of the preceding process) by the number of datapoints. The resulting quantities are the average values for the sineand cosine components at the frequency being investigated as wedescribed in the preceding chapter. We must repeat this processfor all integer mu ltiple frequencies up to the frequency tha t is equalto the sampling rate minus 1 (i.e. twice the Nyquest frequencyminus 1), and the jo b is done.In this chapter we will examine a program that performsthe DFT. We will walk through this first program step by step,describing each operation explicitly.

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    60/186

    52 Understanding the FFT

    3.1 THE DFT COM PUTER PROGRAM

    In the program presented below a "time domain" functionis generated (16 data points) by summing together the first 8harmonic com ponents of the classic "triangle wave." This timedomain data is stored in an array Y(n), and then analyzed asdescribed abov e. In this program we use programm ing and datastructuring features common to all higher level languages, viz. thedata is stored in arrays and the execution of the program takesplace via subrou tines. Each subrou tine works on the data arrays,performing a specific task. This allows the main body of theprogram (i.e. lines 20 through 80) to operate at a high level,executing the necessary tasks (i.e. the subroutines) in a logicalorder. Lets begin by looking at the whole program . As you cansee, everything is controlled between lines 20 and 60.

    6 REM ******************************************8 REM *** (DFT3.1) GENERATE/ANALYZE WAVEFORM ***10 REM ******************************************12 PI=3.141592653589793#:P2=2*PI:K1=PI/8:K2=1/PI14 DIM Y(16),FC(16),FS(16),KC(16),KS(16)16 CLS:F0R J=0 TO 16:FC(J)=0:FS(J)=0:NEXT20 GOSUB 108: REM - PRINT COLUMN HEADINGS30 GOSUB 120: REM - GENERATE FUNCTION Y(X)40 GOSUB 200: REM - PERFORM DFT60 GOSUB 140: REM - PRINT OUT FINAL VALUES70 PRINT:PRINT "MORE (Y/N)? ";72 A$ = INKEY$:IF A$="" THEN 7274 PRINT A$:IF A$ = "Y" THEN 1680 END

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    61/186

    FFT/02

    100 REM ******************************************102 REM * PROGRAM SUBROUTINES *104 REM ******************************************106 REM * PRINT COLUMN HEADINGS *107 REM ******************************************108 PRINT:PRINT110 PRINT "FREQ F(COS) F(SIN) Y(C OS) Y(SIN)"112 PRINT114 RETURN118 REM ******************************120 REM *** GENERATE FUNCTION Y(X) ***121 REM ******************************122 FOR I = 0 TO 15:K3=I*K1124 Y(I) = COS(K3)+COS(3*K3)/(9)+COS(5*K3)/(25)+COS(7*K3)/49126 NEXT128 FOR 1=1 TO 7 STEP 2: KC(I)=1/IA2:NEXT130 RETURN132 REM ******************************138 REM * PRINT OUTPUT *139 REM ******************************140 FOR Z=0 TO 15142 PRINT Z;" ";144 PRINT USING "##.#### #_ ";FC(Z),FS(Z) ,KC(Z) fKS(Z)146 NEXT Z148 RETURN^200 REM **************************202 REM * SOLVE FOR COMPONENTS *204 REM **************************206 FOR J=0 TO 15: REM SOLVE EQNS FOR EACH FREQUENCY208 FOR I = 0 TO 15:REM MULTIPLY AND SUM EACH DATA POINT210 FC(J)=FC(J)+Y(I)*COS(J*I*K1):FS(J)=FS(J)+Y(I)*SIN(J*I*K1)212 NEXT I214 FC(J) =FC( J)/16: FS(J)=FS(J)/16:REM FIND MEAN VALUE216 NEXT J218 RETURN

    Figure 3.1

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    62/186

    54 Understanding the FFT

    N ow let's dissect this program and its routines to see howthings really get done. A t the beginning of the program (line 12)we define the frequently used constants of PI, 2*PI, PI/8, and 1/PI(we will duplicate each section of the program as we go along sothat you do n't have to flip pages). At line 14 we "DIMension" (i.e.define the size) of the arrays to be used in the program . ArrayY(16) will store the 16 data points of the time domain function tobe analyzed, while FC(16) and FS(16) will hold the 16 derivedamplitudes of the Fourier cosine and sine components. Similarly,

    6 Rgfi| ******************************************8 REM *** (DFT3.1) GENERATE/ANALYZE WAVEFORM ***10 REM ******************************************12 PI=3.141592653589793#:P2=2*PI:K1=PI/8:K2=1/PI14 DIM Y(16),FC(16),FS(16),KC(16),KS(16)16 CLS:FOR J=0 TO 16:FC(J)=0:FS(J)=0:NEXT

    K C(16) and K S(16) w ill hold the amplitudes of the sinusoids usedto generate the input function (these are saved for comparison tothe derived com ponents). Having completed this preliminarywork, line 16 clears the screen with a CLS statement, and theninitializes the arrays FC(J) and FS(J) by placing a zero in everylocation. Note that the array proper is the FC() designation andthat J only provides a convenient variable to specify the locationwithin the array. We may use any variable (or constan t) at anytim e to specify locations within arrays. The data stored at thoselocations will be unaffected.This brings us to the main program (lines 20 through 60),which accom plishes the high level objectives. W hen the program

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    63/186

    FFT/03 55

    20 GOSUB 108: REM - PRINT COLUMN HEADINGS30 GOSUB 120: REM - GENERATE FUNCTION Y(X)40 GOSUB 200: REM - PERFORM DFT60 GOSUB 140: REM - PRINT OUT FINAL VALUES70 PRINT:PRINT "MORE (Y/N)? ";72 A$ = INKEY$:IF A$="" THEN 7274 PRINT A$:IF A$ = "Y" THEN 1680 ENDcom es to the GO SU B instruction at line 20 it will "jump dow n" toline 108, and so will we. This subroutine prints the columnhead ings. In addition to printing out the am plitudes of the sine and106 REM * PRINT COLUMN HEADINGS *108 PRINT:PRINT110 PRINT "FREQ F(C OS) F(SIN) Y(COS) Y(SIN)"112 PRINT114 RETURN

    cosine com ponents (as do most Fourier analysis prog ram s), in thisprogram we also print out the amplitude of the components whichwre used to generate the input function [i.e. Y(COS) Y(SIN )].This allows a direct comparison of output to input and tells us howwell the analysis scheme is working . Lines 108 through 112 printthis heading and then, at line 114, we encounter a RETURNstatement which sends program control back to the instruction

    following the line 20 GOSUB 108 statement (i.e program execution jum ps back to line 30).

    Line 30 jum ps us down to the subroutine located at line120, which generates the input function. Line 120 is a REM arkstatement telling us this is where we generate the time domaininput function Y(X ), which we will do by summ ing the harmoniccom ponents know n to construct a "triangle wave." At line 122 weset up a loop that steps "I" from 0 to 15 (the variable /w i l l count

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    64/186

    56 Und erstanding the FFT

    120 REM *** GENERATE FUNCTION Y(X) ***122 FOR I = 0 TO 15:K3=I*K1124 Y(I) = COS(K3)+C0S(3*K3)/(9)+C0S(5*IC3)/(25>+C0S(7*K3)/49126 NEXT128 FOR 1 = 1 TO 7 STEP 2: KC( I)=1/IA2:NEXT130 RETURN

    the 16 data points of our triangle wave function note that K 3 iscom puted each time through the loop (K l is defined back on line12 as PI/8 ). Line 124 is the business end of this routine, it sumsthe odd cosine components (with amplitudes inversely proportionalto the square of their frequencies) into each point of array Y(I).Since there are 16 points in the data array we can have a m aximumof 8 harmon ic components (there must be a minimum of two datapoints for each "cycle" of the Nyquest frequency)1. At line 126the NEXT statement sends us back through the loop again, untilwe have stepped through the 2*PI radians of a full cycle of thefundamental. At line 128 we have inserted a loop which puts 1/N2into the odd cosine terms of the K C(I) array (which is, in fact, theamplitudes of the sine waves we used to generate this function).Having done all this, we have completed the generation of ourinput function, and now RET UR N (line 130) to the main program(i.e. to line 40).4 0 GOSUB 2 0 0 : REM - PERFORM DFT

    We are now ready to perform a Fourier Transform of thetime domain function in array Y(X ). From line 40 we GO SUB to

    1. Note that only 8 harmonics are used to generate this function (in fact that isall the Nyquest Sampling Theorem will allow), but there are 16 frequenciesderived in the DFT. We will discuss this in detail later.

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    65/186

    FFT/03 57

    line 206 where w e set up a loop. This loop will handle everythingthat must be done at each of the harmonic frequencies (in this casethe frequency is designated by J). We must perform a multiplication by cosine and sine at each point of the data array (for thefrequency being worked on) and sum the results into the locationof the FC(J) and FS (J). Line 208 sets up a nested loop which will200 REM **************************202 REM * SOLVE FOR COMPONENTS *204 REM **************************206 FOR J=0 TO 15.-REM SOLVE EQNS FOR EACH FREQUENCY208 FOR I = 0 TO 15:REM MULTIPLY AND SUM EACH DATA POINT210 FC(J)=FC(J)+Y(I)*C0S(J*I*K1):FS(J)=FS(J)+Y(I)*SIN(J*I*K1)212 NEXT I214 FC(J)=FC(J)/16: FS(J)=FS(J)/16:REM FIND MEAN VALUE216 NEXT J218 RETURN

    step I from 0 to 15. Note that, just as J indicates the frequency, Iindicates the data point in the input function array. Line 210 sumsinto FC(J) the product of the data point at Y(I) multiplied by theC O S ( K l *I*J). We are multiplying the Ith data point by the C osineof: K l (i.e. PI/8) multiplied by I (which yields the num ber ofradians along the fundamental that this data point lies) and thenmu ltiplied by the frequency of the component being extracted (i.e.J), which yields the correct number of radians for that particularharm onic. In this same line the "sine term" is also found andsummed into FS(J). At line 212 we encounter the N EX T Istatement, ju m p back to line 208 and repeat this operation for thenext data poin t. When we have stepped through the 16 points ofthe data array, we m ove down to line 214 and divide both of thesesum mations by 16 to obtain the average value. At line 216 weju m p back to line 206 and perform the wh ole routine over for the

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    66/186

    58 Understanding the FFT

    next harmonic. We continue this process until we have analyzedall 16 frequencies (the constant, or "D.C." com ponen t, is occasionally referred to as the "zeroth" frequency).60 GOSUB 140: REM - PRINT OUT FINAL VALUES

    Having completed our Fourier analysis, we then return toline 60 where w e jum p down to the "PRINT OU TPU T" subroutinelocated at line 140. We set up a loop counter Z which counts from0 to 15 (corresponding to the frequencies analyzed) and, in fact, atline 142, we print Z under the column heading "FR EQ ". Let'smake note of a few things that happen here:138 REM * PRINT OUTPUT *140 FOR 2=0 TO 15142 PRINT Z;" ";144 PRINT USING "##.#### #_ ";FC

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    67/186

    FFT/02 59

    70 PRINT:PRINT "MORE (Y/N)? ";72 A$ = INKEYS:IF A$="" THEN 7274 PRINT A$:IF A$ = "Y" THEN 1680 ENDthe input to the variable A $. If no key is pressed, A$ will havenothing in it (i.e. A$ will equal "") and the instruction will berepeated. If A$ has any data in it at all, program execution passesdow n to line 74 where the data is printed and we check to see if A$= "Y". If A$ equals "Y" then the execution ju m ps back to line 16and we begin again; otherwise, execution passes on to line 80which ends the program. For now this routine only provides acontrolled ending of the program, but it will be used moremeaningfully later.

    \2 PROGRAM EXECUTION AND PHENOM ENA

    In the exercises that follow we will test what we havedon e. The value of this section is subtle, but profound; all toooften the student fails to grasp the practical significance andlimitations of the subject he studies. Do you know, for exam ple,if the results of the DFT will be exact or only approximate?Perhaps theoretically exact but masked by "noise" sources (e.g.truncation errors)? The actual results may surprise you. Th efollowing exercises have been selected to be instructive in thepractical usage of the DFT. Our purpose is to gain expe rience ofthe tool we use, as well as confidence in the software we write.Our purpose is to understand the DFT.

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    68/186

    60 Und erstanding the FFT

    3.2.1 PROGRAM EXECUTION

    If we run the program created above we will obtain theresults shown in Fig . 3.2 below. You will note that only cosinecomponents were generated for the input function and, fortunately,only cosine components appear in the analysis; however, all of theresults obtained by the analysis are one half the am plitudes of theinput waveform, within the accuracy of the data printout. You will

    FREQ F(COS) F (S IN ) Y (COS) Y (S IN )

    0123456789101112131415

    0.00000.50000.00000.05560.00000.02000.00000.01020.00000.01020.00000.02000.00000.05560.00000.5000

    0.00000.00000.00000.00000.00000.00000.00000.00000.00000.00000.00000.00000.00000.00000.00000.0000

    0.00001.00000.00000.11110.00000.04000.00000.02040.00000.00000.00000.00000.00000.00000.00000.0000

    0.00000.00000.00000.00000.00000.00000.00000.00000.00000.00000.00000.00000.00000.00000.00000.0000

    Figure 3.2 - Fourier Transform Outputalso note that, while only the first seven harmonics were createdfor the input function, components show up for all 15 frequencies

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    69/186

    FFT702 61

    of the analysis. Note that the components from 9 through 15 area "mirror image" of the com ponents from 1 through 7 (i.e. the tw ohalves of the spectrum are symm etrical about the Nyquest frequency). The frequencies above the Ny quest are negative frequencies,and consequently are com plex conjugates of the frequencies belowthe Nyq uest (as shall be seen shortly).

    3.3 DATA EX ER CISE S

    The "triangle wave" used above is a relatively simplefunction, but it confirms that our DFT is working . We will giveour DFT program a more complicated example shortly, but beforewe do that, let 's consider another simp le test. We will analyze asingle sinusoid which has been shifted in phase by 67.5 from thereference cosine wav e. To do this we change the GENER ATEFUNCTION Y(X) subroutine as follows:

    122 K4=3*PI/8:KC(1)=COS(K4):KS(1)=SIN(K4):REM SET K4=67.5124 FOR I = 0 TO 15:K3=I*K1126 Y(I) = COSCK3+K4)128 NEXT I

    At line 122 we define K 4 (i.e. we set K 4 to 67.5 inradians), and p lace the cosine and sine of this angle into K C( 1) andK S(1), which is the data we will use for com parison to the outpu t.Lines 124 through 128 then generate a full cycle of a cosine wav eshifted by 67.5 . W hen we perform this analysis we find that theDF T yields only sine and cosine components at the fundamental

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    70/186

    62 Und erstanding the FFT

    and its negative. This example simply illustrates that the programcan extract the sine and cosine components of a waveform that hasbeen generated as a single sinusoid.

    In most of the practical applications of the DFT we willdeal with considerably more complicated functions than thosepresented above. A more difficult test for our program would beto create a composite time dom ain wave composed of com pletelyrandom harmonic componentsif the program can analyze thiswave successfully if can handle any thing. To generate this test wetake advantage of the computer's ability to generate pseudorandom numbers and create a random pattern of sine and cosineam plitudes. We save these amplitudes in the arrays K C(I) andK S(I), and then use them to generate the time based function Y(X).This is accomplished by changing the GENERATE FUNCTIONsubroutine as follows:

    122 FOR 1=0 TO 8:KC(I)=RND(1):KS(I)=RND(1):NEXT124 FOR 1=0 TO 15:F0R J=0 TO 8:K4=I*J*K1126 Y(I)=Y(I)+KC(J)*C0S(K4)+KS(J)*SIN(K4)128 NEXT J:NEXT I130 RETURN

    Line 122 generates the random amplitudes of the componentsusing the R N D (l) instruction. Lines 124 through 128 then createthe poin ts of Y(I) by sum ming in the contributions of the sinusoidswh ich have those random am plitudes. For each data point in thetime domain function (indicated by I) we step through the 0through 8th harmonic component contribution (indicated by J).

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    71/186

    FFT/02 63

    Now when we run the program we obtain the followingr e s u l t s :

    FREQ F(COS) F(SIN) Y(COS) Y(SIN)0123456789101112131415

    0.121350.434430.399430.245160.053620.351930.485580.478060.534940.478060.485580.351930.053620.245160.399430.43443

    0.000000.364880.036850.227260.475260.2659316407

    46726000004672616407

    0.265930.475260.227260.036850.36488

    .12135.86886.79885.49031.10724,70387.971160.956125349300000000000000000000000000000000000

    0.651860.729760.073690.454510.950510.531860.320930.934510.56442.00000.00000.00000.00000.00000.00000.00000

    0 .0.0 .0 .0.0 .0 .

    Figure 3.3 - Random Amplitude Function

    We notice several things about this analysis immediately:1. The sine com ponents for the 0th term and 8th term areboth zero, even though they were not zero in the input function.This is because no sine term can exist for either of these components! SIN(N*0) = 0 and SIN(N *PI) = 0. Since we have multiplied through the zeroth term by the frequency of zero, all of thesine terms will be zero in the analysisthey will also be zero inthe input function for the same reason. Likew ise, there can be nosine term for the Nyquest frequency. Even though we assignedvalues to these components in our generation of the wave, theywere never created in the time domain function simply becausesuch components cannot be created.

    2. The cosine amplitude of the zeroth and 8th frequencycomponents are not half of the input function am plitudes. Now ,

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    72/186

    64 Und erstanding the FFT

    we showed in the last chapter that the derived amplitudes would allbe half of the actual component amplitudes, so what is going onhere? The Oth term represents the D.C. com ponent (average value)as explained in chapter 1, and all of the terms are simply multipliedby the cos(0) = 1. This is reasonably apparent and, in fact, waswhat we should have expected; but, it may not have been apparentthat the argument for the cosine term at the Nyquest frequencywould always be 0 or N*PI, always yielding a cosine value of + 1.Any cosine component in the input will be rectified, yielding anaverage value in the analysis equal to the peak value of thatcomponent.3. N ote that the sine components for all of the frequenciesabove the Nyquest are negative. This negation of the sinecomponent comes about because the frequencies above theNyquest are mathematically negative frequencies (as we notedearlier), and a negative frequency produces the complex conjugateof its positive frequency counterpart (i.e. the sine component of acomplex frequency is negated but the cosine component remainsunchanged).If you are already familiar with Fourier Analysis the aboveobservations should come as no surprise; still, it is interesting tosee that practical results agree w ith the theory.

    Let's change the GENERATE FUNCTION subroutine toillustrate one last important point: we will use a linear equation togenerate a "perfect" triangle wav e. We already know that theterms attenuate as 1/N2 in a triangle wave and that only the oddnumbered terms are present we have just analyzed a sevencom po nen t app roxim ation of this function. It wo uld seemreasonable that we obtain similar results with a "straight line"version of this function. In the routine shown below we use a"scale factor" of PI2/8 to provide the same amplitudes as thecom ponents used in our syn thesized version (i.e. the fundamentalhas an amplitude of 1.0 and the harmonics all "roll off" as 1/N2).The final GENERATE FUN CTIO N subroutine will be:

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    73/186

    FFT/03 65

    122 K2=(PI*PI)/8:K3=K2/4124 FOR 1=0 TO 7:Y(I)=K2-K3*I:NEXT I126 FOR 1=8 TO 15:Y(I)=K3*I-3*K2:NEXT I128 RETURNWe run the program and obtain the results shown in Fig .3.4. First of all we notice that there are no harm onic am plitudesgiven for the input function; there shouldn't be any, of course,because we did n't generate the function that way. Of considerably

    FREQ012345678910H2131415

    F(COS)0.000000.506480.000000.062450.000000.027880.000000.020040.000000.020040.000000.027880.000000.062450.000000.50648

    F(SIN)0.00000.00000.00000.00000.00000.00000.00000.00000.00000.00000.00000.00000.00000.00000.00000.0000

    Y(COS)0.00000.00000.00000.00000.00000.00000.00000.00000.00000.00000.00000.00000.00000.00000.00000.0000

    Y(SIN)0.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.00000

    Figure 3.4 - Analysis of a "Perfect" Triangle Wavemore importance is the fact that the components don't match theamplitudes that we said they would (compare them to the valuesderived back in Figure 3.2). Not only do they not have the correctvalues, they d on 't even have the correct 1/N2 ratios! This is completely wrong ! Is something wrong with our program?

    Even though it is customary to throw up the hands whenresults such as these are obtained (not a completely infrequentoccurrence), and proclaim the DFT useless for "real work," it willactually be best if we can remain calm for a few minutes and

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    74/186

    66 Understanding the FF T

    exam ine what has happened here. First of all, there is nothingwrong with the computer program. The program is telling usexactly what it should be telling us. There is nothing wrong withthe equations we used to generate the function and there is nothingwrong w ith the DFT w e are using. The thing that is "wrong" isthat we have jus t experienced the effects of aliasing] We generated the above triangle wave deliberately so that it would include thehigher order harmonic components (even though we know themaximum Nyquest frequency is "8" for a data base of only 16 datapoints. All of the harmonics above that frequency have been"folded back" into the spectrum we are ana lyzing and have givenus "incorrect" va lues . If we want to generate a function as we didin this example, and have it agree with the known harmonicanalysis of the "classic" waveshape, we must filter off the harmonics above the nyquest before we attempt to digitize it.The mechanics of the aliasing phenomenon are veryinteresting to delve into, but our concern here is with the FFT, andso we w ill resist the urge to dig deeper. We have gone throughthis exercise because it is the sort of thing that happens in thepractical application of DF T/FF T routines. Systems are improperly designed (or improperly applied) and then, later, no one canunderstand why the results are invalid. The DFT algorithm isindeed a simple program, but there are a great many "traps" lurkingfor the unwary. W hile it is relatively easy to explain how the F FTworks and how to write FFT programs, there is no alternative tostudying the DFT, and FFT, and all of the associated engineeringdiscip lines, in deta il. Like Geom etry (and, for that matter, mostother things of value) for this subject "There is no royal road ..."

  • 7/27/2019 Anders E. Zonst-Understanding the FFT-Citrus Press (1997)

    75/186

    CHAPTER IVTHE INVERSE TRAN SFORMAND CO MPLE X VARIABLES

    4.1 RECONSTRU