# Unexpected behaviour of PowerSpectralDensity

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}]


gives:

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

ListPlot[Abs[Fourier[straightline]]^2]


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]


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.

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