I recently wanted to calculate the power spectral density of a surface profile. I was happy to find out that there is a built in PowerSpectralDensity[] function in Mathematica (version 10). However, I'm surprised to find the following behaviour:

straightline = Range[1, 10, 0.2];
Plot[PowerSpectralDensity[straightline, w], {w, 0.1, 10}]


enter image description here

Note that 2Pi=6.28. Now, from my very faint recollection of University classes, I assumed this should be flat or at least similar to


Why is it not? Why do we get this result?

It probably has to do with the window function w since 2w moves the position of the peak by a factor of 1/2.


They are the same, sort of. You can make PowerSpectralDensity and Fourier show the same plot:

straightline = Range[1, 10, 0.2];
straightline = straightline - Mean[straightline];
ListPlot[Table[PowerSpectralDensity[straightline, w], 
         {w, 0, 2 Pi-0.001, 2 Pi/Length[straightline]}], PlotRange -> All]

ListPlot[Abs[Fourier[straightline]]^2, PlotRange -> All]

enter image description here

The main difference is that the PowerSpectralDensity (PSD) is reported as a (continuous-valued) function of frequency, while Fourier just calculates samples of this function. So to make the plots the same, we need to sample the PSD at the same points. A minor difference is that the PSD more or less assumes a zero mean signal, so to make them match, the code above removes the DC/constant term. Outside of {0,2 Pi}, both functions repeat with period 2 Pi, which in this case, is the complete list of 40-some points.

| improve this answer | |
  • $\begingroup$ thanks bill. Why did you exclude the 2Pi datapoint? $\endgroup$ – Kab Oct 16 '18 at 17:43
  • 1
    $\begingroup$ The zero point and the 2 Pi point are the same, due to the periodicity, so it seemed cleaner to remove it. $\endgroup$ – bill s Oct 16 '18 at 18:26

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.