0

I've been trying to find the FT of a more complicated function, but it seems my method is wrong. To check, I tried to calculate the FT of a Gaussian numerically. This is what I did:

tabexp = Table[Exp[-x^2], {x, 0, 100, 0.1}];
ListPlot[Abs[Fourier[tabexp]]]

This gives me a weird plot: enter image description here

What exactly am I doing wrong here? TIA!

1 Answers1

3

Mathematica performs its Fourier transform such that there are no negative frequencies. If you're coming from another computing language, you're probably more used to seeing the transform centred at 0 frequency. If you want that functionality, I use the fftshift function from this answer and it works really well.

The other potential issue is that you're only generating half of a Gaussian. I'm not sure if that's what you intended or not but it does give you a slightly different answer.

fftshift[dat_?ArrayQ, k : (_Integer?Positive | All) : All] := 
 Module[{dims = Dimensions[dat]}, 
  RotateRight[dat, 
   If[k === All, Quotient[dims, 2], 
    Quotient[dims[[k]], 2] UnitVector[Length[dims], k]]]]

tabexp = Table[Exp[-x^2], {x, 0, 100, 0.1}];
tabexp2 = Table[Exp[-(x - 50)^2], {x, 0, 100, 0.1}];

ListLinePlot[{
  tabexp,
  tabexp2
  },
 PlotRange -> Full
 ]

ListLinePlot[{
  fftshift[Abs[Fourier[tabexp]]^2],
  fftshift[Abs[Fourier[tabexp2]]^2]
  },
 PlotRange -> Full
 ]

This is what the plots of the Gaussians look like with your tabexp in blue, and a centred Gaussian in yellow:

Plot of Gaussian and centred Gaussian.

Plots of the Fourier transforms of the above Gaussians, with the FT of tabexp in blue and tabexp2 in yellow:

Plot of FT of Gaussian and centred Gaussian.

Oh, and I guess I squared the Abs. I just noticed you didn't in your code, but I'm too lazy to fix it now. One other thing to note, is that Fourier doesn't allow you to include any x-data. You have to provide it with the y-data and then add in the frequency data later if you want. The x-axes here range from 1 to 1000 because there are 1000 data points.

EDIT 01:

Manipulate[
  tabexp = Table[Exp[-x^2], {x, start, start + 100, 0.1}];
  ListLinePlot[{
      tabexp,
      fftshift[Abs[Fourier[tabexp]]^2]
    },
    PlotRange -> Full
  ],
  {{start, 0}, -50, 0, 1}
]

Animation of gaussian plot.

Here the blue curve is that Gaussian, and the yellow curve is the power of the shifted Fourier transform. Essentially as soon as the full Gaussian is displayed (start < 2 or so) then the FT doesn't change anymore.

Instead of starting your sampling at -50, you could also sample the equation Exp[-(x - 50)^2] from 0 to 100, they would be exactly equivalent in the end.

Manipulate is one of my favourite tools in Mathematica. If you're not familiar with it, I definitely recommend checking it out! It's helped me understand a lot about Fourier transforms, plotting, filtering, and all sorts of other things.

MassDefect
  • 10,081
  • 20
  • 30
  • Ah. Thank you so much for clearing this up! What would be the difference if, instead I tabulated my data for Exp[-x^{2}] starting from a non-zero value instead of 0? Does that make sense? – 123infinity Apr 15 '20 at 13:21
  • @123infinity Yes, you can change your sampling if you want to have the Gaussian centred. I've updated my answer to include some more information on that. – MassDefect Apr 15 '20 at 20:15
  • This has been really helpful. Thank you so much! :) – 123infinity Apr 16 '20 at 12:26