Python+matplotlib实现计算两个信号的交叉谱密度实例
更新时间:2018年01月08日 16:57:01 投稿:mengwei
这篇文章主要介绍了Python+matplotlib实现计算两个信号的交叉谱密度实例,具有一定借鉴价值,需要的朋友可以参考下
计算两个信号的交叉谱密度
结果展示:

完整代码:
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()
总结
以上就是本文关于Python+matplotlib实现计算两个信号的交叉谱密度实例的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站其他相关专题,如有不足之处,欢迎留言指出。感谢朋友们对本站的支持!
相关文章
使用pandas中的DataFrame.rolling方法查看时间序列中的异常值
Pandas是Python中最受欢迎的数据分析和处理库之一,提供了许多强大且灵活的数据操作工具,在Pandas中,DataFrame.rolling方法是一个强大的工具,在本文中,我们将深入探讨DataFrame.rolling方法的各种参数和示例,以帮助您更好地理解和应用这个功能2023-12-12
pandas实现DataFrame显示最大行列,不省略显示实例
今天小编就为大家分享一篇pandas实现DataFrame显示最大行列,不省略显示实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧2019-12-12
python Autopep8实现按PEP8风格自动排版Python代码
这篇文章主要介绍了python Autopep8实现按PEP8风格自动排版Python代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2021-03-03


最新评论