matplotlib.axes.axes.psd() - 绘制功率谱密度

matplotlib.axes.axes.psd()

matplotlib.axes.axes.psd()函数,利用matplotlib库的axis模块中的Axes.psd()函数绘制功率谱密度

语法:

Axes.psd(self, x, NFFT=None, Fs=None, Fc=None, detrend=None, window=None, noverlap=None, pad_to=None, sides=None, scale_by_freq=None, return_line=None, *, data=None, **kwargs)

参数:该方法接受如下参数说明:

  • x:数据序列。
  • Fs:标量。默认值为2。
  • window:该参数接受一个数据段作为参数,并返回该段的窗口版本。其默认值是window_hanning()
  • sides:该参数指定返回频谱的哪一边。它可以有以下值:’ default ‘, ‘ onesided ‘和’ twosided ‘。
  • pad_to:该参数包含填充数据段的整数值。
  • NFFT:该参数包含用于FFT的每个块的数据点的数量。
  • detrend:该参数包含在fft-ing之前应用于每个分段的函数,旨在去除平均值或线性趋势{‘ none ‘, ‘ mean ‘, ‘ linear ‘}。
  • scale_by_freq:该参数允许对返回的频率值进行集成。
  • noverlap:该参数表示块之间的重叠点数量。
  • Fc: x的中心频率。
  • return_line:该参数包括在返回值中绘制的line对象。

返回如下内容:

  • Pxx:这将返回缩放前功率谱P_{xx}的值。
  • freqs:返回Pxx中元素的频率。
  • line:返回由该函数创建的行。

结果是(Pxx, freqs, line)

下面的例子演示了matplotlib.axes中的matplotlib.axes.csd()函数:

示例1

# Implementation of matplotlib function
import numpy as np
import matplotlib.pyplot as plt
   
dt = 0.01
t = np.arange(0, 30, dt)
nse1 = np.random.randn(len(t))
   
s1 = 1.5 * np.sin(2 * np.pi * 10 * t) + nse1 + np.cos(np.pi * t)
   
fig, ax1 = plt.subplots()
ax1.psd(s1**2, 512, 1./dt, color ="green")
ax1.set_xlabel('Frequency')
ax1.set_ylabel('PSD(db)')
   
ax1.set_title('matplotlib.axes.Axes.psd() Example')
plt.show()

输出:

matplotlib.axes.axes.psd()

示例2

# Implementation of matplotlib function
import numpy as np
import matplotlib.pyplot as plt
   
dt = 0.01
t = np.arange(0, 30, dt)
nse1 = np.random.randn(len(t))
r = np.exp(-t / 0.05)
   
cnse1 = np.convolve(nse1, r, mode ='same')*dt
   
s1 = np.cos(np.pi * t) + cnse1 + np.sin(2 * np.pi * 10 * t) 
   
fig, [ax1, ax2] = plt.subplots(2, 1)
ax1.plot(t, s1)
ax1.set_xlim(0, 5)
ax1.set_ylabel('value s1')
ax1.grid(True)
   
ax2.psd(s1, 256, 1./dt)
ax2.set_ylabel('PSD(db)')
ax2.set_xlabel('Frequency')
   
ax1.set_title('matplotlib.axes.Axes.psd() Example')
plt.show()

输出:

matplotlib.axes.axes.psd()

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程