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

Help with fft

  1. Dec 11, 2014 #1
    Hello, im a physics engineering student and i need a little help with fft function. I wrote the following code everything works, but when i get the fft. I was supose to obtain a sinc function and if you take a close look, it is a sinc, but in the wrong points, can anyone help me with this?

    if you dont know/remember what a sinc function looks like:
    https://www.google.pt/search?q=3d+s...%2Fwiki%2FFile%3AMatlab_surf_sinc.svg;561;420

    x0=0;
    y0=0;
    dx=5;
    dy=5;
    px=0.05;
    py=0.05;
    dxx=1;
    dyy=1;
    n=dx/px+1;
    m=dy/py+1;

    xx=-dx/2:px:dx/2;
    yy=-dy/2:py:dy/2;

    [X,Y]=meshgrid(xx,yy);

    Z=zeros(n,m);

    %w=X.^2+Y.^2;

    for i=1:n
    for j=1:m
    if X(i,j)>=x0-dxx/2 && X(i,j)<=x0+dxx/2 && Y(i,j)>=y0-dyy/2 && Y(i,j)<=y0+dyy/2
    Z(i,j)=1;
    end
    end
    end

    A=fft(Z);
    B=A.*conj(A);

    figure(1)
    surf(X,Y,Z)
    colormap jet
    colorbar

    figure(2)
    surf(X,Y,B)
    colormap jet
    colorbar





    Also, how i make sure that Z, has always the size of the matrixs X and Y?
     
  2. jcsd
  3. Dec 11, 2014 #2

    vela

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper
    Education Advisor

    It would help if you explained what your code is supposed to be doing.
     
  4. Dec 11, 2014 #3
    it is suppose to plot the fft of a square function which is the sinc function. if you take a look a the photo i've just uploaded, the second one should be a sinc function.
     

    Attached Files:

  5. Dec 11, 2014 #4

    vela

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper
    Education Advisor

    I don't understand the second plot. You're doing a two-dimensional FFT, right? Why do you have a one-dimensional power spectrum?
     
  6. Dec 11, 2014 #5
    its 2d too...
     
  7. Dec 11, 2014 #6

    vela

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper
    Education Advisor

    Really? I don't see depth in the second plot, unlike the first one.
     
  8. Dec 11, 2014 #7
    and now?
     

    Attached Files:

  9. Dec 11, 2014 #8

    vela

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper
    Education Advisor

    I'm assuming this is MATLAB code. According to the documentation, the routine fft doesn't do a two-dimensional DFT. It only acts on the first non-singleton dimension.

    EDIT: It looks like the function you want is fft2.
     
  10. Dec 11, 2014 #9
    humm ok, and how do i center it?
     
  11. Dec 12, 2014 #10

    vela

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper
    Education Advisor

    Probably easiest just to rotate the rows and columns by 50 positions.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Help with fft
  1. Fft in matlab (Replies: 0)

  2. Matlab (fft) (Replies: 1)

  3. FFT in Matlab (Replies: 12)

  4. Matlab fft help (Replies: 10)

  5. FFT and ifft (Replies: 3)

Loading...