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!

Homework Help: 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

    L=100; %length of the domain
    J=1000; %number of grids
    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




    X=1:J; %Plot part, and visiul check of the result
    hold on


    Thank you
    Last edited: Oct 4, 2011
  2. jcsd
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted