Python+matplotlib實現(xiàn)計算兩個信號的交叉譜密度實例
更新時間:2018年01月08日 16:57:01 投稿:mengwei
這篇文章主要介紹了Python+matplotlib實現(xiàn)計算兩個信號的交叉譜密度實例,具有一定借鑒價值,需要的朋友可以參考下
計算兩個信號的交叉譜密度
結(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實現(xiàn)計算兩個信號的交叉譜密度實例的全部內(nèi)容,希望對大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站其他相關(guān)專題,如有不足之處,歡迎留言指出。感謝朋友們對本站的支持!
相關(guān)文章
python散點圖雙軸設(shè)置坐標軸刻度的實現(xiàn)
散點圖是一種常用的圖表類型,可以用來展示兩個變量之間的關(guān)系,本文主要介紹了python散點圖雙軸設(shè)置坐標軸刻度的實現(xiàn),具有一定的參考價值,感興趣的可以了解一下2024-01-01Python2和Python3中print的用法示例總結(jié)
在Python 3中接觸的第一個很大的差異就是縮進是作為語法的一部分,這和C++等其他語言確實很不一樣,所以要小心,其中python3和python2中print的用法有很多不同,這篇文章主要給大家介紹了關(guān)于Python2和Python3中print用法的相關(guān)資料,需要的朋友可以參考下。2017-10-10pyhton中__pycache__文件夾的產(chǎn)生與作用詳解
這篇文章主要介紹了pyhton中__pycache__文件夾的產(chǎn)生與作用詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-11-11