Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Fourier series

  1. May 18, 2005 #1


    User Avatar

    I've been trying pretty consistently to work out the fourier series for a number of functions, but continually fail to find the correct series. My book is terrible in that it only has one poorly explained example of how to do a fourier series. I was wondering if anyone has any links to worked problems involving them, that would be much appreciated.
  2. jcsd
  3. May 18, 2005 #2
    I dont have any links, but I can offer some advice...

    Any periodic integrable function can be approximated by a sum of sine and cosine function. This is Fourier's theorem. Formally,

    [tex]f(x) = a_0 + \sum_{n=1}^{\infty}\left(a_n\cos(nx) + b_n\sin(nx)\right)[/tex]

    The purpose of many Fourier decomposition problems is to write a given function [itex]f(x)[/itex] into this form. This almost always requires us to calculate [itex]a_0,\,a_n,\,b_n[/itex]. I say almost always because sometimes the function may be even or odd.

    Well, these Fourier coefficients are easy to calculate, because there are formula's for them - namely the Euler Formulas:

    [tex]a_0 = \frac{1}{2\pi}\int_{-\pi}^{\pi}f(x)dx[/tex]

    [tex]a_n = \frac{1}{\pi}\int_{-\pi}^{\pi}f(x)\cos(nx)dx[/tex]

    [tex]b_n = \frac{1}{\pi}\int_{-\pi}^{\pi}f(x)\sin(nx)dx[/tex]

    Note that if [itex]f(x)[/itex] is a polynomial of degree greater than 1, or any trigonometric or exponential function, then calculating these coefficients is probably going to require integration by parts. If you're lucky enough to have Maple or some computer mathematics package, this can be simple.

    Once you have determined each of these coefficients it is just a simple matter of substituting them into Fourier's equation.
  4. May 18, 2005 #3
    Functions that you will be asked to find the Fourier series for are going to be periodic. The more simpler functions will be periodic with a period of [itex]2\pi[/itex], whereas the slightly more complicated functions will have a period of [itex]2L[/itex].

    So after you are given your function [itex]f(x)[/itex] you first must recognise its period. If it is [itex]2\pi[/itex] then your function has a fundamental period and we just use the Euler Formulae above. For now this is what we will consider...

    After you have determined your function to be periodic over the interval [itex]\[-\pi,\pi\][/itex], the next thing you must do is determine if it is even or odd.

    If you have a periodic function that isnt even or odd at [itex]x=0[/itex] but at some other point [itex]x = y[/itex], you can adjust the axes so that the function becomes symmetric at [itex]x=0[/itex]. This pretty much means you can centre your function at 0 and your integration becomes simpler.

    Generally this requires one or both of two things:
    1. You know what the graph of the function looks like, and you can make an educated guess at whether or not the function is even or odd.
    2. You are able to calculate it using the fact that a function is even if
    [tex]g(-x) = g(x)[/tex]
    or odd if
    [tex]g(-x) = -g(x)[/tex]
    Last edited: May 18, 2005
  5. May 18, 2005 #4
    In applications, periodic functions will almost never have a period of [itex]2\pi[/itex]. However, if you think about it, it is possible to expand or contract the scale of the axes upon which your function is defined, such that the period becomes [itex]2\pi[/itex].

    If your function has an arbitrary period [itex]2L[/itex], then we must adjust the Euler formulae accordingly.

    [tex]a_0 = \frac{1}{2L}\int_{-L}^{L}f(x)dx[/tex]

    [tex]a_n = \frac{1}{L}\int_{-L}^{L}f(x)\cos\frac{n\pi x}{L}dx[/tex]

    [tex]b_n = \frac{1}{L}\int_{-L}^{L}f(x)\sin\frac{n\pi x}{L}dx[/tex]

    Further, the Fourier Series becomes

    [tex]f(x) = a_0 + \sum_{n=1}^{\infty}\left(a_n\cos\frac{n\pi x}{L} + b_n \sin\frac{n\pi x}{L}\right)[/tex]

    Next I will work through a problem
  6. May 18, 2005 #5
    Consider the well-known rectangle function.

    [tex]f(x) = \left\{\begin{array}{cc}
    -k & -\pi < x < 0 \\
    k & 0 < x < \pi

    The first question to ask yourself is: what is the period of this function?

    What is the length of this function before it repeats itself? Quite simply, the period is [itex]2\pi[/itex]. Draw it on some paper, and notice that it repeats the same pattern every [itex]2\pi[/itex]. So since this function has the fundamental period, we use the corresponding Euler formulae and Fourier Series.

    The second question to ask yourself is: is this function even or odd?

    Luckily, this is one of those functions which you can picture in your head, or write down on a piece of paper. It is odd, since it is NOT symmetric about 0.
    When a function is odd, the first Fourier coefficient is always 0, no matter how much dont want it to be. To see this, we compute

    [tex]a_n = \frac{1}{\pi}\int_{-\pi}^{\pi}f(x)\cos(nx)dx[/tex]

    [tex]= \frac{1}{\pi}\left[\int_{-\pi}^{0}(-k)\cos(nx)dx + \int_{0}^{\pi}k\cos(nx)dx\right][/tex]

    Notice how I have split the integral into two integrals. The rest of the computation is simple calculus, and

    [tex]a_n = 0[/tex]

    Why does an odd function always have [itex]a_n = 0[/itex]? Remember, that the Fourier Series of a function is just an approximation of that function as a sum of sines and cosines. The sine function is by definition odd, and the cosine function is by definition even.

    The Forier coefficient that accompany the sine and cosine term in the Fourier Sum are like weighted parameters. The larger the [itex]a_n[/itex] the more the function will be "like" a cosine and hence even. The larger the [itex]b_n[/itex] the more the function will be "like" a sine and hence odd.

    So the Fourier coefficients [itex]a_n[/itex] and [itex]b_n[/itex] influence how the Fourier Sum will act.

    In our example, the rectangle function is odd. So we are going to expect that the Fourier Series will be a sine wave. In fact we will see that the more sine terms we allow into our Fourier Series, the more and more the Fourier Series will look like our function. This will become clear in a minute...

    So it is of no surprise that [itex]a_n = 0[/itex] because it is [itex]a_n[/itex] that accompanies the cosine term.

    This leaves us to calculate [itex]a_0[/itex]. This coefficient is special in that it always defined as the average value of the function. This coefficient tells us where the function is located.

    So for our rectangle function, what do you think its average value is? Zero of course. So we guess that [itex]a_0 = 0[/itex]. Lets see if we are right?

    [tex]a_0 = \frac{1}{2\pi}\left[\int_{-\pi}^0-kdx + \int_0^{\pi}kdx\right][/tex]

    [tex]a_0 = \frac{1}{2\pi}\left[\left.-kx\right|_{-\pi}^0 + \left.kx\right|_0^{\pi}\right][/tex]

    [tex]a_0 = \frac{1}{2\pi}\left(k\pi -k\pi\right)[/tex]

    [tex]a_0 = 0[/tex]

    Of course the same technique applies to all functions.


    [tex]b_n = \frac{1}{\pi}\int_{-\pi}^{\pi}f(x)\sin(nx)dx[/tex]

    [tex]b_n = \frac{1}{\pi}\left[\int_{-\pi}^{0}(-k)\sin(nx)dx + \int_{0}^{\pi}k\sin(nx)dx\right][/tex]

    [tex]b_n = \frac{1}{\pi}\left[\left.k\frac{\cos(nx)}{n}\right|_{-\pi}^0 - \left.k\frac{\cos(nx)}{n}\right|_0^{\pi}\right][/tex]

    [tex]b_n = \frac{k}{n\pi}\left[\cos0 - \cos(-n\pi) - \cos(n\pi) + \cos0\right][/tex]

    [tex]b_n = \frac{2k}{n\pi}(1-\cos(n\pi))[/tex]

    Now, something which you must always do when you get to this stage in your calculations, something that a lot of people forget. Simply note that the sum of Fourier Series take on values of [itex]n \in \mathbb{N}[/itex]. That is

    [tex]n = 1,2,\dots[/tex]

    And we must note that

    [tex]\cos(n\pi) = (-1)^n \, \forall \, n \in \mathbb{N}[/tex]

    This is just a fancy way of writing...

    [tex]\cos(n\pi) = \left\{\begin{array}{cc}
    1 & \mbox{for even}\, n \\
    -1 & \mbox{for odd}\, n

    and thus

    [tex]1-\cos(n\pi) = \left\{\begin{array}{cc}
    2 & \mbox{for odd}\, n \\
    0 & \mbox{for even}\, n

    Now we can explicitly calculate our [itex]b_n[/itex] coeffcients

    [tex]b_1 = \frac{4k}{\pi}[/tex]
    [tex]b_2 = 0[/tex]
    [tex]b_3 = \frac{4k}{3\pi}[/tex]
    [tex]b_4 = 0[/tex]

    Obviously for every even n, [itex]b_n = 0[/itex].

    Hence the Fourier Series is

    [tex] f(x) = \frac{2k}{\pi}\sum_{n=1}^{\infty}b_n\sin(nx)[/tex]

    [tex] f(x) = \frac{2k}{\pi}\left(\sin(x) + \frac{1}{3}\sin(3x) + \frac{1}{5}\sin(5x) + \dots \right)[/tex]
    Last edited: May 18, 2005
  7. May 18, 2005 #6


    User Avatar
    Science Advisor
    Homework Helper
    Gold Member

    Nice oxymoron, but is this true?

    Look at the attachement for example.

    Attached Files:

  8. May 18, 2005 #7
    No, it isn't.

    Ahh, I know what I meant to say... let me re-word this...

    If you have a periodic function that isnt even or odd at [itex]x=0[/itex] but at some other point [itex]x = y[/itex], you can adjust the axes so that the function becomes symmetric at [itex]x=0[/itex]. This pretty much means you can centre your function at 0 and your integration becomes simpler.

    I guess what I said doesnt make much sense at all. Sorry about that.
    Last edited: May 18, 2005
  9. May 18, 2005 #8
    By the way quasar987, I have changed what I said above.
  10. May 19, 2005 #9


    User Avatar

    Wow, thank you for the help Oxy, my book's only example was the series for the the rectangle function, but your method of solving it was much more illuminating. Thanks again for the help.
  11. Jul 17, 2010 #10
    Hi ....I have a doubt realted to this...Say I have f(x)=xsinx...this is an even function...so I should get values for only a0 and an....however,in my book there are 2 sums based on xsinx...one in which we find its fourier series in the interval (0,2pi) and another in which its fourier cosine series in (0.pi) is to be found. In the solution provided,they get a certain value for b1 for the first sum whereas they don't get any b-terms for the second one.
    My question is,why do we get a b1 term at all for the first situation,as the function is even and is not supposed to have b terms. Further,why do we get a different answer for the two sums?
  12. Jul 21, 2010 #11
  13. Jul 25, 2010 #12

    This is an excellent site for what you're looking for....just scroll down to "Higher Calculus" and you should see "Fourier Series."
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook