Matlab - Fourier transform doesn't look as expected

Discussion in 'Programmer's Corner' started by lll, Aug 15, 2012.

  1. lll

    Thread Starter New Member

    Mar 7, 2012
    21
    1
    x=-5:.001:5;
    y = ( (-0.5 <= x) .* (x < 0.5 ) ); %the rect function
    plot(x,fft(y)) %looks nothing like sinc function


    Why doesn't the graph look like the sinc function?
     
  2. MrChips

    Moderator

    Oct 2, 2009
    12,440
    3,360
    You have a number of problems.

    Firstly, the result of the fft is complex. You need to find the magnitude of each complex pair or you can use the abs( ) function but this doesn't give you the sign.

    Secondly, the fft will produce positive frequencies followed by negative frequencies.
    In order to rearrange the array to look the way you see it in the text books you use the fftshift( ) function.

    Thirdly, you have way too many points so the sinc function will be very narrow.
    Try using

    x = -5:.1:5;

    for 101 points
     
    Last edited: Aug 15, 2012
    lll likes this.
  3. lll

    Thread Starter New Member

    Mar 7, 2012
    21
    1
    Thanks, I got it working now.
     
  4. MrChips

    Moderator

    Oct 2, 2009
    12,440
    3,360
    For the benefit of all concerned please state what you did to get it working.
     
Loading...