I have a huge data set (400000 sample) and when I plot them

ListLinePlot[Au4, PlotRange -> {All, All}]

enter image description here

I used the following code to Fourier transform it

ListLinePlot[Abs[Fourier[Au4][[2 ;; 6000]]], PlotRange -> All, 
 DataRange -> {2, 6000}, PlotStyle -> Red]

And got this

enter image description here

My problem is how to convert the x axis here in to the frequency domain in Mathematica? I saw that I can use the DataRange for that but I could not figure out how to do that exactly. I failed all the attempts. (I also saw that I can only use Fourier to the sample data only but I don't understand what is resulted in X axis after doing the Fourier to samples) Can someone help me at this point?


1 Answer 1


Based on the above referenced (and unreferenced) answers on mathematica.stackexchange, here is a short version of running code:

data=Au4;                      (* input *)
timeInterval = 10;             (* input *)
nSamples = Length@data;

spectrumLength = Floor[0.5 nSamples];
powerSpectralDensity = Abs[Fourier[signal][[;; spectrumLength]]]^2;
freqs = Range[0, spectrumLength - 1]/(dt*nSamples);
plot = ListLogLogPlot[Transpose[{freqs,powerSpectralDensity}]]

Seeing is believing, so here is the code applied to a simple sine wave:

  • Frequency is 0.5.
  • Duration of sampled time interval is 20.
  • Number of discrete samples in interval is 1000.


signal=Table[Sin[2.0 Pi f t dt],{t,nSamples}];

enter image description here

spectrumLength=Round[0.5 nSamples];
ListLogLogPlot[Transpose[{freqs,powerSpectralDensity}],Frame->True,Joined->True,PlotRange->All,PlotRangePadding->None,GridLines->{{f},None},GridLinesStyle->Directive[Red,Dashed],FrameLabel->{"frequency f","power spectral density"},PlotRangePadding->{None,Automatic},FrameStyle->Directive[Black,20,FontFamily->"Helvetica",AbsoluteThickness[2]]]

enter image description here

  • $\begingroup$ Thank you very much for your help but I am still confused on my set of data on how to relate what you mentioned above. I have 400000 data set but if I just use fourier for whole 400000 set it gives me two identical peaks (I guess that is because + and - data) . If I want to show one peak which is clear how should I do. If I use this will be correct. ListLinePlot[Abs[Fourier[Au10TD][[2 ;; 4000]]], PlotRange -> All, DataRange -> {2, 4000}, PlotStyle -> Red] I see a clear peak with this code but I can't understand it's physical meaning. Can you help me to understand this ? $\endgroup$
    – ravi3
    Commented Feb 4, 2016 at 1:00
  • $\begingroup$ @ravi3 You need to know 2 things in advance before you start the algorithm: a) How many datapoints do you have? In your case it is 400,000. b) What is your real time sampling interval for the 400,000 points? For example, if you measure 400,000 datapoints in one hour or in 10 years; that will lead to very different physical frequencies. Problem is, the measurement interval is not included in your time series! That is why you need to specify the variable "timeInterval" in the code above. $\endgroup$
    – Oscillon
    Commented Feb 4, 2016 at 9:52
  • $\begingroup$ Thank you for your reply. I have 400000 points corresponds to 480fs. Then when I plot for the whole set I see two peaks (identical) in the two extreme comers of the graph. Then to get a good peak I tried the above mentioned code so I could only see one peak (I selected 6000 out of 400000 data set to get that) So 6000 steps means 7.2 fs. (dt =1.2as) But my question is is it correct to do so and what I am seeing is correct as a peak. $\endgroup$
    – ravi3
    Commented Feb 4, 2016 at 21:32
  • $\begingroup$ Sure, you can just take a small part of the spectrum. However, if you want to see a peak close to zero better, I would suggest using a logarithmic x scale instead of cutting it. Also in your approach, you still need to calculate the maximum frequency for DataRange, which is 0.5/dt and not 4000. $\endgroup$
    – Oscillon
    Commented Feb 6, 2016 at 12:05
  • $\begingroup$ Thanks. I have a confusion with this ListLinePlot[Abs[Fourier[Au10TD][[2 ;; 4000]]], PlotRange -> All, DataRange -> {2, 4000}, PlotStyle -> Red] . This Au10TD list is having 400000 sample points. I thought when I use this code it only takes the 2 to 4000 data samples out of 400000 and Fourier transform this. Or is it taking all the 400000 data point samples and just show me the plot for 4000 samples? Can you clarify that to me. $\endgroup$
    – ravi3
    Commented Feb 8, 2016 at 18:29

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