4
$\begingroup$

Usually, Fourier Transform in mathematica is supplied by y data only, like the famous Sin[x] transform example. What if my data is a list of {x,Sin[x]}? and x has units (for example, nm)? I would expect to see a spectrum with the correct units as frequencies. How can I achieve this?

Data1 = Table[Sin[x], {x, 0, 2*Pi, 2*Pi/1000}];
ListPlot[Abs[Fourier[Data1]], PlotRange -> All, Joined -> True]

and you see the plot doesn't make much sense. Although i have 2 peaks, their frequencies are not specified. I actually couldn't know which is + frequency and which is - frequency. In deed, i can not make much sense of this plot except for it has peaks.

Data2 = Table[{x, Sin[x]}, {x, 0, 2*Pi, 2*Pi/1000}];
ListPlot[Abs[Fourier[Data2]], PlotRange -> All, Joined -> True]

I would expect this to recover the x-axis information. But it doesn't . So what should I do if I wanted to know, for example, the peaks in the plot has a meaningful x axis, corresponding to , 2\Pi for example

Thanks

$\endgroup$
  • $\begingroup$ See the Frequency identification example on the Fourier[] doc page $\endgroup$ – Dr. belisarius Dec 18 '14 at 21:42
  • $\begingroup$ I didn't find it helpful.. And still it can not transform with real data (ones having x axis) $\endgroup$ – bboczeng Dec 18 '14 at 21:56
  • $\begingroup$ to compare, origin labs can handle it extremely well. $\endgroup$ – bboczeng Dec 18 '14 at 21:57
  • $\begingroup$ You might find the answer here useful to understand what the DFT is doing. mathematica.stackexchange.com/q/33574/1783 $\endgroup$ – bill s Dec 18 '14 at 21:58
  • $\begingroup$ Is this any improvement? Fourier[data1, FourierParameters -> {0, 2*Pi/1000}] $\endgroup$ – Daniel Lichtblau Dec 18 '14 at 22:03
2
$\begingroup$

If you look up ListPlot you will see that it uses point number for the x - axis. You have to make the frequency axis. Your question is a little muddled because you talk about time and frequency but the units you suggest are nm which I take to be nano meters. If you are working with length in one domain then when transformed you are in units of reciprocal length or wave number. I will continue with time to frequency transformation. The increment in the frequency domain is given by the sample rate divided by the number of points. The sample rate is the reciprocal of the time step. The frequency spectrum starts at zero and continues to the sample rate less one increment. Here is one way to make your frequency axis.

sr = 1000./(2 Pi);  (* sample rate*)
inc = sr/Length[Data1]; (* increment *)
freq = Table[f, {f, 0, sr - inc, inc}];

Now you can plot your data

ListPlot[Transpose[{freq, Abs[Fourier[Data1]]}], PlotRange -> All, 
 Joined -> True]

Mathematica graphics

Your sample rate is small compared to the frequency so your data is concentrated near the origin. Expanding the plot shows that your peak is at the second point.

ListPlot[Transpose[{freq, Abs[Fourier[Data1]]}], 
 PlotRange -> {{0, 1}, All}, Joined -> True]

Mathematica graphics

I suggest you write a Module if you whish to calculate the frequency axis automatically.

Further comments

  1. Your sine wave has a period of 2 Pi hence a frequency of 1/(2 Pi) = 0.159155.
  2. The data is sampled in the time domain and consequently periodic in the frequency domain. You have got one period in the frequency domain. This could be remapped to be negative then positive frequencies with zero in the middle. However, it is traditional in Fourier analysis to start at zero and keep going rather than give negative then positive frequencies. You get a positive and negative frequency (hence two peaks) for each frequency in the time domain.
$\endgroup$
  • 1
    $\begingroup$ thx. so what does this peak mean? its x-axis means something smaller than 0.2 I thought it has a frequency of 2Pi or 1 (depending on the units) $\endgroup$ – bboczeng Dec 18 '14 at 22:59
  • $\begingroup$ also, it has two peaks. What is the other peak? I think this DFT has some problem that it can not resolve the 0 in the frequency domain. Compare with what Orgin Labs can do. $\endgroup$ – bboczeng Dec 18 '14 at 23:00
  • $\begingroup$ The Fourier transform in Mathematica is correct and the same as used everywhere. If you plot your time history you will find it has approximately one cycle and thus appears at the second point in the frequency domain. The first point is the mean value. If you had a time history with 10 cycles it would appear at the 11th point. And with 100 cycles it appears at the 101th point. This is basic Fourier analysis and off topic. Two peaks is also normal. Drop the second half of the spectrum if you don't want thi $\endgroup$ – Hugh Dec 19 '14 at 22:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.