1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

DFT Matlab - fft and ifft commands

  1. Oct 3, 2011 #1
    1. The problem statement, all variables and given/known data

    Hello people

    For a few days I'm having trouble with periodic boundary 1D poisson solver code on matlab. I'm trying to figure out discritized fourier transform (fft), and ifft commands.

    To make things simpler I want to type a simple code. Aim on the code is integrating a function ( such as sin(x) ) two times on frequency domain, then convert back to time domain and check it with the analytical result.

    My procedure is: first fft(y), then divide by (i*w)^2, finally invert back to time domain by using ifft.

    2. The attempt at a solution

    This is my code, but have no idea why it is not working...

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    clear all
    clc

    L=100; %length of the domain
    J=1000; %number of grids
    x=linspace(0,L,J);
    y=sin(x); %original y(x) function
    g=-sin(x); % if you integrate y(x) 2 times, you get this one.
    %And we use this to check code

    f=fft(y,J); %DFT of function y

    freq=(2*pi)*[0:(J/2-1) (-J/2):-1]/J; %frequencies

    for a=2:J
    f(a)=-f(a)/freq(a)^2; %integrating 2 times
    end

    f(1)=0;

    gf=ifft(f);

    gf=real(gf);


    X=1:J; %Plot part, and visiul check of the result
    plot(x(X),g(X));
    hold on
    plot(x(X),gf(X),'r');

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    Thank you
     
    Last edited: Oct 4, 2011
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?



Similar Discussions: DFT Matlab - fft and ifft commands
  1. Matlab help (Replies: 0)

  2. Help with Matlab (Replies: 0)

  3. Matlab Problem (Replies: 0)

  4. MATLAB: Optimization (Replies: 0)

Loading...