Arun Subraminion
Arun Subraminion

Reputation: 89

power spectral density-scipy.signal

While trying to compute the Power spectral density with an acquisition rate of 300000hz using ... signal.periodogram(x, fs,nfft=4096) , I get the graph upto 150000Hz and not upto 300000. Why is this upto half the value ? What is the meaning of sampling rate here?

In the example given in scipy documentation , the sampling rate is 10000Hz but we see in the plot only upto 5000Hz.

https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.signal.periodogram.html

Upvotes: 3

Views: 2329

Answers (2)

SleuthEye
SleuthEye

Reputation: 14577

The spectrum of real-valued signal is always symmetric with respect to the Nyquist frequency (half of the sampling rate). As a result, there is often no need to store or plot the redundant symmetric portion of the spectrum.

If you still want to see the whole spectrum, you can set the return_onesided argument to True as follows:

f, Pxx_den = signal.periodogram(x, fs, return_onesided=False)

The resulting plot of the same example provided in scipy.periodogram documentation would then cover a 10000Hz frequency range as would be expected:

enter image description here

Upvotes: 2

newkid
newkid

Reputation: 1468

If you check the length of f in the example:

>>> len(f)
>>> 50001

This is NOT 50000 Hz. This is because scipy.signal.periodogram calls scipy.signal.welch with the parameter nperseg=x.shape[-1] by default. This is the correct input for scipy.signal.welch. However, if dig into source and see lines 328-329 (as of now), you'll see the reason why the size of output is 50001.

if nfft % 2 == 0:  # even
   outshape[-1] = nfft // 2 + 1

Upvotes: 1

Related Questions