Fourier transforms in Matlab

Status
Not open for further replies.

Biftheunderstudy

Senior member
Aug 15, 2006
375
1
81
I'm taken a Fourier transform of some equations and solving them using Matlab's ode45 routine. Next I want to inverse fft them back to spatial coordinates and I have a few questions about how Matlab does this.

To give a concrete example of my problem I start with the initial conditions:

I have a gaussian given by,
u(x,0) = exp( -x^2 ) [1]

The Fourier transform of this is simply another Gaussian,
u(k,0) = sqrt(pi) * exp( -(pi*k)^2 ) [2]

Now, with this in mind, I solve my equations and I decide to ifft the 1st time step. My expectations were that I should get [1]. Instead, I get a Gaussian that seems to be phaseshifted by pi? I'm not too sure on this, but instead of being centered at zero the peak of the Gaussian is split into 2 and located at the boundary (I have to take abs() of the resulting vector).

I've looked into this a bit and it has something to do with the fftshift function, but most of applications involved taking some combination of fftshift and fft of the data first. In my case, I've Fourier transformed everything analytically first and now am using Matlab to solve the resulting ODEs.
 

TecHNooB

Diamond Member
Sep 10, 2005
7,458
1
76
When you fft in matlab, the result indices represent 0 to sampling frequency / 2, -sampling frequency / 2 to 0 instead of -sampling freq/2 to sampling freq/2. fftshift converts between these two by moving the numbers around.

So if you take the fft of a gaussian and you plot the result, you're gonna get a bathtub curve instead of a gaussian. If you fftshift that, you get your gaussian. ifft is probably expecting the 0 to fs/2, -fs/2 to 0 vector, so if you want to ifft a gaussian centered about zero, you're going to have to fftshift it first.
 
Status
Not open for further replies.