Results 1 to 4 of 4

Math Help - Matlab: Plotting Fourier-Series

  1. #1
    Newbie cith's Avatar
    Joined
    May 2009
    Posts
    7

    Question Matlab: Plotting Fourier-Series

    I'm doing some fourier transforms and I'm wondering how to plot this in Matlab to look at the graphs. I don't know how to plot the function, nor the series.

    f(x)=\Big\{_{ 1, \hspace{0.5cm} 0 \leq x < \pi}^{-1, \hspace{0.3cm} -\pi \leq x < 0}; f(x+2\pi)=f(x), for all x.

    which has the fourier series (if calculated correctly):

    b_n=\frac{2}{n\pi}[1-(-1)^n]\to\frac{4}{\pi}\sum_{m=1}^{\infty}\frac{sin((2m-1)x)}{2m-1}

    I'd like to do a comparison of the Fourier-series and the original function by looking at the graphs. Also, how do you find the Fourier-series and their coefficients, from a function like the one I posted? It'd be great to use Matlab for that.

    Any help would be appreciated
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by cith View Post
    I'm doing some fourier transforms and I'm wondering how to plot this in Matlab to look at the graphs. I don't know how to plot the function, nor the series.

    f(x)=\Big\{_{ 1, \hspace{0.5cm} 0 \leq x < \pi}^{-1, \hspace{0.3cm} -\pi \leq x < 0}; f(x+2\pi)=f(x), for all x.

    which has the fourier series (if calculated correctly):

    b_n=\frac{2}{n\pi}[1-(-1)^n]\to\frac{4}{\pi}\sum_{m=1}^{\infty}\frac{sin((2m-1)x)}{2m-1}
    x=0: pi/1000 :2*pi;

    f=-1+(x>=0)*(2);

    plot(x,f);


    CB
    Last edited by CaptainBlack; May 17th 2009 at 02:43 PM.
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie cith's Avatar
    Joined
    May 2009
    Posts
    7
    \sum_{m=1}^{\infty}\frac{sin((2m-1)x)}{2m-1}
    Is there a way to plot this too?

    Thanks
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by cith View Post
    \sum_{m=1}^{\infty}\frac{sin((2m-1)x)}{2m-1}
    Is there a way to plot this too?

    Thanks
    By that I assume you mean the partial sums, then yes:

    Code:
    x=0:pi/100:2*pi
    n=1:5;
     
    [N,X]=meshgrid(n,x);
     
    S=sin((2*N-1).*X)./(2*N-1);
     
    SS=sum(S');
     
    plot(x,SS);
    and if you want this on the same plot as the other use "hold on" before the second plot (and "hold off" after the second).

    CB
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Replies: 2
    Last Post: January 3rd 2012, 10:53 AM
  2. plotting a graph in matlab
    Posted in the Math Software Forum
    Replies: 3
    Last Post: March 21st 2009, 02:11 PM
  3. MATLAB Plotting Fourier series coefficients
    Posted in the Math Software Forum
    Replies: 1
    Last Post: January 25th 2009, 12:29 PM
  4. MATLAB: Plotting MATRIX?
    Posted in the Math Software Forum
    Replies: 3
    Last Post: January 25th 2009, 12:21 PM
  5. Plotting fourier series approximation of F(t)
    Posted in the Calculus Forum
    Replies: 2
    Last Post: October 30th 2008, 02:56 PM

Search Tags


/mathhelpforum @mathhelpforum