# Homework Help: DFT Matlab - fft and ifft commands

1. Oct 3, 2011

### SoajanII

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