# What is the meaning of the scaling difference between my DFT magnitude squared plot and my periodogram plot?

I have an EEG recording of duration $$2\text{s}$$ with sampling rate $$f_s=200 \,\text{Hz}$$ and, as a mathematician, wish to familiarize myself with some of the standard terminology in signal processing. I've computed the DFT, it's magnitude squared, and the power spectral density using the periodogram.

First, the DFT, where $$x$$ is my signal of length $$N=2*200=400$$, and $$f_s=200$$:

Xf = np.fft.rfft(x)
f = np.fft.rfftfreq(N)*fs


Question 1: What term is used to denote the magnitude of $$X_f$$ itself, i.e., $$|X_f|$$? Is it the amplitude spectrum, energy spectrum, or something different?

I then plotted the magnitude-squared of my DFT, along with the power spectral density obtained using the periodogram

fig, ax = plt.subplots(2)
ax[0].plot(f,abs(Xf)**2)

f,Pxx=periodogram(x,fs,nfft=len(x))
ax[1].plot(f,Pxx)
ax[1].set_xlabel('frequency (Hz)')
plt.show()


Below is the resulting plot.

I determined that the scaling difference equals $$f_s/2N$$ so that $$P_{xx}\frac{f_s}{2N}=|X_f|^2$$ In terms of units I suppose this makes sense to me since I understand $$P_{xx}$$ has units of $$\text{V}^2/\text{Hz}$$ and $$|X_f|^2$$ has units of $$\text{V}^2$$.

Question 2: Does the frequency scaling factor $$f_s/2N$$ have a particular name and what is its significance?

Question 1: Magnitude spectrum or Amplitude spectrum, to my knowledge, are used mostly interchangeably. As a plus, here is a formal definition of energy signals vs power signals.

Question 2: Yes, there is a scaling factor to apply in order to get correct units for Power Spectral Density from the DFT magnitude squared. No idea what it's called or if it even has a name!

The correct scaling factor is: $$\frac{2}{f_s\sum_\limits{j=0}^{N-1}w_j^2}$$ where $$w$$ is the window function used to, well, window the input to the DFT. That's the scaling factor periodogram applies to the squared magnitude of the DFT.

You're using the default box car window, for which $$\sum_\limits{j=0}^{N-1}w_j^2 = N$$ since $$w_j = 1$$

Hence the scaling difference does not equal $$\dfrac{f_s}{2N}$$, but rather $$\dfrac{f_sN}{2}$$, and

$$P_{xx}\cfrac{f_sN}{2} = |X_f|^2$$

Hence to match Pxx and Xf:

scaling_factor = 2/(fs*N)
ax[0].plot(f,scaling_factor*abs(Xf)**2)


The scaling for Power Spectrum is slightly different, you can read through this great reference on the subject if you're interested!

• This is all very helpful.Thanks for the info (and LaTeX edits) ! Dec 1, 2022 at 10:54
• Is there a similar relation for the cross-spectral density. Specifically, does |Pxy|*fs*N/2=|Xf|*|Yf| ? Dec 7, 2022 at 12:30
• @fishbacp that is correct. Specifically, $P_{xy} = \cfrac{2X_f \overline{Y_f}}{f_s\sum_\limits{j=0}^{N-1}w_j^2}$ With a rectangular window, $\sum_\limits{j=0}^{N-1}w_j^2 = N$. Take the absolute value and you get your result ;)
– Jdip
Dec 7, 2022 at 14:13