Python+matplotlib實(shí)現(xiàn)計(jì)算兩個(gè)信號的交叉譜密度實(shí)例
計(jì)算兩個(gè)信號的交叉譜密度
結(jié)果展示:

完整代碼:
import numpy as np
import matplotlib.pyplot as plt
fig, (ax1, ax2) = plt.subplots(2, 1)
# make a little extra space between the subplots
fig.subplots_adjust(hspace=0.5)
dt = 0.01
t = np.arange(0, 30, dt)
# Fixing random state for reproducibility
np.random.seed(19680801)
nse1 = np.random.randn(len(t)) # white noise 1
nse2 = np.random.randn(len(t)) # white noise 2
r = np.exp(-t / 0.05)
cnse1 = np.convolve(nse1, r, mode='same') * dt # colored noise 1
cnse2 = np.convolve(nse2, r, mode='same') * dt # colored noise 2
# two signals with a coherent part and a random part
s1 = 0.01 * np.sin(2 * np.pi * 10 * t) + cnse1
s2 = 0.01 * np.sin(2 * np.pi * 10 * t) + cnse2
ax1.plot(t, s1, t, s2)
ax1.set_xlim(0, 5)
ax1.set_xlabel('time')
ax1.set_ylabel('s1 and s2')
ax1.grid(True)
cxy, f = ax2.csd(s1, s2, 256, 1. / dt)
ax2.set_ylabel('CSD (db)')
plt.show()
總結(jié)
以上就是本文關(guān)于Python+matplotlib實(shí)現(xiàn)計(jì)算兩個(gè)信號的交叉譜密度實(shí)例的全部內(nèi)容,希望對大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站其他相關(guān)專題,如有不足之處,歡迎留言指出。感謝朋友們對本站的支持!
相關(guān)文章
使用pandas中的DataFrame.rolling方法查看時(shí)間序列中的異常值
Pandas是Python中最受歡迎的數(shù)據(jù)分析和處理庫之一,提供了許多強(qiáng)大且靈活的數(shù)據(jù)操作工具,在Pandas中,DataFrame.rolling方法是一個(gè)強(qiáng)大的工具,在本文中,我們將深入探討DataFrame.rolling方法的各種參數(shù)和示例,以幫助您更好地理解和應(yīng)用這個(gè)功能2023-12-12
Python如何將一個(gè)EXCEL表拆分多個(gè)excel表
在Python中,你可以使用pandas庫來讀取Excel文件,并將一個(gè)大的Excel表格(工作表)拆分成多個(gè)單獨(dú)的Excel文件,這篇文章主要介紹了Python如何將一個(gè)EXCEL表拆分多個(gè)excel表,需要的朋友可以參考下2024-06-06
python的endswith()的使用方法及實(shí)例
這篇文章主要介紹了python的endswith()的使用方法及實(shí)例,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-07-07
pandas實(shí)現(xiàn)DataFrame顯示最大行列,不省略顯示實(shí)例
今天小編就為大家分享一篇pandas實(shí)現(xiàn)DataFrame顯示最大行列,不省略顯示實(shí)例,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-12-12
python Autopep8實(shí)現(xiàn)按PEP8風(fēng)格自動(dòng)排版Python代碼
這篇文章主要介紹了python Autopep8實(shí)現(xiàn)按PEP8風(fēng)格自動(dòng)排版Python代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-03-03

