There are all sorts of resonances around us, in the world, in our culture, and in our technology. A tidal resonance causes the 55 foot tides in the Bay of Fundy. Mechanical and acoustical resonances and their control are at the center of practically every musical instrument that ever existed. Even our voices and speech are based on controlling the resonances in our throat and mouth. Technology is also a heavy user of resonance. All clocks, radios, televisions, and gps navigating systems use electronic resonators at their very core. Doctors use magnetic resonance imaging or MRI to sense the resonances in atomic nuclei to map the insides of their patients. In spite of the great diversity of resonators, they all share many common properties. In this blog, we will delve into their various aspects. It is hoped that this will serve both the students and professionals who would like to understand more about resonators. I hope all will enjoy the animations.

For a list of all topics discussed, scroll down to the very bottom of the blog, or click here.

Origins of Newton's laws of motion

Non-mathematical introduction to relativity

Three types of waves: traveling waves, standing waves and rotating waves new

History of mechanical clocks with animations
Understanding a mechanical clock with animations
includes pendulum, balance wheel, and quartz clocks

Water waves, Fourier analysis



Saturday, March 28, 2009

How good is a Fourier series of a function at reproducing the original function?

Summary of the last postings

We so far have discussed the terms of a Fourier series. Here is a summary:

1. A Fourier series is a method of replacing a repeating function f(θ)  with a series of sinusoidal functions:
2. The equations for calculating the coefficients of the various terms are:
3. An alternate equation for the Fourier series using only cosines and phase shifts is:
4. The equations for calculating these coefficients using the previous set of coefficients are:

Interactive table showing the fit of Fourier series for various functions. Click on the various function buttons at the top to see the process of fitting a Fourier series term-by-term to that function.
copy interactive table fair use policy

The question of fit

How good are these equations at actually reproducing the original function? The interactive table to the right shows the fit of partial Fourier series to the original function for a variety of functions. The viewer can choose from various repeating functions and see the fit and the error in using increasing number of terms of a Fourier series.

Detailed explanation of the interactive table

  1. In the first block (which we shall call block 0), the user selects a particular function by clicking on it. "Square wave" is initially selected and is a good function to start with, because we have already examined its Fourier series in detail in the last two postings.
  2. In the next block, "1. Function to be fit", we see a graph of the function that was selected.
  3. In block 2,  "2. Fourier series of this function" we see the Fourier series of the selected function written out, term by term. Note that we do not include those terms that have zero coefficients (zero amplitudes). The last term shown is a general equation for the nth term.
  4. In the next block, "3. Fourier series of one term", we show a graph of a partial Fourier series consisting of only one term, the first term shown in block 2. This graph is shown in blue. For most functions, the first terms is a constant and the graph is that of a constant, i.e. a horizontal line. We also have included the original function (in red) from block 1. In the cases where the first term is a constant, you can see that the constant is indeed the average value of the original function as mentioned in the previous posting.
  5. In block 3a, we include a brief discussion of the fitting of the particular function selected. This is directed towards all the other blocks, but primarily towards block 2 and the last block, block 9. There is additional discussion of the functions and their Fourier series in the section of text below titled, "Detailed discussion of the Fourier series fit to the functions in the interactive table".
  6. In block 4, the red line represents the original function (from block 1.) with the first term subtracted off. In other words, the red graph represents the part of the function that needs to be fit by the Fourier series terms beyond the first one. It is the remaining "error" in our "one term Fourier series" of block 3. Also shown, in blue, is the term to be added next to the Fourier series to further fit the remaining error (the second term from block 2). Note how nicely this sinusoid fits the remaining error. It is what most people would draw in on top of the red error function, if asked to draw the best sinusoid to fit the error. Most people find it easy to make a fairly accurate guess at this first term.

    The blue sinusoid, as shown, is the next term, the "fundamental, i.e. n = 1" of the Fourier series as calculated by the equations in the first table in this posting. It turns out that this sinusoid is the least squares best fit to the red remaining error.

  7. Adding the higher order terms, shown in the succeeding graphs, repeat this: that the next term is what you might guess given a graph of the error remaining.  
  8. In block 5, we show the partial Fourier series consisting of two terms in blue along with the original function to allow the reader to compare the two. In most cases this Fourier series is simply a y-shifted sinusoid of the fundamental frequency.
  9. Blocks 6 and 7 repeat blocks 4 and 5, only with one more term. The remaining error in 6 (in red) is less than it is in 4 and the fit of the partial Fourier series (in blue) in 7 is a better fit to the original function (in red) than it was in block 5.
  10. Blocks 8 and 9 repeat blocks 4 through 7 with still another term in the Fourier series. The error is less and the fit better still. We stop here. However we could keep going to get whatever accuracy of fit we desire, with one exception. That exception is that the Gibbs phenomenon prevents a good fit to the abrupt changes or discontinuities.

Naming convention for the terms in a Fourier series

Generally the first sinusoidal term, the n = 1 term, is call the fundamental. The n = 2 term which is a sinusoid of twice the frequency of the fundamental is usually called the second harmonic or first overtone. The n = 3 term is the third harmonic or second overtone. The term overtone actually can refer to any frequency component which is present in a signal (other than the fundamental) and may not be at a frequency equal to an integral multiple of the fundamental. On the other hand, repeating functions with repetition frequencies equal to the fundamental frequency will only have harmonic overtones. If a signal contains a non-harmonic overtone, the signal will not be repeating at the fundamental's frequency and must be decomposed with a Fourier integral (as opposed to a Fourier series) or with a Fourier series using a lower fundamental frequency (that matches the repetition frequency of the signal.) The n = 1 term or fundamental is also the first harmonic, but is usually referred to as the fundamental.

In Fourier series, we can have a lacking fundamental if the n = 1 term is missing (has a zero coefficient). An example of this would be the case where only the n = 2 and 3 terms are present, or in the case where only the n = 3, 5, 7,... terms are present.   Examples of the latter are shown in red in block 6 in the table for the square wave, and triangle wave. Block 6 of the saw tooth and pulse train are examples of functions with a missing fundamental but containing the n = 2, 3, 4, .... terms. While the red graph in block 6 is labeled as the remaining error, it is also equal to the original functions with the constant value and fundamental stripped out. Note that if we strip out the constant and fundamental from the half wave function, we are left with only terms of even n's which means the function will repeat itself every half cycle (look at block 6 for this function) and we should redefine our fundamental to be twice our original fundamental frequency.


Detailed discussion of the Fourier series fit to the functions in the interactive table

By examining the interactive table and reading the discussion panel, block 3a, for the various functions,  we can observe the following:
  1. For most functions, the fit between the original function and a Fourier series of just a few terms is surprisingly good.
  2. The fit is best for smooth repeating functions having no abrupt transitions, i.e. discontinuities. The square wave, pulse train, and sawtooth all have discontinuities and are plagued by the Gibbs phenomenon. Gibbs showed that a Fourier series used for a square wave always overshoots by the same amount around the abrupt transition, no matter how many terms in the Fourier series are used. On the other hand, including more terms does reduce the width (and appearance) of the overshoot. Sinusoids are not the best for breaking down functions with abrupt transitions, but can do a reasonably good job of fitting these for many less demanding applications.
  3. The fit is extremely good for the function made of half circles that resembles a sine function.
  4. The fit, using only one term, is perfect for a sine function. This is obvious in hindsight, that you can fit a sine function perfectly with a single sine function.
  5. The coefficients of the last function, that is made up of half circle segments, were derived with the above equations using numerical integration. We did this because the analytic, i.e. symbolic integration (what we did for other functions in the last two postings), proved to be quite tedious. Many calculators and computer programs can do numerical integration and provide numerical answers.
  6. The pulse train is the hardest function of our set to fit and the fit is the poorest of the lot. The integral for the coefficients results in a sinx/x function, also known as a sinc function, which sees considerable use in wave related technology.  The variable τ in the equation in block 2 stands for the pulse width in radians.
  7. The "half wave" and "full wave" functions are the waveforms that one gets when looking at two types of electrical rectifiers: half-wave rectifiers and full-wave rectifiers. It is fairly easy to show that the full wave function equals two times the half wave function minus the fundamental. Thus it is not surprising that the Fourier series of the two are very similar. It turns out that subtracting off the fundamental totally eliminates the fundamental in the full wave function leaving it with only terms for even n's. An alternate point of view is that the full wave function as shown in the table really has a period of 0 to π (repeats itself every π radians) and should be recast (stretched) so its period is 0 to 2π to make it consistent with the other functions shown. If we did the stretching, then the n of all the terms would become n/2 so that the n = 4 term would become the new n = 2 term with the same amplitude and we would have all possible terms present in the Fourier series.
  8. Generally, functions with abrupt changes or discontinuities contain larger higher harmonics. We see that most of the smoother functions have harmonics that fall off as 1/n2 (look at the last term in block 2 in the interactive table for various functions). The functions with discontinuities such as the square wave or sawtooth fall off as 1/n, i.e. more slowly. As an example, consider the n = 5 harmonic. For this, 1/n2 = 1/25 = 0.04 = 4%, whereas 1/n = 1/5 = 0.20 = 20%. Thus the 5th term in a 1/n2 function has 4% the amplitude of its fundamental, while the 5th term in a 1/n function has 20% the amplitude of its fundamental.

    Another way to view this is that an abrupt change in a function requires rapidly changing sinusoids to properly fit the function. Since higher harmonics are more rapidly changing for the same amplitude, they are required. However, even with use of higher harmonics, the Gibbs phenomenon demonstrates that these abruptly changing functions are never completely fit by a Fourier series. Note that the Fourier series of a pulse train involves the sinc function, which falls off as 1/n.

    Yet another way to see the connections between abrupt changes in a function and the higher harmonic content is to examine the graphs on the right side of the interactive table above. Note that in block 5, the Fourier series fails to reproduce all the corners and transitions of the original function. When we add another higher harmonic, as in block 7, the Fourier series fits these corners and transitions better. With yet still another higher harmonic added, as in block 9, the corners and transitions are fit still better. Each additional higher harmonic fits into the corners and crevices a little better. In general, it is the job of the higher harmonics to fit the fine details of the function, whereas the first few term fit the general overall shape of the function.

  9. We discussed making the independent variable of these functions involve distance or time in an earlier posting under the sub-heading of "functions of distance or time". In this posting we use θ as a generic independent variable, which can be replaced by ωt, κx, κx ±ωt, etc. as appropriate to model real physical oscillations or waves in which the independent variable is distance, time, or both.

Summary

  • The mathematical formulas given above for Fourier series coefficients produce a very good fit to a given repeating function if it does not have discontinuities.
  • This fit is very good even if a small number of terms in the Fourier series is used. Increasing the number of terms increases the accuracy of the fit.
  • Functions that are unlike sinusoids, especially those having with abrupt changes, require more terms in the Fourier series for the same accuracy of fit.
  • Functions with discontinuities suffer from the Gibbs phenomenon, an overshoot of the Fourier series expression that persists even when a very large number of terms is used in the series.
  • The constant term and first sinusoidal terms can be accurately guessed at by inspection. This can be a good check for the computation of the terms using the formulas.

Copyright P. Ceperley 2009

LAST POSTING: Sines, cosines, and phases
NEXT POSTING: Symmetries in Fourier series