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

Fourier series in matlab

  1. Feb 5, 2006 #1
    hey guys, Ive gotta do some fourier series work using matlab, but I have no idea what to do.

    Ive found the coefficients by hand, but now I need to use matlab to evaluate and tabulate the first 8 terms.

    I then have to evaluate the series at 1000 points over a certain range.

    Does someone know how to go about this?
  2. jcsd
  3. Feb 7, 2006 #2
    Discretize your function over the range to more than 4000 points (say) and store it in a vector.
    Then use ifft(vector). You'll get the coefficients (if you want 1000, get the first 1000).

    Suppose you have a cosine transform.


    ifft will give you these coefficients f0, f1, f2...

    If you want to reconstruct the function by yourself in matlab, you'll have to code a for loop.

    start with f=f0.

    then a variable for from 2:(the number of components you want)
    add to f

    I hope this is clear. You should do the same thing with the 8 modes you calculated by hand.
  4. Feb 7, 2006 #3
    Thanks anaemic.
  5. May 9, 2008 #4
    If I don't discretize my function, then, I have to find the coefficient by numerical integration.


    where my f depends on n (the index of coefficient). And Matlab just says something like "dimension mismatch". Do you guys know how to deal with it?

    I can actually do it like this:

    for n=-N:N
    fexp=@(x) (x+2).*exp(i*pi*n*x);

    but I don't like to do it like this because this method seems to take a lot of computer time.
    Last edited: May 9, 2008
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook