简体   繁体   中英

matplotlib power spectral density (PSD) value discrepancy

I tried calculating the power spectral density using matplotlib function psd() . I plotted using two methods:

  1. At first I plot it directly using plt.psd (red line in plot)
  2. Then I output the values from psd to variables and plotting the variables (blue line in plot)

The code I used:

power, freqs = plt.psd(P * 100000, len(P), Fs = 1 / dt, scale_by_freq=0)
plt.psd(P * 100000, len(P), 1 / dt, scale_by_freq=0)
plt.plot(freqs, power)

But the plots are different, I expected it to be coincident. From where does the discrepancy arise?

If you look at the implementation of plt.psd ( here ) you can see that the log of the power is plotted.

Thus to get the same plot you have to call:

plt.plot(freqs, 10*np.log10(power))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM