简体   繁体   English

matplotlib功率谱密度(PSD)值差异

[英]matplotlib power spectral density (PSD) value discrepancy

I tried calculating the power spectral density using matplotlib function psd() . 我尝试使用matplotlib函数psd()计算功率谱密度。 I plotted using two methods: 我使用两种方法绘制:

  1. At first I plot it directly using plt.psd (red line in plot) 首先,我直接使用plt.psd进行plt.psd (图中的红线)
  2. Then I output the values from psd to variables and plotting the variables (blue line in plot) 然后我将psd的值输出到变量并绘制变量(图中的蓝线)

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. 如果查看plt.psd的实现( 此处 ),您会看到绘制了功率的对数。

Thus to get the same plot you have to call: 因此,要获得相同的图,您必须调用:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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