Matplotlib是Python中的一個庫,它是數字的-NumPy庫的數學擴展。 Pyplot是Matplotlib模塊的基於狀態的接口,該模塊提供了MATLAB-like接口。
matplotlib.pyplot.csd()函數
matplotlib庫的pyplot模塊中的csd()函數用於繪製cross-spectral密度。
用法: matplotlib.pyplot.csd(x, y, 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:此參數包括在返回值中繪製的線對象。
返回值:這將返回以下內容:
- Pxx:這將返回縮放之前的功率譜P_ {xx}的值。
- freqs:這將返回Pxx中元素的頻率。
- line:這將返回此函數創建的行。
結果是(Pxx ,freqs, line)
以下示例說明了matplotlib.pyplot中的matplotlib.pyplot.psd()函數:
範例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)
plt.psd(s1**2, 512, 1./dt, color ="green")
plt.xlabel('Frequency')
plt.ylabel('PSD(db)')
plt.suptitle('matplotlib.pyplot.psd() function \
Example', fontweight ="bold")
plt.show()
輸出:
範例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)
plt.psd(s1, 2**14, dt)
plt.ylabel('PSD(db)')
plt.xlabel('Frequency')
plt.title('matplotlib.pyplot.psd() Example\n',
fontsize = 14, fontweight ='bold')
plt.show()
輸出:
相關用法
注:本文由純淨天空篩選整理自SHUBHAMSINGH10大神的英文原創作品 Matplotlib.pyplot.psd() in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。